Skip to content

Commit

Permalink
Merge pull request #30 from jakeret/tf100
Browse files Browse the repository at this point in the history
Tf100
  • Loading branch information
jakeret authored Mar 27, 2017
2 parents a48861d + ecf67c9 commit 18eb8b5
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 164 deletions.
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Credits
Development Lead
----------------

* Joel Akeret <[email protected]>
* Joel Akeret <[email protected]>

Contributors
------------

* `@FelixGruen <https://github.com/FelixGruen>`_
* `@ameya005 <https://github.com/ameya005>`_

Citations
---------
Expand Down
111 changes: 66 additions & 45 deletions demo/demo_radio_data.ipynb

Large diffs are not rendered by default.

178 changes: 71 additions & 107 deletions demo/demo_toy_problem.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
click
numpy
Pillow
Pillow
tensorflow>=1.0.0
6 changes: 3 additions & 3 deletions tf_unet/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def conv2d(x, W,keep_prob_):

def deconv2d(x, W,stride):
x_shape = tf.shape(x)
output_shape = tf.pack([x_shape[0], x_shape[1]*2, x_shape[2]*2, x_shape[3]//2])
output_shape = tf.stack([x_shape[0], x_shape[1]*2, x_shape[2]*2, x_shape[3]//2])
return tf.nn.conv2d_transpose(x, W, output_shape, strides=[1, stride, stride, 1], padding='VALID')

def max_pool(x,n):
Expand All @@ -51,7 +51,7 @@ def crop_and_concat(x1,x2):
offsets = [0, (x1_shape[1] - x2_shape[1]) // 2, (x1_shape[2] - x2_shape[2]) // 2, 0]
size = [-1, x2_shape[1], x2_shape[2], -1]
x1_crop = tf.slice(x1, offsets, size)
return tf.concat(3, [x1_crop, x2])
return tf.concat([x1_crop, x2], 3)

def pixel_wise_softmax(output_map):
exponential_map = tf.exp(output_map)
Expand All @@ -61,7 +61,7 @@ def pixel_wise_softmax(output_map):
def pixel_wise_softmax_2(output_map):
exponential_map = tf.exp(output_map)
sum_exp = tf.reduce_sum(exponential_map, 3, keep_dims=True)
tensor_sum_exp = tf.tile(sum_exp, tf.pack([1, 1, 1, tf.shape(output_map)[3]]))
tensor_sum_exp = tf.tile(sum_exp, tf.stack([1, 1, 1, tf.shape(output_map)[3]]))
return tf.div(exponential_map,tensor_sum_exp)


Expand Down
14 changes: 7 additions & 7 deletions tf_unet/unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_conv_net(x, keep_prob, channels, n_class, layers=3, features_root=16,
# Placeholder for the input image
nx = tf.shape(x)[1]
ny = tf.shape(x)[2]
x_image = tf.reshape(x, tf.pack([-1,nx,ny,channels]))
x_image = tf.reshape(x, tf.stack([-1,nx,ny,channels]))
in_node = x_image
batch_size = tf.shape(x_image)[0]

Expand Down Expand Up @@ -215,17 +215,17 @@ def _get_cost(self, logits, cost_name, cost_kwargs):
if class_weights is not None:
class_weights = tf.constant(np.array(class_weights, dtype=np.float32))

weight_map = tf.mul(flat_labels, class_weights)
weight_map = tf.multiply(flat_labels, class_weights)
weight_map = tf.reduce_sum(weight_map, axis=1)

loss_map = tf.nn.softmax_cross_entropy_with_logits(flat_logits, flat_labels)
weighted_loss = tf.mul(loss_map, weight_map)
weighted_loss = tf.multiply(loss_map, weight_map)

loss = tf.reduce_mean(weighted_loss)

else:
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(flat_logits,
flat_labels))
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=flat_logits,
labels=flat_labels))
elif cost_name == "dice_coefficient":
eps = 1e-5
prediction = pixel_wise_softmax_2(logits)
Expand Down Expand Up @@ -498,7 +498,7 @@ def get_image_summary(img, idx=0):

img_w = tf.shape(img)[1]
img_h = tf.shape(img)[2]
V = tf.reshape(V, tf.pack((img_w, img_h, 1)))
V = tf.reshape(V, tf.stack((img_w, img_h, 1)))
V = tf.transpose(V, (2, 0, 1))
V = tf.reshape(V, tf.pack((-1, img_w, img_h, 1)))
V = tf.reshape(V, tf.stack((-1, img_w, img_h, 1)))
return V

0 comments on commit 18eb8b5

Please sign in to comment.