Skip to content

Commit

Permalink
fix: pep8 and flake check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Rajchl committed Jun 13, 2018
1 parent 1091697 commit e28cf05
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 43 deletions.
6 changes: 3 additions & 3 deletions data/IXI_Guys/download_IXI_Guys.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def resample_image(itk_image, out_spacing=[1.0, 1.0, 1.0], is_label=False):
original_size = itk_image.GetSize()

out_size = [
int(np.round(original_size[0] * (original_spacing[0]/out_spacing[0]))),
int(np.round(original_size[1] * (original_spacing[1]/out_spacing[1]))),
int(np.round(original_size[2] * (original_spacing[2]/out_spacing[2])))
int(np.round(original_size[0] * (original_spacing[0] / out_spacing[0]))),
int(np.round(original_size[1] * (original_spacing[1] / out_spacing[1]))),
int(np.round(original_size[2] * (original_spacing[2] / out_spacing[2])))
]

resample = sitk.ResampleImageFilter()
Expand Down
6 changes: 3 additions & 3 deletions data/IXI_HH/download_IXI_HH.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def resample_image(itk_image, out_spacing=(1.0, 1.0, 1.0), is_label=False):
original_spacing = itk_image.GetSpacing()
original_size = itk_image.GetSize()

out_size = [int(np.round(original_size[0]*(original_spacing[0]/out_spacing[0]))),
int(np.round(original_size[1]*(original_spacing[1]/out_spacing[1]))),
int(np.round(original_size[2]*(original_spacing[2]/out_spacing[2])))]
out_size = [int(np.round(original_size[0] * (original_spacing[0] / out_spacing[0]))),
int(np.round(original_size[1] * (original_spacing[1] / out_spacing[1]))),
int(np.round(original_size[2] * (original_spacing[2] / out_spacing[2])))]

resample = sitk.ResampleImageFilter()
resample.SetOutputSpacing(out_spacing)
Expand Down
6 changes: 2 additions & 4 deletions dltk/core/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ def sparse_balanced_crossentropy(logits, labels):
labels, minlength=num_classes, dtype=tf.float32))

weights = (1. / (class_frequencies + tf.constant(1e-8)))
weights *= (tf.cast(tf.reduce_prod(tf.shape(labels)), tf.float32)
/ tf.cast(num_classes, tf.float32))
weights *= (tf.cast(tf.reduce_prod(tf.shape(labels)), tf.float32) / tf.cast(num_classes, tf.float32))

new_shape = (([1, ] * len(labels.get_shape().as_list()))
+ [logits.get_shape().as_list()[-1]])
new_shape = (([1, ] * len(labels.get_shape().as_list())) + [logits.get_shape().as_list()[-1]])

weights = tf.reshape(weights, new_shape)

Expand Down
23 changes: 8 additions & 15 deletions dltk/io/abstract_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,17 @@ def clean_ex(ex, compare):
for k in list(ex.keys()):
if k not in list(compare.keys()):
del ex[k]
elif isinstance(ex[k], dict) \
and isinstance(compare[k], dict):
elif isinstance(ex[k], dict) and isinstance(compare[k], dict):
clean_ex(ex[k], compare[k])
elif (isinstance(ex[k], dict)
and not isinstance(compare[k], dict)) \
or (not isinstance(ex[k], dict)
and isinstance(compare[k], dict)):
elif (isinstance(ex[k], dict) and not isinstance(compare[k], dict)) or \
(not isinstance(ex[k], dict) and isinstance(compare[k], dict)):
raise ValueError('Entries between example and '
'dtypes incompatible for key {}'
''.format(k))
elif ((isinstance(ex[k], list)
and not isinstance(compare[k], list))
or (not isinstance(ex[k], list)
and isinstance(compare[k], list))
or (isinstance(ex[k], list)
and isinstance(compare[k], list)
and not len(ex[k]) == len(compare[k]))):
elif ((isinstance(ex[k], list) and not isinstance(compare[k], list)) or
(not isinstance(ex[k], list) and isinstance(compare[k], list)) or
(isinstance(ex[k], list) and isinstance(compare[k], list) and
not len(ex[k]) == len(compare[k]))):
raise ValueError('Entries between example and '
'dtypes incompatible for key {}'
''.format(k))
Expand Down Expand Up @@ -165,8 +159,7 @@ def serving_input_receiver_fn(self, placeholder_shapes):
def f():
inputs = {k: tf.placeholder(
shape=[None] + list(placeholder_shapes['features'][k]),
dtype=self.dtypes['features'][k])
for k in list(self.dtypes['features'].keys())}
dtype=self.dtypes['features'][k]) for k in list(self.dtypes['features'].keys())}

