From 126cf88d7dea1860bb46c4e4d534faac78ffe16d Mon Sep 17 00:00:00 2001 From: Nodar Gogoberidze Date: Wed, 14 Feb 2024 15:29:34 -0500 Subject: [PATCH 1/8] Make dockerfile for cellpose with omnipose --- dockerfiles/RunCellposeOmnipose/Dockerfile | 9 +++++++++ dockerfiles/RunCellposeOmnipose/Makefile | 23 ++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 dockerfiles/RunCellposeOmnipose/Dockerfile create mode 100644 dockerfiles/RunCellposeOmnipose/Makefile diff --git a/dockerfiles/RunCellposeOmnipose/Dockerfile b/dockerfiles/RunCellposeOmnipose/Dockerfile new file mode 100644 index 00000000..9c2f395c --- /dev/null +++ b/dockerfiles/RunCellposeOmnipose/Dockerfile @@ -0,0 +1,9 @@ +FROM pytorch/pytorch:1.13.0-cuda11.6-cudnn8-runtime + +RUN pip install cellpose==1.0.2 +RUN pip install omnipose + +RUN sed -i 's/from\ scipy\ import\ fft/from\ scipy.fftpack import\ fft/g' /opt/conda/lib/python3.9/site-packages/peakdetect/peakdetect.py + +# COPY download_cellpose_models.py / +# RUN python /download_cellpose_models.py diff --git a/dockerfiles/RunCellposeOmnipose/Makefile b/dockerfiles/RunCellposeOmnipose/Makefile new file mode 100644 index 00000000..c1aca1f8 --- /dev/null +++ b/dockerfiles/RunCellposeOmnipose/Makefile @@ -0,0 +1,23 @@ +NAME ?= runcellpose_omnipose_no_pretrained +TAG ?= 0.0.1 +REPO ?= cellprofiler +IMG := $(REPO)/$(NAME):$(TAG) + +.PHONEY: build +build: + docker build -t $(IMG) . + +.PHONY: run +run: + docker run \ + -it --rm \ + $(IMG) \ + bash + +.PHONY: deploy +deploy: + docker image push $(IMG) + +.PHONY: clean_docker +clean_docker: + docker rmi $(IMG) diff --git a/setup.py b/setup.py index 4508d1fd..abce419d 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ install_deps = [ "cellprofiler", "cellprofiler-core", - ] + ] cellpose_deps = [ "cellpose>=1.0.2" From a68b686b236f90e3a465d1cd547b5418780079ca Mon Sep 17 00:00:00 2001 From: Nodar Gogoberidze Date: Wed, 14 Feb 2024 15:33:37 -0500 Subject: [PATCH 2/8] Remove commented out line --- dockerfiles/RunCellposeOmnipose/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/dockerfiles/RunCellposeOmnipose/Dockerfile b/dockerfiles/RunCellposeOmnipose/Dockerfile index 9c2f395c..635eb0b2 100644 --- a/dockerfiles/RunCellposeOmnipose/Dockerfile +++ b/dockerfiles/RunCellposeOmnipose/Dockerfile @@ -4,6 +4,3 @@ RUN pip install cellpose==1.0.2 RUN pip install omnipose RUN sed -i 's/from\ scipy\ import\ fft/from\ scipy.fftpack import\ fft/g' /opt/conda/lib/python3.9/site-packages/peakdetect/peakdetect.py - -# COPY download_cellpose_models.py / -# RUN python /download_cellpose_models.py From 24104980e1c62d1e3addd0dfa59e5761fee22d41 Mon Sep 17 00:00:00 2001 From: Nodar Gogoberidze Date: Wed, 14 Feb 2024 15:35:26 -0500 Subject: [PATCH 3/8] Add comment explaining hotfix --- dockerfiles/RunCellposeOmnipose/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dockerfiles/RunCellposeOmnipose/Dockerfile b/dockerfiles/RunCellposeOmnipose/Dockerfile index 635eb0b2..79cd0ff5 100644 --- a/dockerfiles/RunCellposeOmnipose/Dockerfile +++ b/dockerfiles/RunCellposeOmnipose/Dockerfile @@ -3,4 +3,6 @@ FROM pytorch/pytorch:1.13.0-cuda11.6-cudnn8-runtime RUN pip install cellpose==1.0.2 RUN pip install omnipose +# hotfix for the now-deprecated `peakdetect` package +# latest omnipose on github fixes this by no longer using `peakdetect` library, but not on pypi RUN sed -i 's/from\ scipy\ import\ fft/from\ scipy.fftpack import\ fft/g' /opt/conda/lib/python3.9/site-packages/peakdetect/peakdetect.py From 4e80f5a676e00237e2130bd7e41d9087fcb45469 Mon Sep 17 00:00:00 2001 From: ErinWeisbart <54687786+ErinWeisbart@users.noreply.github.com> Date: Thu, 31 Jul 2025 12:34:57 -0700 Subject: [PATCH 4/8] rename folder to match #276 --- .../Dockerfile | 0 .../Makefile | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename dockerfiles/{RunCellposeOmnipose => RunCellpose_CellposeOmnipose}/Dockerfile (100%) rename dockerfiles/{RunCellposeOmnipose => RunCellpose_CellposeOmnipose}/Makefile (100%) diff --git a/dockerfiles/RunCellposeOmnipose/Dockerfile b/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile similarity index 100% rename from dockerfiles/RunCellposeOmnipose/Dockerfile rename to dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile diff --git a/dockerfiles/RunCellposeOmnipose/Makefile b/dockerfiles/RunCellpose_CellposeOmnipose/Makefile similarity index 100% rename from dockerfiles/RunCellposeOmnipose/Makefile rename to dockerfiles/RunCellpose_CellposeOmnipose/Makefile From 5704ed0a3c13fe16e70fcf96697d34872b4f172a Mon Sep 17 00:00:00 2001 From: ErinWeisbart <54687786+ErinWeisbart@users.noreply.github.com> Date: Thu, 31 Jul 2025 12:44:02 -0700 Subject: [PATCH 5/8] change versioning to match current structure --- dockerfiles/RunCellpose_CellposeOmnipose/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/RunCellpose_CellposeOmnipose/Makefile b/dockerfiles/RunCellpose_CellposeOmnipose/Makefile index c1aca1f8..5546139f 100644 --- a/dockerfiles/RunCellpose_CellposeOmnipose/Makefile +++ b/dockerfiles/RunCellpose_CellposeOmnipose/Makefile @@ -1,5 +1,5 @@ NAME ?= runcellpose_omnipose_no_pretrained -TAG ?= 0.0.1 +TAG ?= 1.0.2 REPO ?= cellprofiler IMG := $(REPO)/$(NAME):$(TAG) From de56c9ba3a7b825fc17bedc918ff511ead7159b0 Mon Sep 17 00:00:00 2001 From: ErinWeisbart <54687786+ErinWeisbart@users.noreply.github.com> Date: Thu, 31 Jul 2025 15:20:14 -0700 Subject: [PATCH 6/8] explicit download of models --- dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile b/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile index 79cd0ff5..a284cfe1 100644 --- a/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile +++ b/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile @@ -6,3 +6,7 @@ RUN pip install omnipose # hotfix for the now-deprecated `peakdetect` package # latest omnipose on github fixes this by no longer using `peakdetect` library, but not on pypi RUN sed -i 's/from\ scipy\ import\ fft/from\ scipy.fftpack import\ fft/g' /opt/conda/lib/python3.9/site-packages/peakdetect/peakdetect.py + +# Include if you wish the image to contain Cellpose pretrained models +COPY download_cellpose_models.py / +RUN python /download_cellpose_models.py \ No newline at end of file From bf16f186adcbfa03294b751bd0983a90d8fce966 Mon Sep 17 00:00:00 2001 From: ErinWeisbart <54687786+ErinWeisbart@users.noreply.github.com> Date: Thu, 31 Jul 2025 15:25:46 -0700 Subject: [PATCH 7/8] auto download --- .../RunCellpose_CellposeOmnipose/Makefile | 2 +- .../download_cellpose_models.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 dockerfiles/RunCellpose_CellposeOmnipose/download_cellpose_models.py diff --git a/dockerfiles/RunCellpose_CellposeOmnipose/Makefile b/dockerfiles/RunCellpose_CellposeOmnipose/Makefile index 5546139f..b3d84b23 100644 --- a/dockerfiles/RunCellpose_CellposeOmnipose/Makefile +++ b/dockerfiles/RunCellpose_CellposeOmnipose/Makefile @@ -1,4 +1,4 @@ -NAME ?= runcellpose_omnipose_no_pretrained +NAME ?= runcellpose_omnipose_with_pretrained TAG ?= 1.0.2 REPO ?= cellprofiler IMG := $(REPO)/$(NAME):$(TAG) diff --git a/dockerfiles/RunCellpose_CellposeOmnipose/download_cellpose_models.py b/dockerfiles/RunCellpose_CellposeOmnipose/download_cellpose_models.py new file mode 100644 index 00000000..4ce13ccb --- /dev/null +++ b/dockerfiles/RunCellpose_CellposeOmnipose/download_cellpose_models.py @@ -0,0 +1,35 @@ +import cellpose +import cellpose_omni +from cellpose.models import MODEL_NAMES + +for m in ["cyto", "nuclei", "cyto2"]: + model = cellpose.models.Cellpose(gpu=True, model_type=m) + if model in ("cyto", "nuclei", "cyto2"): + size_model_name = cellpose.models.size_model_path(model) + +import urllib.request +import zipfile +import os + +url = "https://files.osf.io/v1/resources/xmury/providers/osfstorage/646d978ef4be380b5362bb64/?zip=" +filename = "omnipose_models.zip" + +try: + urllib.request.urlretrieve(url, filename) + print(f"File downloaded successfully to {filename}") +except Exception as e: + print(f"Error downloading file: {e}") + +destination_directory = os.path.expanduser("~/.cellpose/models/") + +# Create the destination directory if it doesn't already exist +os.makedirs(destination_directory, exist_ok=True) + +try: + # Open the zip file in read mode ('r') + with zipfile.ZipFile(filename, 'r') as zip_ref: + print(f"Extracting all contents of '{filename}' to '{destination_directory}'...") + # Extract all the contents to the specified directory + zip_ref.extractall(destination_directory) +except Exception as e: + print(f"An unexpected error occurred: {e}") \ No newline at end of file From 55fa00b1d7d61760a5781ac87d5b786e3b323fef Mon Sep 17 00:00:00 2001 From: ErinWeisbart <54687786+ErinWeisbart@users.noreply.github.com> Date: Mon, 4 Aug 2025 11:23:33 -0700 Subject: [PATCH 8/8] get rid of not working file download --- .../RunCellpose_CellposeOmnipose/Dockerfile | 4 --- .../RunCellpose_CellposeOmnipose/Makefile | 2 +- .../download_cellpose_models.py | 35 ------------------- 3 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 dockerfiles/RunCellpose_CellposeOmnipose/download_cellpose_models.py diff --git a/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile b/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile index a284cfe1..79cd0ff5 100644 --- a/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile +++ b/dockerfiles/RunCellpose_CellposeOmnipose/Dockerfile @@ -6,7 +6,3 @@ RUN pip install omnipose # hotfix for the now-deprecated `peakdetect` package # latest omnipose on github fixes this by no longer using `peakdetect` library, but not on pypi RUN sed -i 's/from\ scipy\ import\ fft/from\ scipy.fftpack import\ fft/g' /opt/conda/lib/python3.9/site-packages/peakdetect/peakdetect.py - -# Include if you wish the image to contain Cellpose pretrained models -COPY download_cellpose_models.py / -RUN python /download_cellpose_models.py \ No newline at end of file diff --git a/dockerfiles/RunCellpose_CellposeOmnipose/Makefile b/dockerfiles/RunCellpose_CellposeOmnipose/Makefile index b3d84b23..5546139f 100644 --- a/dockerfiles/RunCellpose_CellposeOmnipose/Makefile +++ b/dockerfiles/RunCellpose_CellposeOmnipose/Makefile @@ -1,4 +1,4 @@ -NAME ?= runcellpose_omnipose_with_pretrained +NAME ?= runcellpose_omnipose_no_pretrained TAG ?= 1.0.2 REPO ?= cellprofiler IMG := $(REPO)/$(NAME):$(TAG) diff --git a/dockerfiles/RunCellpose_CellposeOmnipose/download_cellpose_models.py b/dockerfiles/RunCellpose_CellposeOmnipose/download_cellpose_models.py deleted file mode 100644 index 4ce13ccb..00000000 --- a/dockerfiles/RunCellpose_CellposeOmnipose/download_cellpose_models.py +++ /dev/null @@ -1,35 +0,0 @@ -import cellpose -import cellpose_omni -from cellpose.models import MODEL_NAMES - -for m in ["cyto", "nuclei", "cyto2"]: - model = cellpose.models.Cellpose(gpu=True, model_type=m) - if model in ("cyto", "nuclei", "cyto2"): - size_model_name = cellpose.models.size_model_path(model) - -import urllib.request -import zipfile -import os - -url = "https://files.osf.io/v1/resources/xmury/providers/osfstorage/646d978ef4be380b5362bb64/?zip=" -filename = "omnipose_models.zip" - -try: - urllib.request.urlretrieve(url, filename) - print(f"File downloaded successfully to {filename}") -except Exception as e: - print(f"Error downloading file: {e}") - -destination_directory = os.path.expanduser("~/.cellpose/models/") - -# Create the destination directory if it doesn't already exist -os.makedirs(destination_directory, exist_ok=True) - -try: - # Open the zip file in read mode ('r') - with zipfile.ZipFile(filename, 'r') as zip_ref: - print(f"Extracting all contents of '{filename}' to '{destination_directory}'...") - # Extract all the contents to the specified directory - zip_ref.extractall(destination_directory) -except Exception as e: - print(f"An unexpected error occurred: {e}") \ No newline at end of file