-
Notifications
You must be signed in to change notification settings - Fork 1
Parallelize prediction #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
85ae0e3
Convert tif to n5 file format.
schilling40 51cc1b9
Resize wrongly scaled cochleas
schilling40 236f7d0
Prediction distance unet with multiple GPUs
schilling40 8f2dfb1
Fixed argument parsing
schilling40 40f0813
Fixed requirement of SLURM_ARRAY_TASK_ID
schilling40 41067ef
Fix error in cochlea rescaling
constantinpape 230b806
Fixed missing import
schilling40 12799b1
Script for counting cells in segmentation
schilling40 e185ee1
Calculation of mean and standard deviation as preprocessing
schilling40 5473462
Extract sub-volume of n5 file
schilling40 d26f2c6
Small changes and documentation
schilling40 9e4588a
Support of S3 bucket for block extraction
schilling40 a6ff2d2
Distance U-Net prediction with CPU
schilling40 9d3a61f
Fixed issue with chunk reference
schilling40 5a5207d
Improved style
schilling40 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import os, sys | ||
| import argparse | ||
| import pybdv | ||
| import imageio.v3 as imageio | ||
|
|
||
|
|
||
| def main(input_path, output_path): | ||
| if not os.path.isfile(input_path): | ||
| sys.exit("Input file does not exist.") | ||
|
|
||
| if input_path.split(".")[-1] not in ["TIFF", "TIF", "tiff", "tif"]: | ||
| sys.exit("Input file must be in tif format.") | ||
|
|
||
| basename = "".join(input_path.split("/")[-1].split(".")[:-1]) | ||
| input_dir = input_path.split(basename)[0] | ||
| input_dir = os.path.abspath(input_dir) | ||
|
|
||
| if "" == output_path: | ||
| output_path = os.path.join(input_dir, basename + ".n5") | ||
| img = imageio.imread(input_path) | ||
| pybdv.make_bdv(img, output_path) | ||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| parser = argparse.ArgumentParser( | ||
| description="Script to transform file from tif into n5 format.") | ||
|
|
||
| parser.add_argument('input', type=str, help="Input file") | ||
| parser.add_argument('-o', "--output", type=str, default="", help="Output file") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| main(args.input, args.output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import argparse | ||
| import sys, os | ||
|
|
||
| import multiprocessing as mp | ||
| from concurrent import futures | ||
|
|
||
| import imageio.v3 as imageio | ||
| import numpy as np | ||
| import nifty.tools as nt | ||
| from tqdm import tqdm | ||
|
|
||
| from elf.wrapper.resized_volume import ResizedVolume | ||
| from elf.io import open_file | ||
|
|
||
| def main(input_path, output_folder, scale, input_key, interpolation_order): | ||
| input_ = open_file(input_path, "r")[input_key] | ||
|
|
||
| abs_path = os.path.abspath(input_path) | ||
| basename = "".join(os.path.basename(abs_path).split(".")[:-1]) | ||
| output_path = os.path.join(output_folder, basename + "_resized.n5") | ||
|
|
||
| shape = input_.shape | ||
| ndim = len(shape) | ||
|
|
||
| # Limit the number of cores for parallelization. | ||
| n_threads = min(16, mp.cpu_count()) | ||
|
|
||
| shape = input_.shape | ||
| new_shape = tuple( | ||
| int(round(sh / scale)) for sh in shape | ||
| ) | ||
|
|
||
| resized_volume = ResizedVolume(input_, new_shape, order=interpolation_order) | ||
|
|
||
| output = open_file(output_path, mode="a") | ||
| dataset = output.create_dataset(input_key, shape=new_shape, dtype = input_.dtype, chunks=input_.chunks, compression="gzip") | ||
| blocking = nt.blocking([0] * ndim, new_shape, input_.chunks) | ||
|
|
||
| def copy_chunk(block_index): | ||
| block = blocking.getBlock(block_index) | ||
| volume_index = tuple(slice(begin, end) for (begin, end) in zip(block.begin, block.end)) | ||
| data = resized_volume[volume_index] | ||
| output[volume_index] = data | ||
|
|
||
| with futures.ThreadPoolExecutor(n_threads) as resize_pool: | ||
| list(tqdm(resize_pool.map(copy_chunk, range(blocking.numberOfBlocks)), total=blocking.numberOfBlocks)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| parser = argparse.ArgumentParser( | ||
| description="Script for resizing microscoopy data in n5 format.") | ||
|
|
||
| parser.add_argument('input_file', type=str, help="Input file") | ||
| parser.add_argument('output_folder', type=str, help="Output folder. Default resized output is <basename>_resized.n5") | ||
|
|
||
| parser.add_argument('-s', "--scale", type=float, default=0.38, help="Scale of input. Re-scaled to 1.") | ||
| parser.add_argument('-k', "--input_key", type=str, default="setup0/timepoint0/s0", help="Input key for n5 file.") | ||
| parser.add_argument('-i', "--interpolation_order", type=float, default=3, help="Interpolation order.") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| main(args.input, args.output, args.scale, args.input_key, args.interpolation_order) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.