Spaces:
Sleeping
Sleeping
perf: MAX_BASE_TILES=4 + 50s time budget to prevent timeout
Browse files- Dockerfile +1 -1
- api/scanner.py +11 -1
Dockerfile
CHANGED
|
@@ -15,7 +15,7 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 15 |
COPY api/ ./api/
|
| 16 |
|
| 17 |
# HF Space: limit tiles for CPU inference speed
|
| 18 |
-
ENV MAX_BASE_TILES=
|
| 19 |
ENV PORT=7860
|
| 20 |
EXPOSE 7860
|
| 21 |
|
|
|
|
| 15 |
COPY api/ ./api/
|
| 16 |
|
| 17 |
# HF Space: limit tiles for CPU inference speed
|
| 18 |
+
ENV MAX_BASE_TILES=4
|
| 19 |
ENV PORT=7860
|
| 20 |
EXPOSE 7860
|
| 21 |
|
api/scanner.py
CHANGED
|
@@ -11,6 +11,7 @@ Revenue estimates use 2025 Korean market rates:
|
|
| 11 |
"""
|
| 12 |
import math
|
| 13 |
import os
|
|
|
|
| 14 |
import numpy as np
|
| 15 |
import requests
|
| 16 |
from collections import deque
|
|
@@ -299,8 +300,17 @@ def scan_region(
|
|
| 299 |
batch_keys.append((vx, vy))
|
| 300 |
batch_feats.append(_img_features(crop_256))
|
| 301 |
|
|
|
|
|
|
|
|
|
|
| 302 |
if batch_imgs:
|
| 303 |
-
probs =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
for (vx, vy), prob, feat in zip(batch_keys, probs, batch_feats):
|
| 305 |
tile_data[(vx, vy)] = (prob, feat)
|
| 306 |
|
|
|
|
| 11 |
"""
|
| 12 |
import math
|
| 13 |
import os
|
| 14 |
+
import time
|
| 15 |
import numpy as np
|
| 16 |
import requests
|
| 17 |
from collections import deque
|
|
|
|
| 300 |
batch_keys.append((vx, vy))
|
| 301 |
batch_feats.append(_img_features(crop_256))
|
| 302 |
|
| 303 |
+
# ์๊ฐ ์์ฐ 50s: ์ด๊ณผ ์ ๋จ์ ํ์ผ์ prob=0์ผ๋ก ์ฒ๋ฆฌ (ํ์์์ ๋ฐฉ์ง)
|
| 304 |
+
_BUDGET_S = 50.0
|
| 305 |
+
_t0 = time.monotonic()
|
| 306 |
if batch_imgs:
|
| 307 |
+
probs: list[float] = []
|
| 308 |
+
mini = 8
|
| 309 |
+
for i in range(0, len(batch_imgs), mini):
|
| 310 |
+
if time.monotonic() - _t0 > _BUDGET_S:
|
| 311 |
+
probs.extend([0.0] * (len(batch_imgs) - len(probs)))
|
| 312 |
+
break
|
| 313 |
+
probs.extend(infer_batch(batch_imgs[i : i + mini]))
|
| 314 |
for (vx, vy), prob, feat in zip(batch_keys, probs, batch_feats):
|
| 315 |
tile_data[(vx, vy)] = (prob, feat)
|
| 316 |
|