Skip to content

Commit 4cb1021

Browse files
authored
Merge pull request #17 from fercer/dev-content
Updated gpu instructions to consider mps
2 parents 544f3c0 + 4bfbf91 commit 4cb1021

File tree

2 files changed

+150
-500
lines changed

2 files changed

+150
-500
lines changed

notebooks/Solved_Zarr_and_Dask_for_large-scale_imaging-Part-2.ipynb

Lines changed: 136 additions & 428 deletions
Large diffs are not rendered by default.

notebooks/Zarr_and_Dask_for_large-scale_imaging-Part-2.ipynb

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,7 @@
8080
},
8181
{
8282
"cell_type": "code",
83-
"execution_count": null,
84-
"metadata": {},
85-
"outputs": [],
86-
"source": []
87-
},
88-
{
89-
"cell_type": "code",
90-
"execution_count": null,
83+
"execution_count": 3,
9184
"metadata": {
9285
"executionInfo": {
9386
"elapsed": 976,
@@ -120,11 +113,11 @@
120113
},
121114
{
122115
"cell_type": "code",
123-
"execution_count": null,
116+
"execution_count": 8,
124117
"metadata": {},
125118
"outputs": [],
126119
"source": [
127-
"# input_path = /path/to/local/image\n",
120+
"# input_path = \"CMU-1_Crop.ome.zarr\"\n",
128121
"input_path = \"https://storage.googleapis.com/jax-public-ngff/example_v2/CMU-1_Crop.ome.zarr\""
129122
]
130123
},
@@ -152,7 +145,7 @@
152145
},
153146
{
154147
"cell_type": "code",
155-
"execution_count": null,
148+
"execution_count": 20,
156149
"metadata": {
157150
"cellView": "form",
158151
"colab": {
@@ -176,7 +169,7 @@
176169
"from cellpose import models, transforms\n",
177170
"import torch\n",
178171
"\n",
179-
"gpu = torch.cuda.is_available()\n",
172+
"gpu = torch.cuda.is_available() or torch.mps.is_available()\n",
180173
"model_type = \"cyto3\"\n",
181174
"\n",
182175
"cellpose_model = models.CellposeModel(gpu=gpu, model_type=model_type)"
@@ -202,24 +195,7 @@
202195
"execution_count": null,
203196
"metadata": {},
204197
"outputs": [],
205-
"source": [
206-
"img_t = transforms.convert_image(da_sel.compute(), channel_axis=2, channels=[0, 0])\n",
207-
"img_t = transforms.normalize_img(img_t, invert=False, axis=2)\n",
208-
"\n",
209-
"labels, _, _ = cellpose_model.eval(img_t[None, ...], diameter=None, flow_threshold=None, channels=[0, 0])"
210-
]
211-
},
212-
{
213-
"cell_type": "code",
214-
"execution_count": null,
215-
"metadata": {
216-
"id": "iRTdgTzi_KfU"
217-
},
218-
"outputs": [],
219-
"source": [
220-
"plt.imshow(da_sel)\n",
221-
"plt.imshow(skimage.color.label2rgb(labels), alpha=0.5)"
222-
]
198+
"source": []
223199
},
224200
{
225201
"cell_type": "markdown",
@@ -321,7 +297,7 @@
321297
},
322298
{
323299
"cell_type": "code",
324-
"execution_count": null,
300+
"execution_count": 41,
325301
"metadata": {},
326302
"outputs": [],
327303
"source": [
@@ -449,7 +425,7 @@
449425
},
450426
{
451427
"cell_type": "code",
452-
"execution_count": null,
428+
"execution_count": 66,
453429
"metadata": {
454430
"id": "2yzM2YNRcAFI"
455431
},
@@ -515,39 +491,9 @@
515491
{
516492
"cell_type": "code",
517493
"execution_count": null,
518-
"metadata": {
519-
"cellView": "form",
520-
"id": "Bh6c9EVy9hST"
521-
},
522-
"outputs": [],
523-
"source": [
524-
"with ProgressBar():\n",
525-
" for s in range(1, 6):\n",
526-
" da_labels = da.from_zarr(\"CMU-1_Crop_labels_cellpose_cyto3.zarr\", component=str(s - 1))\n",
527-
"\n",
528-
" da_labels_ds = da_labels[::2, ::2]\n",
529-
" da_labels_ds = da_labels_ds.rechunk()\n",
530-
"\n",
531-
" da_labels_ds.to_zarr(\n",
532-
" \"CMU-1_Crop_labels_cellpose_cyto3.zarr\",\n",
533-
" component=str(s),\n",
534-
" write_empty_chunks=False,\n",
535-
" compressor=zarr.Blosc(clevel=9),\n",
536-
" overwrite=True\n",
537-
" )"
538-
]
539-
},
540-
{
541-
"cell_type": "code",
542-
"execution_count": null,
543-
"metadata": {
544-
"cellView": "form",
545-
"id": "Bh6c9EVy9hST"
546-
},
494+
"metadata": {},
547495
"outputs": [],
548-
"source": [
549-
"z_labels = zarr.open(\"CMU-1_Crop_labels_cellpose_cyto3.zarr\", mode=\"a\")"
550-
]
496+
"source": []
551497
},
552498
{
553499
"cell_type": "markdown",
@@ -558,7 +504,7 @@
558504
},
559505
{
560506
"cell_type": "code",
561-
"execution_count": null,
507+
"execution_count": 76,
562508
"metadata": {
563509
"cellView": "form",
564510
"id": "Bh6c9EVy9hST"
@@ -585,7 +531,7 @@
585531
" \"path\" : str(s),\n",
586532
" \"coordinateTransformations\": [\n",
587533
" {\n",
588-
" \"scale\" : [4.942E-4 / (2**s), 4.942E-4 / (2**s)],\n",
534+
" \"scale\" : [0.499 / (2**s), 0.499 / (2**s)],\n",
589535
" \"type\" : \"scale\"\n",
590536
" }\n",
591537
" ]\n",
@@ -600,13 +546,9 @@
600546
{
601547
"cell_type": "code",
602548
"execution_count": null,
603-
"metadata": {
604-
"id": "giJcwW_F3vrF"
605-
},
549+
"metadata": {},
606550
"outputs": [],
607-
"source": [
608-
"z_labels = zarr.open(\"CMU-1_Crop_labels_cellpose_cyto3.zarr\", mode=\"r\")"
609-
]
551+
"source": []
610552
},
611553
{
612554
"cell_type": "markdown",

0 commit comments

Comments
 (0)