Skip to content

Commit bf16f18

Browse files
committed
auto download
1 parent de56c9b commit bf16f18

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

dockerfiles/RunCellpose_CellposeOmnipose/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NAME ?= runcellpose_omnipose_no_pretrained
1+
NAME ?= runcellpose_omnipose_with_pretrained
22
TAG ?= 1.0.2
33
REPO ?= cellprofiler
44
IMG := $(REPO)/$(NAME):$(TAG)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import cellpose
2+
import cellpose_omni
3+
from cellpose.models import MODEL_NAMES
4+
5+
for m in ["cyto", "nuclei", "cyto2"]:
6+
model = cellpose.models.Cellpose(gpu=True, model_type=m)
7+
if model in ("cyto", "nuclei", "cyto2"):
8+
size_model_name = cellpose.models.size_model_path(model)
9+
10+
import urllib.request
11+
import zipfile
12+
import os
13+
14+
url = "https://files.osf.io/v1/resources/xmury/providers/osfstorage/646d978ef4be380b5362bb64/?zip="
15+
filename = "omnipose_models.zip"
16+
17+
try:
18+
urllib.request.urlretrieve(url, filename)
19+
print(f"File downloaded successfully to {filename}")
20+
except Exception as e:
21+
print(f"Error downloading file: {e}")
22+
23+
destination_directory = os.path.expanduser("~/.cellpose/models/")
24+
25+
# Create the destination directory if it doesn't already exist
26+
os.makedirs(destination_directory, exist_ok=True)
27+
28+
try:
29+
# Open the zip file in read mode ('r')
30+
with zipfile.ZipFile(filename, 'r') as zip_ref:
31+
print(f"Extracting all contents of '{filename}' to '{destination_directory}'...")
32+
# Extract all the contents to the specified directory
33+
zip_ref.extractall(destination_directory)
34+
except Exception as e:
35+
print(f"An unexpected error occurred: {e}")

0 commit comments

Comments
 (0)