Skip to content

Commit 7f0f3c5

Browse files
authored
Merge branch 'master' into 1155-savitzky-golay-kernel
2 parents 7d48d87 + 3b20de8 commit 7f0f3c5

File tree

95 files changed

+1193
-557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1193
-557
lines changed

.deepsource.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version = 1
2+
3+
test_patterns = ["tests/**"]
4+
5+
exclude_patterns = [
6+
"monai/_version.py",
7+
"versioneer.py"
8+
]
9+
10+
[[analyzers]]
11+
name = "python"
12+
enabled = true
13+
14+
[analyzers.meta]
15+
runtime_version = "3.x.x"
16+
17+
[[analyzers]]
18+
name = "test-coverage"
19+
enabled = true
20+
21+
[[analyzers]]
22+
name = "docker"
23+
enabled = true
24+
25+
[[analyzers]]
26+
name = "shell"
27+
enabled = true

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@ Its ambitions are:
2929

3030

3131
## Installation
32-
To install [the current release](https://pypi.org/project/monai/):
32+
33+
### Installing [the current release](https://pypi.org/project/monai/):
3334
```bash
3435
pip install monai
3536
```
3637

37-
To install from the source code repository:
38+
### Installing the master branch from the source code repository:
3839
```bash
3940
pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI
4041
```
4142

42-
Alternatively, pre-built Docker image is available via [DockerHub](https://hub.docker.com/r/projectmonai/monai):
43+
### Using the pre-built Docker image [DockerHub](https://hub.docker.com/r/projectmonai/monai):
4344
```bash
4445
# with docker v19.03+
4546
docker run --gpus all --rm -ti --ipc=host projectmonai/monai:latest

docs/source/losses.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,13 @@ Registration Losses
6565
~~~~~~~~~~~~~~~~~~~
6666
.. autoclass:: BendingEnergyLoss
6767
:members:
68+
69+
`LocalNormalizedCrossCorrelationLoss`
70+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71+
.. autoclass:: LocalNormalizedCrossCorrelationLoss
72+
:members:
73+
74+
`GlobalMutualInformationLoss`
75+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
.. autoclass:: GlobalMutualInformationLoss
77+
:members:

monai/apps/datasets.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,9 @@ def get_properties(self, keys: Optional[Union[Sequence[str], str]] = None):
291291
"""
292292
if keys is None:
293293
return self._properties
294-
elif self._properties is not None:
294+
if self._properties is not None:
295295
return {key: self._properties[key] for key in ensure_tuple(keys)}
296-
else:
297-
return {}
296+
return {}
298297

299298
def _generate_data_list(self, dataset_dir: str) -> List[Dict]:
300299
section = "training" if self.section in ["training", "validation"] else "test"

monai/apps/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def download_url(url: str, filepath: str, hash_val: Optional[str] = None, hash_t
146146
if has_tqdm:
147147
pbar.close()
148148
except IOError as e:
149-
logging.debug("IO Error - %s" % e)
149+
logging.debug("IO Error - %s", e)
150150
finally:
151151
if file_size == os.path.getsize(tmp_file_path):
152152
if hash_val and not check_hash(tmp_file_path, hash_val, hash_type):

monai/config/deviceconfig.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,31 @@ def get_system_info() -> OrderedDict:
123123
"""
124124
output: OrderedDict = OrderedDict()
125125

126-
_dict_append(output, "System", lambda: platform.system())
126+
_dict_append(output, "System", platform.system)
127127
if output["System"] == "Windows":
128-
_dict_append(output, "Win32 version", lambda: platform.win32_ver())
128+
_dict_append(output, "Win32 version", platform.win32_ver)
129129
if hasattr(platform, "win32_edition"):
130-
_dict_append(output, "Win32 edition", lambda: platform.win32_edition()) # type:ignore[attr-defined]
130+
_dict_append(output, "Win32 edition", platform.win32_edition) # type:ignore[attr-defined]
131131
elif output["System"] == "Darwin":
132132
_dict_append(output, "Mac version", lambda: platform.mac_ver()[0])
133133
else:
134134
linux_ver = re.search(r'PRETTY_NAME="(.*)"', open("/etc/os-release", "r").read())
135135
if linux_ver:
136136
_dict_append(output, "Linux version", lambda: linux_ver.group(1))
137137

138-
_dict_append(output, "Platform", lambda: platform.platform())
139-
_dict_append(output, "Processor", lambda: platform.processor())
140-
_dict_append(output, "Machine", lambda: platform.machine())
141-
_dict_append(output, "Python version", lambda: platform.python_version())
138+
_dict_append(output, "Platform", platform.platform)
139+
_dict_append(output, "Processor", platform.processor)
140+
_dict_append(output, "Machine", platform.machine)
141+
_dict_append(output, "Python version", platform.python_version)
142142

143143
if not has_psutil:
144144
_dict_append(output, "`psutil` missing", lambda: "run `pip install monai[psutil]`")
145145
else:
146146
p = psutil.Process()
147147
with p.oneshot():
148-
_dict_append(output, "Process name", lambda: p.name())
149-
_dict_append(output, "Command", lambda: p.cmdline())
150-
_dict_append(output, "Open files", lambda: p.open_files())
148+
_dict_append(output, "Process name", p.name)
149+
_dict_append(output, "Command", p.cmdline)
150+
_dict_append(output, "Open files", p.open_files)
151151
_dict_append(output, "Num physical CPUs", lambda: psutil.cpu_count(logical=False))
152152
_dict_append(output, "Num logical CPUs", lambda: psutil.cpu_count(logical=True))
153153
_dict_append(output, "Num usable CPUs", lambda: len(psutil.Process().cpu_affinity()))
@@ -204,8 +204,9 @@ def get_gpu_info() -> OrderedDict:
204204
_dict_append(output, "cuDNN version", lambda: cudnn_ver)
205205

206206
if num_gpus > 0:
207-
_dict_append(output, "Current device", lambda: torch.cuda.current_device())
208-
_dict_append(output, "Library compiled for CUDA architectures", lambda: torch.cuda.get_arch_list())
207+
_dict_append(output, "Current device", torch.cuda.current_device)
208+
if hasattr(torch.cuda, "get_arch_list"): # get_arch_list is new in torch 1.7.1
209+
_dict_append(output, "Library compiled for CUDA architectures", torch.cuda.get_arch_list)
209210
for gpu in range(num_gpus):
210211
_dict_append(output, "Info for GPU", gpu)
211212
gpu_info = torch.cuda.get_device_properties(gpu)

monai/csrc/resample/pushpull_cpu.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,25 @@ MONAI_NAMESPACE_DEVICE { // cpu
9797
bool do_sgrad)
9898
: dim(dim),
9999
bound0(bound.size() > 0 ? bound[0] : BoundType::Replicate),
100-
bound1(bound.size() > 1 ? bound[1] : bound.size() > 0 ? bound[0] : BoundType::Replicate),
100+
bound1(
101+
bound.size() > 1 ? bound[1]
102+
: bound.size() > 0 ? bound[0]
103+
: BoundType::Replicate),
101104
bound2(
102-
bound.size() > 2 ? bound[2]
103-
: bound.size() > 1 ? bound[1] : bound.size() > 0 ? bound[0] : BoundType::Replicate),
105+
bound.size() > 2 ? bound[2]
106+
: bound.size() > 1 ? bound[1]
107+
: bound.size() > 0 ? bound[0]
108+
: BoundType::Replicate),
104109
interpolation0(interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
105110
interpolation1(
106-
interpolation.size() > 1 ? interpolation[1]
107-
: interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
111+
interpolation.size() > 1 ? interpolation[1]
112+
: interpolation.size() > 0 ? interpolation[0]
113+
: InterpolationType::Linear),
108114
interpolation2(
109-
interpolation.size() > 2
110-
? interpolation[2]
115+
interpolation.size() > 2 ? interpolation[2]
111116
: interpolation.size() > 1 ? interpolation[1]
112-
: interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
117+
: interpolation.size() > 0 ? interpolation[0]
118+
: InterpolationType::Linear),
113119
extrapolate(extrapolate),
114120
do_pull(do_pull),
115121
do_push(do_push),
@@ -136,13 +142,14 @@ MONAI_NAMESPACE_DEVICE { // cpu
136142
bound2(bound),
137143
interpolation0(interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
138144
interpolation1(
139-
interpolation.size() > 1 ? interpolation[1]
140-
: interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
145+
interpolation.size() > 1 ? interpolation[1]
146+
: interpolation.size() > 0 ? interpolation[0]
147+
: InterpolationType::Linear),
141148
interpolation2(
142-
interpolation.size() > 2
143-
? interpolation[2]
149+
interpolation.size() > 2 ? interpolation[2]
144150
: interpolation.size() > 1 ? interpolation[1]
145-
: interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
151+
: interpolation.size() > 0 ? interpolation[0]
152+
: InterpolationType::Linear),
146153
extrapolate(extrapolate),
147154
do_pull(do_pull),
148155
do_push(do_push),
@@ -165,10 +172,15 @@ MONAI_NAMESPACE_DEVICE { // cpu
165172
bool do_sgrad)
166173
: dim(dim),
167174
bound0(bound.size() > 0 ? bound[0] : BoundType::Replicate),
168-
bound1(bound.size() > 1 ? bound[1] : bound.size() > 0 ? bound[0] : BoundType::Replicate),
175+
bound1(
176+
bound.size() > 1 ? bound[1]
177+
: bound.size() > 0 ? bound[0]
178+
: BoundType::Replicate),
169179
bound2(
170-
bound.size() > 2 ? bound[2]
171-
: bound.size() > 1 ? bound[1] : bound.size() > 0 ? bound[0] : BoundType::Replicate),
180+
bound.size() > 2 ? bound[2]
181+
: bound.size() > 1 ? bound[1]
182+
: bound.size() > 0 ? bound[0]
183+
: BoundType::Replicate),
172184
interpolation0(interpolation),
173185
interpolation1(interpolation),
174186
interpolation2(interpolation),

monai/csrc/resample/pushpull_cuda.cu

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,25 @@ MONAI_NAMESPACE_DEVICE { // cuda
9494
bool do_sgrad)
9595
: dim(dim),
9696
bound0(bound.size() > 0 ? bound[0] : BoundType::Replicate),
97-
bound1(bound.size() > 1 ? bound[1] : bound.size() > 0 ? bound[0] : BoundType::Replicate),
97+
bound1(
98+
bound.size() > 1 ? bound[1]
99+
: bound.size() > 0 ? bound[0]
100+
: BoundType::Replicate),
98101
bound2(
99-
bound.size() > 2 ? bound[2]
100-
: bound.size() > 1 ? bound[1] : bound.size() > 0 ? bound[0] : BoundType::Replicate),
102+
bound.size() > 2 ? bound[2]
103+
: bound.size() > 1 ? bound[1]
104+
: bound.size() > 0 ? bound[0]
105+
: BoundType::Replicate),
101106
interpolation0(interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
102107
interpolation1(
103-
interpolation.size() > 1 ? interpolation[1]
104-
: interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
108+
interpolation.size() > 1 ? interpolation[1]
109+
: interpolation.size() > 0 ? interpolation[0]
110+
: InterpolationType::Linear),
105111
interpolation2(
106-
interpolation.size() > 2
107-
? interpolation[2]
112+
interpolation.size() > 2 ? interpolation[2]
108113
: interpolation.size() > 1 ? interpolation[1]
109-
: interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
114+
: interpolation.size() > 0 ? interpolation[0]
115+
: InterpolationType::Linear),
110116
extrapolate(extrapolate),
111117
do_pull(do_pull),
112118
do_push(do_push),
@@ -133,13 +139,14 @@ MONAI_NAMESPACE_DEVICE { // cuda
133139
bound2(bound),
134140
interpolation0(interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
135141
interpolation1(
136-
interpolation.size() > 1 ? interpolation[1]
137-
: interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
142+
interpolation.size() > 1 ? interpolation[1]
143+
: interpolation.size() > 0 ? interpolation[0]
144+
: InterpolationType::Linear),
138145
interpolation2(
139-
interpolation.size() > 2
140-
? interpolation[2]
146+
interpolation.size() > 2 ? interpolation[2]
141147
: interpolation.size() > 1 ? interpolation[1]
142-
: interpolation.size() > 0 ? interpolation[0] : InterpolationType::Linear),
148+
: interpolation.size() > 0 ? interpolation[0]
149+
: InterpolationType::Linear),
143150
extrapolate(extrapolate),
144151
do_pull(do_pull),
145152
do_push(do_push),
@@ -162,10 +169,15 @@ MONAI_NAMESPACE_DEVICE { // cuda
162169
bool do_sgrad)
163170
: dim(dim),
164171
bound0(bound.size() > 0 ? bound[0] : BoundType::Replicate),
165-
bound1(bound.size() > 1 ? bound[1] : bound.size() > 0 ? bound[0] : BoundType::Replicate),
172+
bound1(
173+
bound.size() > 1 ? bound[1]
174+
: bound.size() > 0 ? bound[0]
175+
: BoundType::Replicate),
166176
bound2(
167-
bound.size() > 2 ? bound[2]
168-
: bound.size() > 1 ? bound[1] : bound.size() > 0 ? bound[0] : BoundType::Replicate),
177+
bound.size() > 2 ? bound[2]
178+
: bound.size() > 1 ? bound[1]
179+
: bound.size() > 0 ? bound[0]
180+
: BoundType::Replicate),
169181
interpolation0(interpolation),
170182
interpolation1(interpolation),
171183
interpolation2(interpolation),

monai/data/dataset.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,7 @@ def _try_shutdown(self):
699699
self._round = 0
700700
self._replace_done = False
701701
return True
702-
else:
703-
return False
702+
return False
704703

705704
def shutdown(self):
706705
"""
@@ -807,7 +806,7 @@ def __getitem__(self, index: int):
807806
def to_list(x):
808807
return list(x) if isinstance(x, (tuple, list)) else [x]
809808

810-
data = list()
809+
data = []
811810
for dataset in self.data:
812811
data.extend(to_list(dataset[index]))
813812
if self.transform is not None:

monai/data/decathlon_datalist.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ def _compute_path(base_dir, element):
3939
"""
4040
if isinstance(element, str):
4141
return os.path.normpath(os.path.join(base_dir, element))
42-
elif isinstance(element, list):
42+
if isinstance(element, list):
4343
for e in element:
4444
if not isinstance(e, str):
4545
raise TypeError(f"Every file path in element must be a str but got {type(element).__name__}.")
4646
return [os.path.normpath(os.path.join(base_dir, e)) for e in element]
47-
else:
48-
raise TypeError(f"element must be one of (str, list) but is {type(element).__name__}.")
47+
raise TypeError(f"element must be one of (str, list) but is {type(element).__name__}.")
4948

5049

5150
def _append_paths(base_dir: str, is_segmentation: bool, items: List[Dict]) -> List[Dict]:
@@ -136,7 +135,7 @@ def load_decathlon_properties(
136135
with open(data_property_file_path) as json_file:
137136
json_data = json.load(json_file)
138137

139-
properties = dict()
138+
properties = {}
140139
for key in ensure_tuple(property_keys):
141140
if key not in json_data:
142141
raise KeyError(f"key {key} is not in the data property file.")

0 commit comments

Comments
 (0)