Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import SimpleITK as sitk
|
|
7 |
import torch
|
8 |
from numpy import uint8
|
9 |
import spaces
|
|
|
|
|
10 |
|
11 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
12 |
|
@@ -64,14 +66,19 @@ def predict_image(input_image, input_file):
|
|
64 |
image_mask = Model_Seg.load_and_segment_image(image_path, device)
|
65 |
|
66 |
overlay_image_np, original_image_np = utils.overlay_mask(image_path, image_mask)
|
|
|
|
|
67 |
|
68 |
image_mask_im = sitk.GetImageFromArray(image_mask[None, :, :].astype(uint8))
|
69 |
image_im = sitk.GetImageFromArray(original_image_np[None, :, :].astype(uint8))
|
70 |
cropped_boxed_im, _ = utils.mask_and_crop(image_im, image_mask_im)
|
71 |
|
72 |
cropped_boxed_array = sitk.GetArrayFromImage(cropped_boxed_im)
|
73 |
-
cropped_boxed_array_disp = cropped_boxed_array.squeeze()
|
74 |
cropped_boxed_tensor = torch.Tensor(cropped_boxed_array)
|
|
|
|
|
|
|
|
|
75 |
prediction, image_transformed = Model_Class.load_and_classify_image(cropped_boxed_tensor, device)
|
76 |
|
77 |
|
|
|
7 |
import torch
|
8 |
from numpy import uint8
|
9 |
import spaces
|
10 |
+
from numpy import uint8, rot90, fliplr
|
11 |
+
from monai.transforms import Rotate90
|
12 |
|
13 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
14 |
|
|
|
66 |
image_mask = Model_Seg.load_and_segment_image(image_path, device)
|
67 |
|
68 |
overlay_image_np, original_image_np = utils.overlay_mask(image_path, image_mask)
|
69 |
+
overlay_image_np = rot90(overlay_image_np, k=3)
|
70 |
+
overlay_image_np = fliplr(overlay_image_np)
|
71 |
|
72 |
image_mask_im = sitk.GetImageFromArray(image_mask[None, :, :].astype(uint8))
|
73 |
image_im = sitk.GetImageFromArray(original_image_np[None, :, :].astype(uint8))
|
74 |
cropped_boxed_im, _ = utils.mask_and_crop(image_im, image_mask_im)
|
75 |
|
76 |
cropped_boxed_array = sitk.GetArrayFromImage(cropped_boxed_im)
|
|
|
77 |
cropped_boxed_tensor = torch.Tensor(cropped_boxed_array)
|
78 |
+
rotate = Rotate90(spatial_axes=(0, 1), k=3)
|
79 |
+
|
80 |
+
cropped_boxed_tensor = rotate(cropped_boxed_tensor)
|
81 |
+
cropped_boxed_array_disp = cropped_boxed_tensor.numpy().squeeze().astype(uint8)
|
82 |
prediction, image_transformed = Model_Class.load_and_classify_image(cropped_boxed_tensor, device)
|
83 |
|
84 |
|