Skip to content

Commit dcbd450

Browse files
authored
MetaTensor Fix for NuClick Tutorial (#822)
* MetaTensor Fix for NuClick Tutorial Signed-off-by: vnath <[email protected]>
1 parent 7bb39ee commit dcbd450

File tree

2 files changed

+1533
-281
lines changed

2 files changed

+1533
-281
lines changed

nuclick/nuclick_infer.ipynb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18+
"!python -c \"import cv2\" || pip install -q opencv-python-headless==4.5.5.64\n",
1819
"!python -c \"import matplotlib\" || pip install -q matplotlib\n",
1920
"%matplotlib inline"
2021
]
2122
},
2223
{
2324
"cell_type": "code",
24-
"execution_count": 21,
25+
"execution_count": 1,
2526
"metadata": {},
26-
"outputs": [],
27+
"outputs": [
28+
{
29+
"name": "stderr",
30+
"output_type": "stream",
31+
"text": [
32+
"/home/vishwesh/anaconda3/envs/nuclick_tutorial/lib/python3.8/site-packages/requests/__init__.py:109: RequestsDependencyWarning: urllib3 (1.25.11) or chardet (5.0.0)/charset_normalizer (2.0.12) doesn't match a supported version!\n",
33+
" warnings.warn(\n"
34+
]
35+
}
36+
],
2737
"source": [
2838
"from monai.apps.nuclick.transforms import (\n",
2939
" FlattenLabeld,\n",
@@ -48,6 +58,7 @@
4858
"from monai.data import (\n",
4959
" Dataset,\n",
5060
" DataLoader,\n",
61+
" MetaTensor\n",
5162
")\n",
5263
"from monai.networks.nets import BasicUNet\n",
5364
"from skimage.measure import regionprops\n",
@@ -74,16 +85,15 @@
7485
},
7586
{
7687
"cell_type": "code",
77-
"execution_count": 22,
88+
"execution_count": 2,
7889
"metadata": {},
7990
"outputs": [],
8091
"source": [
8192
"def split_nuclei_dataset(d, centroid_key=\"centroid\", mask_value_key=\"mask_value\", min_area=5):\n",
8293
" dataset_json = []\n",
8394
"\n",
8495
" mask = LoadImage(image_only=True, dtype=np.uint8)(d[\"label\"])\n",
85-
" _, labels, _, _ = cv2.connectedComponentsWithStats(mask, 4, cv2.CV_32S)\n",
86-
"\n",
96+
" _, labels, _, _ = cv2.connectedComponentsWithStats(mask.array if isinstance(mask, MetaTensor) else mask, 4, cv2.CV_32S)\n",
8797
" stats = regionprops(labels)\n",
8898
" for stat in stats:\n",
8999
" if stat.area < min_area:\n",

0 commit comments

Comments
 (0)