ammariii08 commited on
Commit
99482d0
·
verified ·
1 Parent(s): bc99e62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -69,10 +69,10 @@ print("YOLOWorld model loaded in {:.2f} seconds".format(time.time() - start_time
69
 
70
  print("Loading YOLO reference model...")
71
  start_time = time.time()
72
- reference_model_path = os.path.join(CACHE_DIR, "last.pt")
73
  if not os.path.exists(reference_model_path):
74
  print("Caching YOLO reference model to", reference_model_path)
75
- shutil.copy("last.pt", reference_model_path)
76
  reference_detector_global = YOLO(reference_model_path)
77
  print("YOLO reference model loaded in {:.2f} seconds".format(time.time() - start_time))
78
 
@@ -120,7 +120,7 @@ def unload_and_reload_models():
120
  gc.collect()
121
  new_drawer_detector = YOLOWorld(os.path.join(CACHE_DIR, "yolov8x-worldv2.pt"))
122
  new_drawer_detector.set_classes(["box"])
123
- new_reference_detector = YOLO(os.path.join(CACHE_DIR, "last.pt"))
124
  new_birefnet = AutoModelForImageSegmentation.from_pretrained(
125
  "zhengpeng7/BiRefNet", trust_remote_code=True, cache_dir=CACHE_DIR
126
  )
@@ -155,7 +155,7 @@ def yolo_detect(image: Union[str, Path, int, Image.Image, list, tuple, np.ndarra
155
 
156
  def detect_reference_square(img: np.ndarray):
157
  t = time.time()
158
- res = reference_detector_global.predict(img, conf=0.05)
159
  if not res or len(res) == 0 or len(res[0].boxes) == 0:
160
  raise ReferenceBoxNotDetectedError("Reference box not detected in the image.")
161
  print("Reference detection completed in {:.2f} seconds".format(time.time() - t))
@@ -561,7 +561,7 @@ def predict(
561
  objects_mask = remove_bg(shrunked_img)
562
  processed_size = objects_mask.shape[:2]
563
 
564
- objects_mask = exclude_scaling_box(objects_mask, scaling_box_coords, orig_size, processed_size, expansion_factor=1.2)
565
  objects_mask = resize_img(objects_mask, (shrunked_img.shape[1], shrunked_img.shape[0]))
566
  del scaling_box_coords
567
  gc.collect()
 
69
 
70
  print("Loading YOLO reference model...")
71
  start_time = time.time()
72
+ reference_model_path = os.path.join(CACHE_DIR, "best.pt")
73
  if not os.path.exists(reference_model_path):
74
  print("Caching YOLO reference model to", reference_model_path)
75
+ shutil.copy("best.pt", reference_model_path)
76
  reference_detector_global = YOLO(reference_model_path)
77
  print("YOLO reference model loaded in {:.2f} seconds".format(time.time() - start_time))
78
 
 
120
  gc.collect()
121
  new_drawer_detector = YOLOWorld(os.path.join(CACHE_DIR, "yolov8x-worldv2.pt"))
122
  new_drawer_detector.set_classes(["box"])
123
+ new_reference_detector = YOLO(os.path.join(CACHE_DIR, "best.pt"))
124
  new_birefnet = AutoModelForImageSegmentation.from_pretrained(
125
  "zhengpeng7/BiRefNet", trust_remote_code=True, cache_dir=CACHE_DIR
126
  )
 
155
 
156
  def detect_reference_square(img: np.ndarray):
157
  t = time.time()
158
+ res = reference_detector_global.predict(img, conf=0.25)
159
  if not res or len(res) == 0 or len(res[0].boxes) == 0:
160
  raise ReferenceBoxNotDetectedError("Reference box not detected in the image.")
161
  print("Reference detection completed in {:.2f} seconds".format(time.time() - t))
 
561
  objects_mask = remove_bg(shrunked_img)
562
  processed_size = objects_mask.shape[:2]
563
 
564
+ objects_mask = exclude_scaling_box(objects_mask, scaling_box_coords, orig_size, processed_size, expansion_factor=1.7)
565
  objects_mask = resize_img(objects_mask, (shrunked_img.shape[1], shrunked_img.shape[0]))
566
  del scaling_box_coords
567
  gc.collect()