Spaces:
Sleeping
Sleeping
AI Agent commited on
Commit ·
2b36e91
1
Parent(s): c67dd40
Protect numpy from bfloat16 errors on T4 and restrict model upcast to CPU only
Browse files
app.py
CHANGED
|
@@ -64,7 +64,8 @@ if model_installed:
|
|
| 64 |
|
| 65 |
model.load_state_dict(image_state_dict, strict=False)
|
| 66 |
model.to(device)
|
| 67 |
-
|
|
|
|
| 68 |
processor = Sam3Processor(model)
|
| 69 |
if not torch.cuda.is_available():
|
| 70 |
processor.device = "cpu"
|
|
@@ -120,8 +121,8 @@ def extract_assets(input_image):
|
|
| 120 |
if masks is None or len(masks) == 0:
|
| 121 |
continue
|
| 122 |
|
| 123 |
-
if torch.is_tensor(masks): masks = masks.cpu().numpy()
|
| 124 |
-
if torch.is_tensor(scores): scores = scores.cpu().numpy()
|
| 125 |
|
| 126 |
for j in range(len(masks)):
|
| 127 |
m = masks[j]
|
|
|
|
| 64 |
|
| 65 |
model.load_state_dict(image_state_dict, strict=False)
|
| 66 |
model.to(device)
|
| 67 |
+
if not torch.cuda.is_available():
|
| 68 |
+
model.to(torch.float32) # Force upcast from checkpoint's native bfloat16 to float32 for CPU inference
|
| 69 |
processor = Sam3Processor(model)
|
| 70 |
if not torch.cuda.is_available():
|
| 71 |
processor.device = "cpu"
|
|
|
|
| 121 |
if masks is None or len(masks) == 0:
|
| 122 |
continue
|
| 123 |
|
| 124 |
+
if torch.is_tensor(masks): masks = masks.float().cpu().numpy()
|
| 125 |
+
if torch.is_tensor(scores): scores = scores.float().cpu().numpy()
|
| 126 |
|
| 127 |
for j in range(len(masks)):
|
| 128 |
m = masks[j]
|