johnlockejrr commited on
Commit
80ac58f
·
verified ·
1 Parent(s): 777a688

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -126,9 +126,18 @@ def predict(model_name, input_img):
126
  else:
127
  return input_img, {"text": text, "score": score}
128
 
 
 
 
 
 
 
 
 
129
  def process_image(image):
130
  # Perform inference on an image, select textline only
131
- results = model(image, imgsz=[640, 512], classes=0)
 
132
 
133
  img_cv2 = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
134
  masks = results[0].masks
 
126
  else:
127
  return input_img, {"text": text, "score": score}
128
 
129
+ def get_dynamic_imgsz(image, target_height=640, stride=32):
130
+ orig_width, orig_height = image.size
131
+ aspect_ratio = orig_width / orig_height
132
+ target_width = int(target_height * aspect_ratio)
133
+ # Round width to next multiple of stride (usually 32 for YOLO)
134
+ target_width = ((target_width + stride - 1) // stride) * stride
135
+ return [target_height, target_width] # YOLO expects [H, W]
136
+
137
  def process_image(image):
138
  # Perform inference on an image, select textline only
139
+ imgsz = get_dynamic_imgsz(image) # dynamically compute correct size
140
+ results = model(image, classes=0, imgsz=imgsz)
141
 
142
  img_cv2 = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
143
  masks = results[0].masks