Skip to content

Commit 165f52a

Browse files
committed
docker minus credentials
1 parent 2d23e63 commit 165f52a

File tree

4 files changed

+71
-53
lines changed

4 files changed

+71
-53
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RUN pip install -e .
1919
RUN chmod +x ./.aws.sh
2020
RUN ./.aws.sh
2121

22-
22+
CMD python experiments/BrainLine/scripts/soma_detect_image.py
2323

2424
# Old version
2525
# FROM python:3.8-slim
@@ -28,7 +28,7 @@ RUN ./.aws.sh
2828
# WORKDIR /usr/src/app
2929

3030
# #RUN apt-get update \
31-
# # && apt-get install -y --no-install-recommends git \
31+
# # && apt-get install -y --no-install-recommends git
3232
# # && apt-get purge -y --auto-remove \
3333
# RUN apt-get update
3434
# RUN apt-get install -y --no-install-recommends \

brainlit/BrainLine/apply_ilastik.py

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,9 @@ def apply_ilastik_parallel(
495495
corners_chunks = [corners[i : i + 100] for i in range(0, len(corners), 100)]
496496

497497
for corners_chunk in tqdm(corners_chunks, desc="corner chunks"):
498-
Parallel(n_jobs=self.ncpu)(
499-
delayed(self._process_chunk)(
498+
if self.ncpu == 1:
499+
for corner in tqdm(corners_chunk, leave=False):
500+
self._process_chunk(
500501
corner[0],
501502
corner[1],
502503
volume_base_dir,
@@ -506,8 +507,20 @@ def apply_ilastik_parallel(
506507
self.object_type,
507508
results_dir,
508509
)
509-
for corner in tqdm(corners_chunk, leave=False)
510-
)
510+
else:
511+
Parallel(n_jobs=self.ncpu)(
512+
delayed(self._process_chunk)(
513+
corner[0],
514+
corner[1],
515+
volume_base_dir,
516+
layer_names,
517+
threshold,
518+
data_dir,
519+
self.object_type,
520+
results_dir,
521+
)
522+
for corner in tqdm(corners_chunk, leave=False)
523+
)
511524
for f in os.listdir(data_dir):
512525
os.remove(os.path.join(data_dir, f))
513526

@@ -566,50 +579,58 @@ def _process_chunk(
566579
fname = f"image_{c1[0]}_{c1[1]}_{c1[2]}.h5"
567580
fname = data_dir / fname
568581

569-
with h5py.File(fname, "w") as f:
570-
dset = f.create_dataset("image_3channel", data=image_3channel)
571-
572-
subprocess.run(
573-
[
574-
f"{self.ilastik_path}",
575-
"--headless",
576-
f"--project={self.ilastik_project}",
577-
fname,
578-
],
579-
stdout=subprocess.PIPE,
580-
stderr=subprocess.PIPE,
581-
)
582-
# subprocess.run(["/Applications/ilastik-1.3.3post3-OSX.app/Contents/ilastik-release/run_ilastik.sh", "--headless", "--project=/Users/thomasathey/Documents/mimlab/mouselight/ailey/benchmark_formal/brain3/matt_benchmark_formal_brain3.ilp", fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
583-
584-
fname_prob = str(fname).split(".")[0] + "_Probabilities.h5"
585-
with h5py.File(fname_prob, "r") as f:
586-
pred = f.get("exported_data")
587-
if object_type == "soma":
588-
fname_results = f"image_{c1[0]}_{c1[1]}_{c1[2]}_somas.txt"
589-
fname_results = results_dir / fname_results
590-
pred = pred[0, :, :, :]
591-
mask = pred > threshold
592-
labels = measure.label(mask)
593-
props = measure.regionprops(labels)
582+
for attempt in range(3):
583+
with h5py.File(fname, "w") as f:
584+
dset = f.create_dataset("image_3channel", data=image_3channel)
594585

595-
results = []
596-
for prop in props:
597-
if prop["area"] > area_threshold:
598-
location = list(np.add(c1, prop["centroid"]))
599-
results.append(location)
600-
if len(results) > 0:
601-
with open(fname_results, "w") as f2:
602-
for location in results:
603-
f2.write(str(location))
604-
f2.write("\n")
605-
elif object_type == "axon":
606-
dir_mask = volume_base_dir + "axon_mask"
607-
vol_mask = CloudVolume(
608-
dir_mask, parallel=1, mip=mip, fill_missing=True, compress=False
609-
)
610-
pred = pred[1, :, :, :]
611-
mask = np.array(pred > threshold).astype("uint64")
612-
vol_mask[c1[0] : c2[0], c1[1] : c2[1], c1[2] : c2[2]] = mask
586+
subprocess.run(
587+
[
588+
f"{self.ilastik_path}",
589+
"--headless",
590+
f"--project={self.ilastik_project}",
591+
fname,
592+
],
593+
stdout=subprocess.PIPE,
594+
stderr=subprocess.PIPE,
595+
)
596+
597+
fname_prob = str(fname).split(".")[0] + "_Probabilities.h5"
598+
try:
599+
with h5py.File(fname_prob, "r") as f:
600+
pred = f.get("exported_data")
601+
except:
602+
if attempt >= 2:
603+
raise ValueError(f"Tried to evaluate thrice and failed")
604+
if os.path.isfile(fname_prob):
605+
os.remove(fname_prob)
606+
continue
607+
608+
if object_type == "soma":
609+
fname_results = f"image_{c1[0]}_{c1[1]}_{c1[2]}_somas.txt"
610+
fname_results = results_dir / fname_results
611+
pred = pred[0, :, :, :]
612+
mask = pred > threshold
613+
labels = measure.label(mask)
614+
props = measure.regionprops(labels)
615+
616+
results = []
617+
for prop in props:
618+
if prop["area"] > area_threshold:
619+
location = list(np.add(c1, prop["centroid"]))
620+
results.append(location)
621+
if len(results) > 0:
622+
with open(fname_results, "w") as f2:
623+
for location in results:
624+
f2.write(str(location))
625+
f2.write("\n")
626+
elif object_type == "axon":
627+
dir_mask = volume_base_dir + "axon_mask"
628+
vol_mask = CloudVolume(
629+
dir_mask, parallel=1, mip=mip, fill_missing=True, compress=False
630+
)
631+
pred = pred[1, :, :, :]
632+
mask = np.array(pred > threshold).astype("uint64")
633+
vol_mask[c1[0] : c2[0], c1[1] : c2[1], c1[2] : c2[2]] = mask
613634

614635
def collect_soma_results(self, brain_id: str):
615636
"""Combine all soma detections and post to neuroglancer. Intended for use after apply_ilastik_parallel.

experiments/BrainLine/scripts/soma_detect_image.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
# Ilastik will run in "headless mode", and the following paths are needed to do so:
3838
ilastik_path = "/brainlit_dir/ilastik-1.4.0-Linux/run_ilastik.sh" # "/Applications/ilastik-1.4.0b21-OSX.app/Contents/ilastik-release/run_ilastik.sh" # "/data/tathey1/matt_wright/ilastik/ilastik-1.4.0rc5-Linux/run_ilastik.sh" # path to ilastik executable
3939
ilastik_project = "/brainlit_dir/experiments/BrainLine/data/models/soma/matt_soma_rabies_pix_3ch.ilp" # "/Users/thomasathey/Documents/mimlab/mouselight/ailey/detection_soma/matt_soma_rabies_pix_3ch.ilp" # "/data/tathey1/matt_wright/ilastik/soma_model/matt_soma_rabies_pix_3ch.ilp" # path to ilastik project
40-
ilastik_path = "/Applications/ilastik-1.4.0b21-OSX.app/Contents/ilastik-release/run_ilastik.sh" # "/data/tathey1/matt_wright/ilastik/ilastik-1.4.0rc5-Linux/run_ilastik.sh" # path to ilastik executable
41-
ilastik_project = "/Users/thomasathey/Documents/mimlab/mouselight/brainlit_parent/brainlit/experiments/BrainLine/data/models/soma/matt_soma_rabies_pix_3ch.ilp" # "/data/tathey1/matt_wright/ilastik/soma_model/matt_soma_rabies_pix_3ch.ilp" # path to ilastik project
42-
4340

4441

4542
min_coords = [544, 1660, -1]

experiments/BrainLine/soma_analysis.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@
704704
"metadata": {},
705705
"source": [
706706
"```\n",
707-
"python -m cloudreg.scripts.registration -input_s3_path precomputed://s3://smartspim-precomputed-volumes/2023_04_12/MS37/Ch_561 --output_s3_path precomputed://s3://smartspim-precomputed-volumes/2023_04_12/MS37/atlas_to_target --atlas_s3_path https://open-neurodata.s3.amazonaws.com/ara_2016/sagittal_50um/average_50um --parcellation_s3_path https://open-neurodata.s3.amazonaws.com/ara_2016/sagittal_10um/annotation_10um_2017 --atlas_orientation PIR -orientation RAI --rotation 0 0 0 --translation 0 0 0 --fixed_scale 1.07 -log_s3_path precomputed://s3://smartspim-precomputed-volumes/2023_04_12/MS37/atlas_to_target --missing_data_correction True --grid_correction False --bias_correction True --regularization 5000.0 --iterations 3000 --registration_resolution 100\n",
707+
"python -m cloudreg.scripts.registration -input_s3_path precomputed://s3://smartspim-precomputed-volumes/2023_04_14/MS25/Ch_561 --output_s3_path precomputed://s3://smartspim-precomputed-volumes/2023_04_14/MS25/atlas_to_target --atlas_s3_path https://open-neurodata.s3.amazonaws.com/ara_2016/sagittal_50um/average_50um --parcellation_s3_path https://open-neurodata.s3.amazonaws.com/ara_2016/sagittal_10um/annotation_10um_2017 --atlas_orientation PIR -orientation RPI --rotation 0 0 0 --translation 0 0 0 --fixed_scale 1. -log_s3_path precomputed://s3://smartspim-precomputed-volumes/2023_04_14/MS25/atlas_to_target --missing_data_correction True --grid_correction False --bias_correction True --regularization 5000.0 --iterations 3000 --registration_resolution 100\n",
708708
"```"
709709
]
710710
},

0 commit comments

Comments
 (0)