multimodalart HF Staff commited on
Commit
ec47a15
·
verified ·
1 Parent(s): 8eaafaf

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. ecmodels.py +9 -6
app.py CHANGED
@@ -29,7 +29,7 @@ print(f"Loaded {len(MODELS)} EdgeCrafter checkpoints", flush=True)
29
  TABLE_HEADERS = ["#", "class", "score", "box (x1, y1, x2, y2)", "mask px / keypoints"]
30
 
31
 
32
- @spaces.GPU(duration=25)
33
  def predict(
34
  image: Image.Image,
35
  task: str = "Object Detection",
 
29
  TABLE_HEADERS = ["#", "class", "score", "box (x1, y1, x2, y2)", "mask px / keypoints"]
30
 
31
 
32
+ @spaces.GPU(duration=10)
33
  def predict(
34
  image: Image.Image,
35
  task: str = "Object Detection",
ecmodels.py CHANGED
@@ -336,15 +336,18 @@ def infer(model, task: str, image: Image.Image, threshold: float, device: str =
336
  results = []
337
  if masks is not None:
338
  img_w, img_h = image.size
339
- msks = torch.nn.functional.interpolate(
340
- masks[0].unsqueeze(0).float(), size=(img_h, img_w),
341
- mode="bilinear", align_corners=False,
342
- )[0]
343
- msks = (msks > 0.0)[keep]
344
  for j in range(len(lbls)):
 
 
 
 
345
  results.append(Result(label=int(lbls[j].item()), score=float(scs[j].item()),
346
  box=bxs[j].float().cpu().numpy(),
347
- mask=msks[j].cpu().numpy()))
348
  else:
349
  for j in range(len(lbls)):
350
  results.append(Result(label=int(lbls[j].item()), score=float(scs[j].item()),
 
336
  results = []
337
  if masks is not None:
338
  img_w, img_h = image.size
339
+ # same as the reference (bilinear upsample of the mask logits to the original
340
+ # resolution, threshold at 0), but one kept instance at a time so memory stays
341
+ # bounded on large inputs instead of upsampling all 300 queries at once.
342
+ kept_masks = masks[0][keep].float()
 
343
  for j in range(len(lbls)):
344
+ m = torch.nn.functional.interpolate(
345
+ kept_masks[j][None, None], size=(img_h, img_w),
346
+ mode="bilinear", align_corners=False,
347
+ )[0, 0]
348
  results.append(Result(label=int(lbls[j].item()), score=float(scs[j].item()),
349
  box=bxs[j].float().cpu().numpy(),
350
+ mask=(m > 0.0).cpu().numpy()))
351
  else:
352
  for j in range(len(lbls)):
353
  results.append(Result(label=int(lbls[j].item()), score=float(scs[j].item()),