Skip to content

Commit 6ed731c

Browse files
Created using Colab
1 parent 840129e commit 6ed731c

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

notebooks/test_Cellpose-SAM.ipynb

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{
44
"cell_type": "markdown",
55
"metadata": {
6-
"colab_type": "text",
7-
"id": "view-in-github"
6+
"id": "view-in-github",
7+
"colab_type": "text"
88
},
99
"source": [
1010
"<a href=\"https://colab.research.google.com/github/MouseLand/cellpose/blob/main/notebooks/test_Cellpose-SAM.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
@@ -38,7 +38,9 @@
3838
},
3939
{
4040
"cell_type": "markdown",
41-
"metadata": {},
41+
"metadata": {
42+
"id": "_lRDGixTm1Px"
43+
},
4244
"source": [
4345
"### Install Cellpose-SAM"
4446
]
@@ -57,7 +59,9 @@
5759
},
5860
{
5961
"cell_type": "markdown",
60-
"metadata": {},
62+
"metadata": {
63+
"id": "JRalUQBTm1Py"
64+
},
6165
"source": [
6266
"Check GPU and instantiate model - will download weights."
6367
]
@@ -78,17 +82,19 @@
7882
"import matplotlib.pyplot as plt\n",
7983
"\n",
8084
"io.logger_setup() # run this to get printing of progress\n",
81-
" \n",
85+
"\n",
8286
"#Check if colab notebook instance has GPU access\n",
83-
"if core.use_gpu()==False: \n",
87+
"if core.use_gpu()==False:\n",
8488
" raise ImportError(\"No GPU access, change your runtime\")\n",
8589
"\n",
8690
"model = models.CellposeModel(gpu=True)"
8791
]
8892
},
8993
{
9094
"cell_type": "markdown",
91-
"metadata": {},
95+
"metadata": {
96+
"id": "fY6Vv5I3m1Py"
97+
},
9298
"source": [
9399
"### Download example images"
94100
]
@@ -132,7 +138,9 @@
132138
},
133139
{
134140
"cell_type": "markdown",
135-
"metadata": {},
141+
"metadata": {
142+
"id": "M-jKt9wsm1Pz"
143+
},
136144
"source": [
137145
"### Run Cellpose-SAM"
138146
]
@@ -146,7 +154,7 @@
146154
},
147155
"outputs": [],
148156
"source": [
149-
"masks_pred, flows, styles, diams = model.eval(imgs, \n",
157+
"masks_pred, flows, styles = model.eval(imgs,\n",
150158
" niter=1000) # using more iterations for bacteria\n"
151159
]
152160
},
@@ -162,7 +170,9 @@
162170
{
163171
"cell_type": "code",
164172
"execution_count": null,
165-
"metadata": {},
173+
"metadata": {
174+
"id": "teNSdi1_m1Pz"
175+
},
166176
"outputs": [],
167177
"source": [
168178
"from cellpose import transforms, plot\n",
@@ -207,16 +217,11 @@
207217
"plt.show()"
208218
]
209219
},
210-
{
211-
"cell_type": "code",
212-
"execution_count": null,
213-
"metadata": {},
214-
"outputs": [],
215-
"source": []
216-
},
217220
{
218221
"cell_type": "markdown",
219-
"metadata": {},
222+
"metadata": {
223+
"id": "rMyZtY6ym1P0"
224+
},
220225
"source": [
221226
"# Run Cellpose-SAM in 3D\n",
222227
"\n",
@@ -229,21 +234,25 @@
229234
{
230235
"cell_type": "code",
231236
"execution_count": null,
232-
"metadata": {},
237+
"metadata": {
238+
"id": "2b2hVxCvm1P0"
239+
},
233240
"outputs": [],
234241
"source": [
235242
"img_3D = io.imread(\"rgb_3D.tif\")\n",
236243
"\n",
237244
"\n",
238245
"# 1. computes flows from 2D slices and combines into 3D flows to create masks\n",
239-
"masks, flows, None = model.eval(img_3D, z_axis=0, channel_axis=1, \n",
246+
"masks, flows, _ = model.eval(img_3D, z_axis=0, channel_axis=1,\n",
240247
" batch_size=32,\n",
241248
" do_3D=True, flow3D_smooth=1)\n"
242249
]
243250
},
244251
{
245252
"cell_type": "markdown",
246-
"metadata": {},
253+
"metadata": {
254+
"id": "KeMtAuRom1P0"
255+
},
247256
"source": [
248257
"Second way: computes masks in 2D slices and stitches masks in 3D based on mask overlap\n",
249258
"\n",
@@ -253,27 +262,33 @@
253262
{
254263
"cell_type": "code",
255264
"execution_count": null,
256-
"metadata": {},
265+
"metadata": {
266+
"id": "WTyCgBUfm1P0"
267+
},
257268
"outputs": [],
258269
"source": [
259270
"# 2. computes masks in 2D slices and stitches masks in 3D based on mask overlap\n",
260271
"print('running cellpose 2D + stitching masks')\n",
261-
"masks_stitched, flows_stitched, None = model.eval(img_3D, z_axis=0, channel_axis=1,\n",
262-
" batch_size=32, \n",
272+
"masks_stitched, flows_stitched, _ = model.eval(img_3D, z_axis=0, channel_axis=1,\n",
273+
" batch_size=32,\n",
263274
" do_3D=False, stitch_threshold=0.5)"
264275
]
265276
},
266277
{
267278
"cell_type": "markdown",
268-
"metadata": {},
279+
"metadata": {
280+
"id": "wbu1j0h6m1P0"
281+
},
269282
"source": [
270283
"Results from 3D flows => masks computation"
271284
]
272285
},
273286
{
274287
"cell_type": "code",
275288
"execution_count": null,
276-
"metadata": {},
289+
"metadata": {
290+
"id": "Vfg67u2dm1P0"
291+
},
277292
"outputs": [],
278293
"source": [
279294
"# DISPLAY RESULTS 3D flows => masks\n",
@@ -291,14 +306,15 @@
291306
},
292307
{
293308
"cell_type": "markdown",
294-
"metadata": {},
309+
"metadata": {
310+
"id": "dj18ZyzHm1P0"
311+
},
295312
"source": [
296313
"Results from stitching"
297314
]
298315
},
299316
{
300-
"cell_type": "markdown",
301-
"metadata": {},
317+
"cell_type": "code",
302318
"source": [
303319
"# DISPLAY RESULTS stitching\n",
304320
"plt.figure(figsize=(15,3))\n",
@@ -311,14 +327,19 @@
311327
" imgout[outX, outY] = np.array([255,75,75])\n",
312328
" plt.imshow(imgout)\n",
313329
" plt.title('iplane = %d'%iplane)"
314-
]
330+
],
331+
"metadata": {
332+
"id": "fd-6Hji-n9_H"
333+
},
334+
"execution_count": null,
335+
"outputs": []
315336
}
316337
],
317338
"metadata": {
318339
"accelerator": "GPU",
319340
"colab": {
320-
"include_colab_link": true,
321-
"provenance": []
341+
"provenance": [],
342+
"include_colab_link": true
322343
},
323344
"kernelspec": {
324345
"display_name": "cellpose",
@@ -340,4 +361,4 @@
340361
},
341362
"nbformat": 4,
342363
"nbformat_minor": 0
343-
}
364+
}

0 commit comments

Comments
 (0)