Skip to content

Commit

Permalink
Merge pull request #23 from Project-MONAI/21-coding-style
Browse files Browse the repository at this point in the history
fixes #21
  • Loading branch information
wyli authored Jan 13, 2020
2 parents c49febd + 05b248c commit eb9189d
Show file tree
Hide file tree
Showing 44 changed files with 502 additions and 585 deletions.
2 changes: 1 addition & 1 deletion examples/cardiac_segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"from monai import application, data, networks, utils\n",
"import monai.data.augments.augments as augments\n",
"\n",
"application.config.printConfig()"
"application.config.print_config()"
]
},
{
Expand Down
12 changes: 5 additions & 7 deletions monai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -10,17 +9,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys

import os, sys
from .utils.moduleutils import loadSubmodules

from .utils.moduleutils import load_submodules, loadSubmodules

__copyright__ = "(c) 2020 MONAI Consortium"
__version__tuple__ = (0, 0, 1)
__version__ = "%i.%i.%i" % (__version__tuple__)

__basedir__ = os.path.dirname(__file__)


loadSubmodules(sys.modules[__name__], False) # load directory modules only, skip loading individual files
loadSubmodules(sys.modules[__name__], True) # load all modules, this will trigger all export decorations
load_submodules(sys.modules[__name__], False) # load directory modules only, skip loading individual files
load_submodules(sys.modules[__name__], True) # load all modules, this will trigger all export decorations
5 changes: 0 additions & 5 deletions monai/application/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -9,7 +8,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




5 changes: 0 additions & 5 deletions monai/application/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -9,7 +8,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




23 changes: 12 additions & 11 deletions monai/application/config/deviceconfig.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -10,24 +9,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.


import os, sys
import os
import sys
from collections import OrderedDict
import monai

import numpy as np
import torch

import monai

try:
import ignite
ignite_version=ignite.__version__
ignite_version = ignite.__version__
except ImportError:
ignite_version='NOT INSTALLED'
ignite_version = 'NOT INSTALLED'

export = monai.utils.export("monai.application.config")


@export
def getConfigValues():
def get_config_values():
output = OrderedDict()

output["MONAI version"] = monai.__version__
Expand All @@ -40,11 +41,11 @@ def getConfigValues():


@export
def printConfig(file=sys.stdout):
for kv in getConfigValues().items():
def print_config(file=sys.stdout):
for kv in get_config_values().items():
print("%s: %s" % kv, file=file, flush=True)


@export
def setVisibleDevices(*devInds):
os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(map(str, devInds))
def set_visible_devices(*dev_inds):
os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(map(str, dev_inds))
5 changes: 0 additions & 5 deletions monai/application/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -9,7 +8,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




3 changes: 0 additions & 3 deletions monai/application/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -9,5 +8,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


40 changes: 19 additions & 21 deletions monai/application/handlers/metric_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -10,7 +9,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


from collections import defaultdict

import monai
Expand All @@ -19,24 +17,24 @@
@monai.utils.export("monai.application.handlers")
@monai.utils.alias("metriclogger")
class MetricLogger:
def __init__(self,loss_transform=lambda x:x, metric_transform=lambda x:x):
self.loss_transform=loss_transform
self.metric_transform=metric_transform
self.loss=[]
self.metrics=defaultdict(list)

def attach(self,engine):
return engine.add_event_handler(monai.application.engine.Events.ITERATION_COMPLETED,self)

def __call__(self,engine):

def __init__(self, loss_transform=lambda x: x, metric_transform=lambda x: x):
self.loss_transform = loss_transform
self.metric_transform = metric_transform
self.loss = []
self.metrics = defaultdict(list)

def attach(self, engine):
return engine.add_event_handler(monai.application.engine.Events.ITERATION_COMPLETED, self)

def __call__(self, engine):
self.loss.append(self.loss_transform(engine.state.output))
for m,v in engine.state.metrics.items():
v=self.metric_transform(v)
# # metrics may not be added on the first timestep, pad the list if this is the case
# # so that each metric list is the same length as self.loss
# if len(self.metrics[m])==0:
# self.metrics[m].append([v[0]]*len(self.loss))

for m, v in engine.state.metrics.items():
v = self.metric_transform(v)
# # metrics may not be added on the first timestep, pad the list if this is the case
# # so that each metric list is the same length as self.loss
# if len(self.metrics[m])==0:
# self.metrics[m].append([v[0]]*len(self.loss))

self.metrics[m].append(v)

3 changes: 0 additions & 3 deletions monai/application/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -9,5 +8,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


5 changes: 0 additions & 5 deletions monai/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -9,7 +8,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




5 changes: 0 additions & 5 deletions monai/data/augments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -9,7 +8,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




Loading

0 comments on commit eb9189d

Please sign in to comment.