Skip to content
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

Add norm percentiles as CLI argument #1058

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions cellpose/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def main():
default_model = "cyto3"
backbone = "default"

if args.norm_percentile is not None:
value1, value2 = args.norm_percentile
normalize = {'percentile': (float(value1), float(value2))}
else:
normalize = (not args.no_norm)


model_type = None
if pretrained_model and not os.path.exists(pretrained_model):
model_type = pretrained_model if pretrained_model is not None else "cyto3"
Expand Down Expand Up @@ -209,7 +216,7 @@ def main():
cellprob_threshold=args.cellprob_threshold,
stitch_threshold=args.stitch_threshold, min_size=args.min_size,
invert=args.invert, batch_size=args.batch_size,
interp=(not args.no_interp), normalize=(not args.no_norm),
interp=(not args.no_interp), normalize=normalize,
channel_axis=args.channel_axis, z_axis=args.z_axis,
anisotropy=args.anisotropy, niter=args.niter,
dP_smooth=args.dP_smooth)
Expand Down Expand Up @@ -303,7 +310,7 @@ def main():
test_data=test_images, test_labels=test_labels,
test_files=image_names_test, train_probs=train_probs,
test_probs=test_probs, compute_flows=compute_flows,
load_files=load_files, normalize=(not args.no_norm),
load_files=load_files, normalize=normalize,
channels=channels, channel_axis=args.channel_axis, rgb=(nchan == 3),
learning_rate=args.learning_rate, weight_decay=args.weight_decay,
SGD=args.SGD, n_epochs=args.n_epochs, batch_size=args.batch_size,
Expand All @@ -327,7 +334,7 @@ def main():
load_files=load_files, channels=channels,
min_train_masks=args.min_train_masks,
channel_axis=args.channel_axis, rgb=(nchan == 3),
nimg_per_epoch=args.nimg_per_epoch, normalize=(not args.no_norm),
nimg_per_epoch=args.nimg_per_epoch, normalize=normalize,
nimg_test_per_epoch=args.nimg_test_per_epoch,
batch_size=args.batch_size)
if test_images is not None:
Expand Down
6 changes: 6 additions & 0 deletions cellpose/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def get_arg_parser():
help="do not interpolate when running dynamics (was default)")
algorithm_args.add_argument("--no_norm", action="store_true",
help="do not normalize images (normalize=False)")
parser.add_argument(
'--norm_percentile',
nargs=2, # Require exactly two values
metavar=('VALUE1', 'VALUE2'),
help="Provide two float values to set norm_percentile (e.g., --norm_percentile 1 99)"
)
algorithm_args.add_argument(
"--do_3D", action="store_true",
help="process images as 3D stacks of images (nplanes x nchan x Ly x Lx")
Expand Down