return tf.estimator.export.ServingInputReceiver(inputs, inputs)
return f
16 changes: 8 additions & 8 deletions dltk/io/augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def extract_class_balanced_example_array(image,

for i in range(len(r_idx)):
# Extract class-balanced examples from the original image
slicer = [slice(r_idx[i][dim]
- ex_rad[dim][0], r_idx[i][dim]
+ ex_rad[dim][1]) for dim in range(rank)]
slicer = [slice(r_idx[i][dim] -
ex_rad[dim][0], r_idx[i][dim] +
ex_rad[dim][1]) for dim in range(rank)]

ex_image = image[slicer][np.newaxis, :]

Expand Down Expand Up @@ -252,15 +252,15 @@ def extract_random_example_array(image_list,

assert all([i_s >= e_s for i_s, e_s in zip(image_list[0].shape, example_size)]), \
'Image must be bigger than example shape'
assert (image_list[0].ndim - 1 == len(example_size)
or image_list[0].ndim == len(example_size)), \
assert (image_list[0].ndim - 1 == len(example_size) or
image_list[0].ndim == len(example_size)), \
'Example size doesnt fit image size'

for i in image_list:
if len(image_list) > 1:
assert (i.ndim - 1 == image_list[0].ndim
or i.ndim == image_list[0].ndim
or i.ndim + 1 == image_list[0].ndim), \
assert (i.ndim - 1 == image_list[0].ndim or
i.ndim == image_list[0].ndim or
i.ndim + 1 == image_list[0].ndim), \
'Example size doesnt fit image size'

assert all([i0_s == i_s for i0_s, i_s in zip(image_list[0].shape, i.shape)]), \
Expand Down
3 changes: 1 addition & 2 deletions dltk/networks/gan/dcgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def dcgan_generator_3d(inputs,
tf.logging.info('Generator at res_scale after up {} tensor '
'shape: {}'.format(res_scale, x.get_shape()))

x = tf.layers.batch_normalization(
x, training=mode == tf.estimator.ModeKeys.TRAIN)
x = tf.layers.batch_normalization(x, training=mode == tf.estimator.ModeKeys.TRAIN)

x = leaky_relu(x, 0.2)
tf.logging.info('Generator at res_scale {} tensor shape: '
Expand Down
4 changes: 2 additions & 2 deletions dltk/networks/segmentation/deepmedic.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def _residual_connection(x, prev_x):
# add prev_x to first channels of x

to_pad = [[0, 0]] * (len(x.get_shape().as_list()) - 1)
to_pad += [[0, x.get_shape().as_list()[-1]
- prev_x.get_shape().as_list()[-1]]]
to_pad += [[0, x.get_shape().as_list()[-1] -
prev_x.get_shape().as_list()[-1]]]
prev_x = tf.pad(prev_x, to_pad)

return x + prev_x
Expand Down
6 changes: 2 additions & 4 deletions dltk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ def sliding_window_segmentation_inference(session,

out_dummies = [np.zeros(
[inp_shape[0], ] + inp_bshape + [op.get_shape().as_list()[-1]]
if len(op.get_shape().as_list()) == len(inp_shape) else [])
for op in ops_list]
if len(op.get_shape().as_list()) == len(inp_shape) else []) for op in ops_list]

out_dummy_counter = [np.zeros_like(o) for o in out_dummies]

Expand Down Expand Up @@ -162,8 +161,7 @@ def sliding_window_segmentation_inference(session,
out_slicers.append(out_slicer)
if len(slicers) == batch_size or done:
slices_dict = {k: np.concatenate(
[v[slicer] for slicer in slicers], 0)
for k, v in padded_dict.items()}
[v[slicer] for slicer in slicers], 0) for k, v in padded_dict.items()}

all_op_parts = session.run(ops_list, feed_dict=slices_dict)

Expand Down
3 changes: 1 addition & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

html_context = {'css_files': [
'_static/theme_overrides.css']}
html_context = {'css_files': ['_static/theme_overrides.css']}

# -- Options for HTMLHelp output ------------------------------------------

Expand Down

0 comments on commit e28cf05

Please sign in to comment.