Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -273,19 +273,22 @@ def run_inference(image, task, dataset_name, h_type, mode_type):
|
|
| 273 |
# ๆๅ โ ๆๅฐ็ปๆ่ๅด๏ผๅนถๆ่พๅบๅพๅญๅฐ Demo1_result.png
|
| 274 |
# ๅคฑ่ดฅ โ ๆๅฐๅฎๆด traceback๏ผๆนไพฟๅฎไฝ้่ฏฏ
|
| 275 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
_test_img = Image.open(_DEMO_IMG_PATH)
|
| 285 |
print(f" Image size : {_test_img.size}, mode: {_test_img.mode}")
|
| 286 |
|
| 287 |
-
#
|
| 288 |
-
_model.to("cuda")
|
| 289 |
|
| 290 |
_out_img, _info = _run_inference_core(
|
| 291 |
_model, "cuda",
|
|
@@ -300,11 +303,18 @@ try:
|
|
| 300 |
print(f" Info : {_info}")
|
| 301 |
print(f" Saved to : Demo1_result.png")
|
| 302 |
|
| 303 |
-
except Exception:
|
| 304 |
-
|
| 305 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
|
| 307 |
-
|
|
|
|
| 308 |
|
| 309 |
|
| 310 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
|
| 273 |
# ๆๅ โ ๆๅฐ็ปๆ่ๅด๏ผๅนถๆ่พๅบๅพๅญๅฐ Demo1_result.png
|
| 274 |
# ๅคฑ่ดฅ โ ๆๅฐๅฎๆด traceback๏ผๆนไพฟๅฎไฝ้่ฏฏ
|
| 275 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 276 |
+
@spaces.GPU(duration=120)
|
| 277 |
+
def _startup_gpu_test():
|
| 278 |
+
"""ๅฟ
้กปๅ
ๅจ @spaces.GPU ้๏ผZeroGPU ๆไผๅ้
็ๅฎ GPU ็ป่ฟๆฎตไปฃ็ """
|
| 279 |
+
_DEMO_IMG_PATH = "Demo1.png"
|
| 280 |
+
print(f"\n{'='*60}")
|
| 281 |
+
print(f"๐งช Startup inference test โ {_DEMO_IMG_PATH} (device=cuda)")
|
| 282 |
+
print(f"{'='*60}")
|
| 283 |
+
try:
|
| 284 |
+
if not os.path.exists(_DEMO_IMG_PATH):
|
| 285 |
+
print(f"โ ๏ธ {_DEMO_IMG_PATH} not found, skipping test.")
|
| 286 |
+
return
|
| 287 |
+
|
| 288 |
_test_img = Image.open(_DEMO_IMG_PATH)
|
| 289 |
print(f" Image size : {_test_img.size}, mode: {_test_img.mode}")
|
| 290 |
|
| 291 |
+
_model.to("cuda") # ๅจ @spaces.GPU ไธไธๆๅ
็งปๅจ๏ผZeroGPU ๆ่ฎคๅพ
|
|
|
|
| 292 |
|
| 293 |
_out_img, _info = _run_inference_core(
|
| 294 |
_model, "cuda",
|
|
|
|
| 303 |
print(f" Info : {_info}")
|
| 304 |
print(f" Saved to : Demo1_result.png")
|
| 305 |
|
| 306 |
+
except Exception:
|
| 307 |
+
print("โ Test FAILED โ full traceback below:")
|
| 308 |
+
traceback.print_exc()
|
| 309 |
+
|
| 310 |
+
finally:
|
| 311 |
+
_model.to("cpu") # ็จๅฎๅฝ่ฟ GPU ๅ
ๅญ
|
| 312 |
+
torch.cuda.empty_cache()
|
| 313 |
+
print(f"{'='*60}\n")
|
| 314 |
+
|
| 315 |
|
| 316 |
+
# ่ฐ็จๅฏๅจๆต่ฏ๏ผๆญคๆถๅทฒๅจ @spaces.GPU ไธไธๆๅ
๏ผGPU ๆญฃๅธธๅฏ็จ๏ผ
|
| 317 |
+
_startup_gpu_test()
|
| 318 |
|
| 319 |
|
| 320 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|