Spaces:
Runtime error
Runtime error
Update model.py
Browse files
model.py
CHANGED
|
@@ -1,47 +1,3 @@
|
|
| 1 |
-
# import torch
|
| 2 |
-
# from monai.networks.nets import DynUNet
|
| 3 |
-
# import os
|
| 4 |
-
|
| 5 |
-
# def load_model(model_path="best_model_large_data.pth", device="cpu"):
|
| 6 |
-
# """Load DynUNet model with weights"""
|
| 7 |
-
# try:
|
| 8 |
-
# model = DynUNet(
|
| 9 |
-
# spatial_dims=2,
|
| 10 |
-
# in_channels=1,
|
| 11 |
-
# out_channels=1,
|
| 12 |
-
# kernel_size=[3, 3, 3, 3, 3],
|
| 13 |
-
# strides=[1, 2, 2, 2, 2],
|
| 14 |
-
# upsample_kernel_size=[2, 2, 2, 2],
|
| 15 |
-
# filters=[32, 64, 128, 256, 512],
|
| 16 |
-
# norm_name="INSTANCE",
|
| 17 |
-
# res_block=True,
|
| 18 |
-
# deep_supervision=False,
|
| 19 |
-
# )
|
| 20 |
-
|
| 21 |
-
# state_dict = torch.load(model_path, map_location=device)
|
| 22 |
-
# model.load_state_dict(state_dict)
|
| 23 |
-
# model.to(device)
|
| 24 |
-
# model.eval()
|
| 25 |
-
# return model
|
| 26 |
-
|
| 27 |
-
# except Exception as e:
|
| 28 |
-
# print(f"❌ Model initialization failed: {e}")
|
| 29 |
-
# raise
|
| 30 |
-
|
| 31 |
-
# def predict_mask(model, image_tensor):
|
| 32 |
-
# """Predict segmentation mask with sigmoid activation."""
|
| 33 |
-
# try:
|
| 34 |
-
# if image_tensor.dim() != 4 or image_tensor.shape[1] != 1:
|
| 35 |
-
# raise ValueError(f"Input tensor must be [1, 1, H, W]. Got {image_tensor.shape}")
|
| 36 |
-
|
| 37 |
-
# with torch.no_grad():
|
| 38 |
-
# return torch.sigmoid(model(image_tensor))
|
| 39 |
-
|
| 40 |
-
# except Exception as e:
|
| 41 |
-
# print(f"Prediction failed: {e}")
|
| 42 |
-
# raise
|
| 43 |
-
|
| 44 |
-
|
| 45 |
import torch
|
| 46 |
from monai.networks.nets import DynUNet
|
| 47 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from monai.networks.nets import DynUNet
|
| 3 |
import os
|