Advertisement
Guest User

Untitled

a guest
Mar 4th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. # In[118]:
  2.  
  3.  
  4. def inception(i, num_layers, w, stride):
  5.     c = tf.layers.conv2d(
  6.         inputs=i,
  7.         filters=num_layers,
  8.         kernel_size=(w, 1),
  9.         padding='same',
  10.         use_bias=False
  11.     )
  12.     c = tf.layers.conv2d(
  13.         inputs=c,
  14.         filters=num_layers,
  15.         kernel_size=(1, w),
  16.         padding='same',
  17.         use_bias=False
  18.     )
  19.     bias = tf.Variable(tf.zeros([num_layers]))
  20.     c = tf.nn.bias_add(c, bias)
  21.     c = tf.nn.relu(c)
  22.     return c
  23.  
  24.  
  25. # In[140]:
  26.  
  27.  
  28. tf.reset_default_graph()
  29. sess = tf.InteractiveSession()
  30.  
  31. x = tf.placeholder(tf.float32, shape=(None, None, None, 3))
  32. y = tf.placeholder(tf.float32, shape=(None, None, None, 1))
  33.  
  34. c = inception(x, 64, 5)
  35. for _ in range(16):
  36.     c = tf.concat([
  37.         inception(c, 16, 7),
  38.         inception(c, 16, 5),
  39.         inception(c, 32, 3),
  40.     ], 3)
  41. o = tf.layers.conv2d(c, 1, (1, 1), activation=tf.nn.sigmoid)
  42.  
  43. y_flat = tf.layers.flatten(y)
  44. o_flat = tf.layers.flatten(o)
  45. loss_op = tf.reduce_mean(tf.keras.backend.binary_crossentropy(y_flat, o_flat), 1)
  46. train_op = tf.train.AdamOptimizer(1e-4).minimize(loss_op)
  47. iou_op = mean_iou(y_flat, o_flat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement