Skip to content

Commit 09a7703

Browse files
crtrentzBenjamin Gorman
authored andcommitted
Remove (bool) from docstring, add type hints
Co-authored-by: Benjamin Gorman <[email protected]>
1 parent 4eae383 commit 09a7703

38 files changed

+144
-143
lines changed

monai/data/csv_saver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, output_dir: str = "./", filename: str = "predictions.csv", ov
3131
Args:
3232
output_dir (str): output CSV file directory.
3333
filename (str): name of the saved CSV file name.
34-
overwrite (bool): whether to overwriting existing CSV file content. If we are not overwriting,
34+
overwrite: whether to overwriting existing CSV file content. If we are not overwriting,
3535
then we check if the results have been previously saved, and load them to the prediction_dict.
3636
3737
"""

monai/data/dataloader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DataLoader(torch.utils.data.DataLoader):
2525
dataset (Dataset): dataset from which to load the data.
2626
batch_size: how many samples per batch to load
2727
(default: ``1``).
28-
shuffle (bool, optional): set to ``True`` to have the data reshuffled
28+
shuffle: set to ``True`` to have the data reshuffled
2929
at every epoch (default: ``False``).
3030
sampler (Sampler, optional): defines the strategy to draw samples from
3131
the dataset. If specified, :attr:`shuffle` must be ``False``.
@@ -35,11 +35,11 @@ class DataLoader(torch.utils.data.DataLoader):
3535
num_workers: how many subprocesses to use for data
3636
loading. ``0`` means that the data will be loaded in the main process.
3737
(default: ``0``)
38-
pin_memory (bool, optional): If ``True``, the data loader will copy Tensors
38+
pin_memory: If ``True``, the data loader will copy Tensors
3939
into CUDA pinned memory before returning them. If your data elements
4040
are a custom type, or your :attr:`collate_fn` returns a batch that is a custom type,
4141
see the example below.
42-
drop_last (bool, optional): set to ``True`` to drop the last incomplete batch,
42+
drop_last: set to ``True`` to drop the last incomplete batch,
4343
if the dataset size is not divisible by the batch size. If ``False`` and
4444
the size of dataset is not divisible by the batch size, then the last batch
4545
will be smaller. (default: ``False``)
@@ -53,7 +53,7 @@ def __init__(
5353
self,
5454
dataset,
5555
batch_size: Optional[int] = 1,
56-
shuffle=False,
56+
shuffle: bool = False,
5757
sampler=None,
5858
batch_sampler=None,
5959
num_workers: Optional[int] = 0,

monai/data/decathalon_datalist.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ def _append_paths(base_dir, is_segmentation, items):
3737
return items
3838

3939

40-
def load_decathalon_datalist(data_list_file_path, is_segmentation=True, data_list_key="training", base_dir=None):
40+
def load_decathalon_datalist(
41+
data_list_file_path, is_segmentation: bool = True, data_list_key="training", base_dir=None
42+
):
4143
"""Load image/label paths of decathalon challenge from JSON file
4244
4345
Json file is similar to what you get from http://medicaldecathlon.com/
4446
Those dataset.json files
4547
4648
Args:
4749
data_list_file_path (str): the path to the json file of datalist.
48-
is_segmentation (bool): whether the datalist is for segmentation task, default is True.
50+
is_segmentation: whether the datalist is for segmentation task, default is True.
4951
data_list_key (str): the key to get a list of dictionary to be used, default is "training".
5052
base_dir (str): the base directory of the dataset, if None, use the datalist directory.
5153

monai/data/nifti_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def __init__(
4242
image_files (list of str): list of image filenames
4343
seg_files (list of str): if in segmentation task, list of segmentation filenames
4444
labels (list or array): if in classification task, list of classification labels
45-
as_closest_canonical (bool): if True, load the image as closest to canonical orientation
45+
as_closest_canonical: if True, load the image as closest to canonical orientation
4646
transform (Callable, optional): transform to apply to image arrays
4747
seg_transform (Callable, optional): transform to apply to segmentation arrays
48-
image_only (bool): if True return only the image volume, other return image volume and header dict
48+
image_only: if True return only the image volume, other return image volume and header dict
4949
dtype (np.dtype, optional): if not None convert the loaded image to this data type
5050
"""
5151

monai/data/nifti_saver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
output_dir (str): output image directory.
4242
output_postfix (str): a string appended to all output file names.
4343
output_ext (str): output file extension name.
44-
resample (bool): whether to resample before saving the data array.
44+
resample: whether to resample before saving the data array.
4545
interp_order: the order of the spline interpolation, default is InterpolationCode.SPLINE3.
4646
The order has to be in the range 0 - 5.
4747
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.affine_transform.html

monai/data/nifti_writer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def write_nifti(
2121
file_name,
2222
affine=None,
2323
target_affine=None,
24-
resample=True,
24+
resample: bool = True,
2525
output_shape=None,
2626
interp_order=InterpolationCode.SPLINE3,
2727
mode="constant",
@@ -63,7 +63,7 @@ def write_nifti(
6363
target_affine (numpy.ndarray, optional): before saving
6464
the (`data`, `affine`) as a Nifti1Image,
6565
transform the data into the coordinates defined by `target_affine`.
66-
resample (bool): whether to run resampling when the target affine
66+
resample: whether to run resampling when the target affine
6767
could not be achieved by swapping/flipping data axes.
6868
output_shape (None or tuple of ints): output image shape.
6969
this option is used when resample = True.
@@ -126,8 +126,8 @@ def write_nifti(
126126
cval=cval,
127127
)
128128
)
129-
data_chns = np.stack(data_chns, axis=-1)
130-
data_ = data_chns.reshape(list(data_chns.shape[:3]) + list(channel_shape))
129+
data_chns_ = np.stack(data_chns, axis=-1)
130+
data_ = data_chns_.reshape(list(data_chns_.shape[:3]) + list(channel_shape))
131131
else:
132132
data_ = data.astype(dtype)
133133
data_ = scipy.ndimage.affine_transform(

monai/data/png_saver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
output_dir (str): output image directory.
4242
output_postfix (str): a string appended to all output file names.
4343
output_ext (str): output file extension name.
44-
resample (bool): whether to resample and resize if providing spatial_shape in the metadata.
44+
resample: whether to resample and resize if providing spatial_shape in the metadata.
4545
interp_order: the order of the spline interpolation, default is InterpolationCode.SPLINE3.
4646
This option is used when spatial_shape is specified and different from the data shape.
4747
The order has to be in the range 0 - 5.
@@ -50,7 +50,7 @@ def __init__(
5050
This option is used when spatial_shape is specified and different from the data shape.
5151
cval (scalar): Value to fill past edges of input if mode is "constant". Default is 0.0.
5252
This option is used when spatial_shape is specified and different from the data shape.
53-
scale (bool): whether to scale data with 255 and convert to uint8 for data in range [0, 1].
53+
scale: whether to scale data with 255 and convert to uint8 for data in range [0, 1].
5454
5555
"""
5656
self.output_dir = output_dir

monai/data/png_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def write_png(
2020
interp_order: int = 3,
2121
mode="constant",
2222
cval=0,
23-
scale=False,
23+
scale: bool = False,
2424
plugin=None,
2525
**plugin_args,
2626
):
@@ -41,7 +41,7 @@ def write_png(
4141
this option is used when `output_shape != None`.
4242
cval (scalar): Value to fill past edges of input if mode is "constant". Default is 0.0.
4343
this option is used when `output_shape != None`.
44-
scale (bool): whether to scale data with 255 and convert to uint8 for data in range [0, 1].
44+
scale: whether to scale data with 255 and convert to uint8 for data in range [0, 1].
4545
plugin (string): name of plugin to use in `imsave`. By default, the different plugins
4646
are tried(starting with imageio) until a suitable candidate is found.
4747
plugin_args (keywords): arguments passed to the given plugin.

monai/data/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def iter_patch(
157157
arr (np.ndarray): array to iterate over
158158
patch_size (tuple of int or None): size of patches to generate slices for, 0 or None selects whole dimension
159159
start_pos (tuple of it, optional): starting position in the array, default is 0 for each dimension
160-
copy_back (bool): if True data from the yielded patches is copied back to `arr` once the generator completes
160+
copy_back: if True data from the yielded patches is copied back to `arr` once the generator completes
161161
pad_mode (str, optional): padding mode, see `numpy.pad`
162162
pad_opts (dict, optional): padding options, see `numpy.pad`
163163
@@ -304,7 +304,7 @@ def zoom_affine(affine, scale, diagonal: bool = True):
304304
Args:
305305
affine (nxn matrix): a square matrix.
306306
scale (sequence of floats): new scaling factor along each dimension.
307-
diagonal (bool): whether to return a diagonal scaling matrix.
307+
diagonal: whether to return a diagonal scaling matrix.
308308
Defaults to True.
309309
310310
returns:

monai/engines/multi_gpu_supervised_trainer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def create_multigpu_supervised_trainer(
4444
loss_fn (`torch.nn` loss function): the loss function to use.
4545
devices (list, optional): device(s) type specification (default: None).
4646
Applies to both model and batches. None is all devices used, empty list is CPU only.
47-
non_blocking (bool, optional): if True and this copy is between CPU and GPU, the copy may occur asynchronously
47+
non_blocking: if True and this copy is between CPU and GPU, the copy may occur asynchronously
4848
with respect to the host. For other cases, this argument has no effect.
4949
prepare_batch (callable, optional): function that receives `batch`, `device`, `non_blocking` and outputs
5050
tuple of tensors `(batch_x, batch_y)`.
@@ -85,7 +85,7 @@ def create_multigpu_supervised_evaluator(
8585
metrics (dict of str - :class:`~ignite.metrics.Metric`): a map of metric names to Metrics.
8686
devices (list, optional): device(s) type specification (default: None).
8787
Applies to both model and batches. None is all devices used, empty list is CPU only.
88-
non_blocking (bool, optional): if True and this copy is between CPU and GPU, the copy may occur asynchronously
88+
non_blocking: if True and this copy is between CPU and GPU, the copy may occur asynchronously
8989
with respect to the host. For other cases, this argument has no effect.
9090
prepare_batch (callable, optional): function that receives `batch`, `device`, `non_blocking` and outputs
9191
tuple of tensors `(batch_x, batch_y)`.

monai/engines/trainer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SupervisedTrainer(Trainer):
5656
and `batchdata` as input parameters. if not provided, use `self._iteration()` instead.
5757
lr_scheduler (LR Scheduler): the lr scheduler associated to the optimizer.
5858
inferer (Inferer): inference method that execute model forward on input data, like: SlidingWindow, etc.
59-
amp (bool): whether to enable auto-mixed-precision training, reserved.
59+
amp: whether to enable auto-mixed-precision training, reserved.
6060
post_transform (Transform): execute additional transformation for the model output data.
6161
Typically, several Tensor based transforms composed by `Compose`.
6262
key_train_metric (ignite.metric): compute metric when every iteration completed, and save average value to

monai/engines/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Workflow(ABC, Engine):
2929
Args:
3030
device (torch.device): an object representing the device on which to run.
3131
max_epochs: the total epoch number for engine to run, validator and evaluator have only 1 epoch.
32-
amp (bool): whether to enable auto-mixed-precision training, reserved.
32+
amp: whether to enable auto-mixed-precision training, reserved.
3333
data_loader (torch.DataLoader): Ignite engine use data_loader to run, must be torch.DataLoader.
3434
prepare_batch (Callable): function to parse image and label for every iteration.
3535
iteration_update (Callable): the callable function for every iteration, expect to accept `engine`
@@ -49,7 +49,7 @@ def __init__(
4949
self,
5050
device,
5151
max_epochs: int,
52-
amp,
52+
amp: bool,
5353
data_loader,
5454
prepare_batch=default_prepare_batch,
5555
iteration_update=None,

monai/handlers/checkpoint_saver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class CheckpointSaver:
3030
3131
name (str): identifier of logging.logger to use, if None, defaulting to ``engine.logger``.
3232
file_prefix (str): prefix for the filenames to which objects will be saved.
33-
save_final (bool): whether to save checkpoint or session at final iteration or exception.
34-
save_key_metric (bool): whether to save checkpoint or session when the value of key_metric is
33+
save_final: whether to save checkpoint or session at final iteration or exception.
34+
save_key_metric: whether to save checkpoint or session when the value of key_metric is
3535
higher than all the previous values during training.keep 4 decimal places of metric,
3636
checkpoint name is: {file_prefix}_key_metric=0.XXXX.pth.
3737
key_metric_name (str): the name of key_metric in ignite metrics dictionary.
3838
if None, use `engine.state.key_metric` instead.
3939
key_metric_n_saved: save top N checkpoints or sessions, sorted by the value of key
4040
metric in descending order.
41-
epoch_level (bool): save checkpoint during training for every N epochs or every N iterations.
41+
epoch_level: save checkpoint during training for every N epochs or every N iterations.
4242
`True` is epoch level, `False` is iteration level.
4343
save_interval: save checkpoint every N epochs, default is 0 to save no checkpoint.
4444
n_saved: save latest N checkpoints of epoch level or iteration level, 'None' is to save all.

monai/handlers/classification_saver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434
Args:
3535
output_dir (str): output CSV file directory.
3636
filename (str): name of the saved CSV file name.
37-
overwrite (bool): whether to overwriting existing CSV file content. If we are not overwriting,
37+
overwrite: whether to overwriting existing CSV file content. If we are not overwriting,
3838
then we check if the results have been previously saved, and load them to the prediction_dict.
3939
batch_transform (Callable): a callable that is used to transform the
4040
ignite.engine.batch into expected format to extract the meta_data dictionary.

monai/handlers/lr_schedule_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def __init__(
3333
Args:
3434
lr_scheduler (torch.optim.lr_scheduler): typically, lr_scheduler should be PyTorch
3535
lr_scheduler object. If customized version, must have `step` and `get_last_lr` methods.
36-
print_lr (bool): whether to print out the latest learning rate with logging.
36+
print_lr: whether to print out the latest learning rate with logging.
3737
name (str): identifier of logging.logger to use, if None, defaulting to ``engine.logger``.
38-
epoch_level (bool): execute lr_scheduler.step() after every epoch or every iteration.
38+
epoch_level: execute lr_scheduler.step() after every epoch or every iteration.
3939
`True` is epoch level, `False` is iteration level.
4040
step_transform (Callable): a callable that is used to transform the information from `engine`
4141
to expected input data of lr_scheduler.step() function if necessary.

monai/handlers/mean_dice.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ def __init__(
3737
"""
3838
3939
Args:
40-
include_background (Bool): whether to include dice computation on the first channel of the predicted output.
40+
include_background: whether to include dice computation on the first channel of the predicted output.
4141
Defaults to True.
42-
to_onehot_y (Bool): whether to convert the output prediction into the one-hot format. Defaults to False.
43-
mutually_exclusive (Bool): if True, the output prediction will be converted into a binary matrix using
42+
to_onehot_y: whether to convert the output prediction into the one-hot format. Defaults to False.
43+
mutually_exclusive: if True, the output prediction will be converted into a binary matrix using
4444
a combination of argmax and to_onehot. Defaults to False.
45-
sigmoid (Bool): whether to add sigmoid function to the output prediction before computing Dice.
45+
sigmoid: whether to add sigmoid function to the output prediction before computing Dice.
4646
Defaults to False.
4747
logit_thresh (Float): the threshold value to round value to 0.0 and 1.0. Defaults to None (no thresholding).
4848
output_transform (Callable): transform the ignite.engine.state.output into [y_pred, y] pair.

monai/handlers/segmentation_saver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(
4242
output_dir (str): output image directory.
4343
output_postfix (str): a string appended to all output file names.
4444
output_ext (str): output file extension name.
45-
resample (bool): whether to resample before saving the data array.
45+
resample: whether to resample before saving the data array.
4646
interp_order: the order of the spline interpolation, default is 0.
4747
The order has to be in the range 0 - 5.
4848
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.affine_transform.html
@@ -52,7 +52,7 @@ def __init__(
5252
This option is used when `resample = True`.
5353
cval (scalar): Value to fill past edges of input if mode is "constant". Default is 0.0.
5454
This option is used when `resample = True`.
55-
scale (bool): whether to scale data with 255 and convert to uint8 for data in range [0, 1].
55+
scale: whether to scale data with 255 and convert to uint8 for data in range [0, 1].
5656
It's used for PNG format only.
5757
dtype (np.dtype, optional): convert the image data to save to this data type.
5858
If None, keep the original type of data. It's used for Nifti format only.

monai/handlers/tensorboard_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def __init__(
192192
summary_writer: Optional[SummaryWriter] = None,
193193
log_dir: str = "./runs",
194194
interval: int = 1,
195-
epoch_level=True,
195+
epoch_level: bool = True,
196196
batch_transform: Callable = lambda x: x,
197197
output_transform: Callable = lambda x: x,
198198
global_iter_transform: Callable = lambda x: x,
@@ -206,7 +206,7 @@ def __init__(
206206
default to create a new writer.
207207
log_dir (str): if using default SummaryWriter, write logs to this directory, default is `./runs`.
208208
interval: plot content from engine.state every N epochs or every N iterations, default is 1.
209-
epoch_level (bool): plot content from engine.state every N epochs or N iterations. `True` is epoch level,
209+
epoch_level: plot content from engine.state every N epochs or N iterations. `True` is epoch level,
210210
`False` is iteration level.
211211
batch_transform (Callable): a callable that is used to transform the
212212
``ignite.engine.batch`` into expected format to extract several label data.

monai/handlers/validation_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, validator: Evaluator, interval: int, epoch_level: bool = True
2525
Args:
2626
validator (Evaluator): run the validator when trigger validation, suppose to be Evaluator.
2727
interval: do validation every N epochs or every N iterations during training.
28-
epoch_level (bool): execute validation every N epochs or N iterations.
28+
epoch_level: execute validation every N epochs or N iterations.
2929
`True` is epoch level, `False` is iteration level.
3030
3131
"""

0 commit comments

Comments
 (0)