Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Cleanup/remove some unnecessary control-flow statement around uncondi…
Browse files Browse the repository at this point in the history
…tional control-flow.
  • Loading branch information
lamby committed Feb 27, 2018
1 parent 8489058 commit 67b8406
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
3 changes: 1 addition & 2 deletions prediction/src/algorithms/classify/src/gtr123_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ def __init__(self, n_in, n_out, stride=1):
self.conv2 = nn.Conv3d(n_out, n_out, kernel_size=3, padding=1)
self.bn2 = nn.BatchNorm3d(n_out)

self.shortcut = None
if stride != 1 or n_out != n_in:
self.shortcut = nn.Sequential(
nn.Conv3d(n_in, n_out, kernel_size=1, stride=stride),
nn.BatchNorm3d(n_out))
else:
self.shortcut = None

def forward(self, x):
residual = x
Expand Down
4 changes: 2 additions & 2 deletions prediction/src/algorithms/evaluation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def logloss(true_label, predicted, eps=1e-15):

if true_label == 1:
return -np.log(p)
else:
return -np.log(1 - p)

return -np.log(1 - p)
3 changes: 1 addition & 2 deletions prediction/src/algorithms/identify/src/gtr123_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ def __init__(self, n_in, n_out, stride=1):
self.conv2 = nn.Conv3d(n_out, n_out, kernel_size=3, padding=1)
self.bn2 = nn.BatchNorm3d(n_out)

self.shortcut = None
if stride != 1 or n_out != n_in:
self.shortcut = nn.Sequential(
nn.Conv3d(n_in, n_out, kernel_size=1, stride=stride),
nn.BatchNorm3d(n_out))
else:
self.shortcut = None

def forward(self, x):
"""
Expand Down
28 changes: 14 additions & 14 deletions prediction/src/algorithms/segment/src/models/unet_3d_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ def compute_level_output_shape(filters, depth, pool_size, image_shape):

def get_upconv(depth, nb_filters, pool_size, image_shape, kernel_size=(2, 2, 2), strides=(2, 2, 2),
deconvolution=False):
if deconvolution:
try:
from keras_contrib.layers import Deconvolution3D
except ImportError:
raise ImportError("Install keras_contrib in order to use deconvolution. Otherwise set deconvolution=False.")

return Deconvolution3D(filters=nb_filters, kernel_size=kernel_size,
output_shape=compute_level_output_shape(filters=nb_filters, depth=depth,
pool_size=pool_size, image_shape=image_shape),
strides=strides, input_shape=compute_level_output_shape(filters=nb_filters,
depth=depth + 1,
pool_size=pool_size,
image_shape=image_shape))
else:
if not deconvolution:
return UpSampling3D(size=pool_size)

try:
from keras_contrib.layers import Deconvolution3D
except ImportError:
raise ImportError("Install keras_contrib in order to use deconvolution. Otherwise set deconvolution=False.")

return Deconvolution3D(filters=nb_filters, kernel_size=kernel_size,
output_shape=compute_level_output_shape(filters=nb_filters, depth=depth,
pool_size=pool_size, image_shape=image_shape),
strides=strides, input_shape=compute_level_output_shape(filters=nb_filters,
depth=depth + 1,
pool_size=pool_size,
image_shape=image_shape))
4 changes: 2 additions & 2 deletions prediction/src/preprocess/load_ct.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,5 @@ def __init__(self, meta):

elif isinstance(self.meta, MetaData):
self.non_copy_constructor(meta)
else:
raise ValueError('The meta should be either list[dicom.dataset.FileDataset] or SimpleITK.SimpleITK.Image')

raise ValueError('The meta should be either list[dicom.dataset.FileDataset] or SimpleITK.SimpleITK.Image')
4 changes: 2 additions & 2 deletions prediction/src/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def get_timeout():

if run_slow_tests:
return 0
else:
return int(os.environ.get('TESTS_TIMEOUT', DEFAULT_TIMEOUT))

return int(os.environ.get('TESTS_TIMEOUT', DEFAULT_TIMEOUT))
7 changes: 4 additions & 3 deletions prediction/src/tests/test_grt123_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def resample(imgs, spacing, new_spacing, order=2):
imgs = zoom(imgs, resize_factor, mode='nearest', order=order)

return imgs, true_spacing
elif len(imgs.shape) == 4:

if len(imgs.shape) == 4:
n = imgs.shape[-1]
newimg = []

Expand All @@ -106,8 +107,8 @@ def resample(imgs, spacing, new_spacing, order=2):
newimg = np.transpose(np.array(newimg), [1, 2, 3, 0])

return newimg, true_spacing
else:
raise ValueError('wrong shape')

raise ValueError('wrong shape')


def test_lum_trans(metaimage_path):
Expand Down

0 comments on commit 67b8406

Please sign in to comment.