Praveen-K-0503 commited on
Commit
f4ccc6d
·
1 Parent(s): 4347e47

perf: force single pass and resolution limits on CPU to prevent timeouts

Browse files
Files changed (1) hide show
  1. api.py +7 -0
api.py CHANGED
@@ -114,6 +114,13 @@ def round_to_stride(value, stride=128):
114
 
115
  def process_frame(img_raw, model, device, transform, threshold, max_dim=3840, magnification=1.5, patch_size=512, nms_radius=8.0, batch_size=8, patch_overlap=0.25, inference_strategy="Auto", full_frame_max_dim=1800, fencing_poly=None):
116
  orig_width, orig_height = img_raw.size
 
 
 
 
 
 
 
117
  work_width = int(orig_width * magnification)
118
  work_height = int(orig_height * magnification)
119
 
 
114
 
115
  def process_frame(img_raw, model, device, transform, threshold, max_dim=3840, magnification=1.5, patch_size=512, nms_radius=8.0, batch_size=8, patch_overlap=0.25, inference_strategy="Auto", full_frame_max_dim=1800, fencing_poly=None):
116
  orig_width, orig_height = img_raw.size
117
+
118
+ # CPU optimizations to prevent >60s timeouts on HF Spaces free tier
119
+ if device.type == 'cpu':
120
+ max_dim = min(max_dim, 1280)
121
+ magnification = min(magnification, 1.0)
122
+ inference_strategy = "Single Pass"
123
+
124
  work_width = int(orig_width * magnification)
125
  work_height = int(orig_height * magnification)
126