Debug app.py
Browse files
app.py
CHANGED
@@ -37,6 +37,7 @@ from skimage.util.dtype import dtype_range
|
|
37 |
from skimage._shared.utils import _supported_float_type
|
38 |
from scipy.ndimage import find_objects, binary_fill_holes
|
39 |
|
|
|
40 |
|
41 |
########################### Data Loading Modules #########################################################
|
42 |
DTYPE_RANGE = dtype_range.copy()
|
@@ -1102,6 +1103,22 @@ def compute_masks(
|
|
1102 |
|
1103 |
return mask, p
|
1104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1105 |
def predict(img):
|
1106 |
# Dataset parameters
|
1107 |
### for huggingface space
|
@@ -1239,7 +1256,7 @@ def predict(img):
|
|
1239 |
tif.imwrite(file_path, pred_mask, compression="zlib")
|
1240 |
print(np.max(pred_mask))
|
1241 |
# return img_data, seg_rgb, join(os.getcwd(), 'segmentation.tiff')
|
1242 |
-
return origin_img, pred_mask, file_path
|
1243 |
|
1244 |
demo = gr.Interface(
|
1245 |
predict,
|
|
|
37 |
from skimage._shared.utils import _supported_float_type
|
38 |
from scipy.ndimage import find_objects, binary_fill_holes
|
39 |
|
40 |
+
import random
|
41 |
|
42 |
########################### Data Loading Modules #########################################################
|
43 |
DTYPE_RANGE = dtype_range.copy()
|
|
|
1103 |
|
1104 |
return mask, p
|
1105 |
|
1106 |
+
def visualize_instance_seg_mask(mask):
|
1107 |
+
image = np.zeros((mask.shape[0], mask.shape[1], 3))
|
1108 |
+
labels = np.unique(mask)
|
1109 |
+
label2color = {label: (random.randint(50, 255), random.randint(50, 255), random.randint(50, 255)) for label in labels if label > 0}
|
1110 |
+
label2color[0] = (0, 0, 0)
|
1111 |
+
for label in labels:
|
1112 |
+
image[mask==label, :] = label2color[label]
|
1113 |
+
# for i in range(image.shape[0]):
|
1114 |
+
# for j in range(image.shape[1]):
|
1115 |
+
# if np.max(label2color[mask[i, j]]) > 0:
|
1116 |
+
# print('####', np.max(label2color[mask[i, j]]), np.min(label2color[mask[i, j]]))
|
1117 |
+
# image[i, j, :] = label2color[mask[i, j]]
|
1118 |
+
# image = image / 255
|
1119 |
+
image = image.astype(np.uint8)
|
1120 |
+
return image
|
1121 |
+
|
1122 |
def predict(img):
|
1123 |
# Dataset parameters
|
1124 |
### for huggingface space
|
|
|
1256 |
tif.imwrite(file_path, pred_mask, compression="zlib")
|
1257 |
print(np.max(pred_mask))
|
1258 |
# return img_data, seg_rgb, join(os.getcwd(), 'segmentation.tiff')
|
1259 |
+
return origin_img, visualize_instance_seg_mask(pred_mask), file_path
|
1260 |
|
1261 |
demo = gr.Interface(
|
1262 |
predict,
|