You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notebooks/run_Cellpose-SAM.ipynb
+49-35Lines changed: 49 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,8 @@
3
3
{
4
4
"cell_type": "markdown",
5
5
"metadata": {
6
-
"colab_type": "text",
7
-
"id": "view-in-github"
6
+
"id": "view-in-github",
7
+
"colab_type": "text"
8
8
},
9
9
"source": [
10
10
"<a href=\"https://colab.research.google.com/github/MouseLand/cellpose_dev/blob/main/notebooks/run_Cellpose-SAM.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
@@ -40,7 +40,9 @@
40
40
},
41
41
{
42
42
"cell_type": "markdown",
43
-
"metadata": {},
43
+
"metadata": {
44
+
"id": "VZe3EmLeDr5h"
45
+
},
44
46
"source": [
45
47
"### Mount your google drive\n",
46
48
"\n",
@@ -67,7 +69,9 @@
67
69
},
68
70
{
69
71
"cell_type": "markdown",
70
-
"metadata": {},
72
+
"metadata": {
73
+
"id": "l9YpMcAuDr5i"
74
+
},
71
75
"source": [
72
76
"\n",
73
77
"Then click on \"Folder\" icon on the Left, press the refresh button. Your Google Drive folder should now be available here as \"gdrive\".\n",
@@ -95,9 +99,7 @@
95
99
"id": "h_iAN7cAthma"
96
100
},
97
101
"source": [
98
-
"## **Setup Cellpose**\n",
99
-
"\n",
100
-
"Install Cellpose-SAM\n"
102
+
"### Install Cellpose-SAM\n"
101
103
]
102
104
},
103
105
{
@@ -114,7 +116,9 @@
114
116
},
115
117
{
116
118
"cell_type": "markdown",
117
-
"metadata": {},
119
+
"metadata": {
120
+
"id": "fGSKx-EiDr5k"
121
+
},
118
122
"source": [
119
123
"Check GPU and instantiate model - will download weights."
120
124
]
@@ -133,20 +137,23 @@
133
137
"from pathlib import Path\n",
134
138
"from tqdm import trange\n",
135
139
"import matplotlib.pyplot as plt\n",
140
+
"from natsort import natsorted\n",
136
141
"\n",
137
142
"\n",
138
143
"#Check if colab notebook instance has GPU access\n",
139
-
"if core.use_gpu()==False:\n",
144
+
"if core.use_gpu()==False:\n",
140
145
" raise ImportError(\"No GPU access, change your runtime\")\n",
141
-
"\n",
146
+
"\n",
142
147
"io.logger_setup() # run this to get printing of progress\n",
143
148
"\n",
144
149
"model = models.CellposeModel(gpu=True)"
145
150
]
146
151
},
147
152
{
148
153
"cell_type": "markdown",
149
-
"metadata": {},
154
+
"metadata": {
155
+
"id": "vOpZWZtDDr5l"
156
+
},
150
157
"source": [
151
158
"Input directory with your images:"
152
159
]
@@ -167,10 +174,10 @@
167
174
" raise FileNotFoundError(\"directory does not exist\")\n",
168
175
"\n",
169
176
"# *** change to your image extension ***\n",
170
-
"image_ext = \".tif\"\n",
177
+
"image_ext = \".tif\"\n",
171
178
"\n",
172
179
"# list all files\n",
173
-
"files = [f for f in dir.glob(\"*\"+image_ext) if \"_masks\" not in f.name and \"_flows\" not in f.name]\n",
180
+
"files = natsorted([f for f in dir.glob(\"*\"+image_ext) if \"_masks\" not in f.name and \"_flows\" not in f.name])\n",
174
181
"\n",
175
182
"if(len(files)==0):\n",
176
183
" raise FileNotFoundError(\"no image files found, did you specify the correct folder and extension?\")\n",
@@ -183,19 +190,21 @@
183
190
},
184
191
{
185
192
"cell_type": "markdown",
186
-
"metadata": {},
193
+
"metadata": {
194
+
"id": "eyj9hnQvDr5l"
195
+
},
187
196
"source": [
188
197
"## Run Cellpose-SAM on one image in folder\n",
189
198
"\n",
190
199
"Here are some of the parameters you can change:\n",
191
200
"\n",
192
-
"* ***flow_threshold*** is the maximum allowed error of the flows for each mask. The default is 0.4.\n",
201
+
"* ***flow_threshold*** is the maximum allowed error of the flows for each mask. The default is 0.4.\n",
193
202
" * **Increase** this threshold if cellpose is not returning as many masks as you’d expect (or turn off completely with 0.0)\n",
194
-
" * **Decrease** this threshold if cellpose is returning too many ill-shaped masks.\n",
203
+
" * **Decrease** this threshold if cellpose is returning too many ill-shaped masks.\n",
195
204
"\n",
196
-
"* ***cellprob_threshold*** determines proability that a detected object is a cell. The default is 0.0.\n",
205
+
"* ***cellprob_threshold*** determines proability that a detected object is a cell. The default is 0.0.\n",
197
206
" * **Decrease** this threshold if cellpose is not returning as many masks as you’d expect or if masks are too small\n",
198
-
" * **Increase** this threshold if cellpose is returning too many masks esp from dull/dim areas.\n",
207
+
" * **Increase** this threshold if cellpose is returning too many masks esp from dull/dim areas.\n",
199
208
"\n",
200
209
"* ***tile_norm_blocksize*** determines the size of blocks used for normalizing the image. The default is 0, which means the entire image is normalized together.\n",
201
210
" You may want to change this to 100-200 pixels if you have very inhomogeneous brightness across your image.\n",
0 commit comments