def CNN_decoder(z, tsamples, nsamples, reuse=False): with tf.variable_scope("CNN_decoder", reuse=reuse): x = tflearn.fully_connected(z, 38 * 32, activation='tanh') x = tf.reshape(x, shape=[-1, 1, 38, 32]) decoder = tflearn.conv_2d(x, 32, [3, 3], activation='tanh') print(decoder.get_shape()) #decoder = tflearn.batch_normalization(decoder) decoder = tflearn.upsample_2d(decoder, [2, 2]) print(decoder.get_shape()) decoder = tflearn.conv_2d(decoder, 64, [3, 3], activation='tanh') print(decoder.get_shape()) #decoder = tflearn.batch_normalization(decoder) #decoder= tflearn.upsample_2d(decoder, [3,2]) decoder = tflearn.upsample_2d(decoder, [3, 2]) print(decoder.get_shape()) decoder = tflearn.conv_2d(decoder, 64, [3, 3], activation='tanh') print(decoder.get_shape()) #decoder = tflearn.batch_normalization(decoder) decoder = tflearn.upsample_2d(decoder, [1, 2]) print(decoder.get_shape()) y = tflearn.conv_2d(decoder, 1, [3, 3], activation='tanh', name="sigout") print(y.get_shape()) #y = tflearn.conv_2d(x, 1, [2,2], activation='relu', name="sigout0") y = tflearn.fully_connected(y, tsamples * nsamples, activation="linear", name="sigout") #y = tf.reshape(y,[-1,tsamples,nsamples]) #x = tf.sigmoid(y) x = y x = tflearn.reshape(x, [-1, tsamples, nsamples], name="reshaped") return x, y
def generator(x, reuse=False): with tf.variable_scope('Generator', reuse=reuse): x = tflearn.fully_connected(x, n_units=7 * 7 * 128) x = tflearn.batch_normalization(x) x = tf.nn.tanh(x) x = tf.reshape(x, shape=[-1, 7, 7, 128]) x = tflearn.upsample_2d(x, 2) x = tflearn.conv_2d(x, 64, 5, activation='tanh') x = tflearn.upsample_2d(x, 2) x = tflearn.conv_2d(x, 1, 5, activation='sigmoid') return x
def net(input_image): ratios = [32, 16, 8, 4, 2, 1] conv_num = 8 network = [] for i in range(len(ratios)): network.append(avg_pool_2d(input_image, ratios[i])) # block_i_0, block_i_1, block_i_2 for block in range(3): with tf.name_scope('block_%d_%d' % (i, block)): filter_size = 1 if (block + 1) % 3 == 0 else 3 network[i] = tflearn.conv_2d(network[i], nb_filter=conv_num, filter_size=filter_size, weights_init='xavier', name='Conv_%d_%d' % (i, block)) network[i] = tf.nn.batch_normalization(network[i], 0, 1.0, 0.0, 1.0, 1e-5, 'BatchNorm') network[i] = tflearn.activations.leaky_relu(network[i]) if i == 0: network[i] = tflearn.upsample_2d(network[i], 2) else: upnet = tf.nn.batch_normalization(network[i - 1], 0, 1.0, 0.0, 1.0, 1e-5, 'BatchNorm') downnet = tf.nn.batch_normalization(network[i], 0, 1.0, 0.0, 1.0, 1e-5, 'BatchNorm') # join_i network[i] = tflearn.merge([upnet, downnet], 'concat', axis=3) # block_i_3, block_i_4, block_i_5 for block in range(3, 6): with tf.name_scope('block_%d_%d' % (i, block)): filter_size = 1 if (block + 1) % 3 == 0 else 3 network[i] = tflearn.conv_2d(network[i], nb_filter=conv_num * i, filter_size=filter_size, weights_init='xavier', name='Conv_%d_%d' % (i, block)) network[i] = tf.nn.batch_normalization( network[i], 0, 1.0, 0.0, 1.0, 1e-5, 'BatchNorm') network[i] = tflearn.activations.leaky_relu(network[i]) if i != len(ratios) - 1: network[i] = tflearn.upsample_2d(network[i], 2) network[len(ratios) - 1] = tflearn.conv_2d(network[len(ratios) - 1], nb_filter=3, filter_size=1, weights_init='xavier', name='Conv2d_out') return network[len(ratios) - 1]
def generator(input_image): ratios = [16, 8, 4, 2, 1] n_filter = 8 net = [] for i in range(len(ratios)): net.append(tflearn.max_pool_2d(input_image, ratios[i], ratios[i])) # block_i_0, block_i_1, block_i_2 for block in range(3): ksize = 1 if (block + 1) % 3 == 0 else 3 net[i] = relu(batch_norm(conv2d(net[i], n_filter, ksize))) if i != 0: # concat with net[i-1] upnet = batch_norm(net[i - 1]) downnet = batch_norm(net[i]) net[i] = tf.concat(3, [upnet, downnet]) # block_i_3, block_i_4, block_i_5 for block in range(3, 6): ksize = 1 if (block + 1) % 3 == 0 else 3 net[i] = conv2d(net[i], n_filter * (i + 1), ksize) net[i] = relu(batch_norm(net[i])) if i != len(ratios) - 1: net[i] = tflearn.upsample_2d(net[i], 2) return conv2d(net[len(ratios) - 1], 3, 1)
def basic_netunit_tf(inputs, No, channel, kernel, wd, drop, down=True): network = tflearn.conv_2d(inputs, channel, [3, 3], activation='relu', regularizer='L2', weight_decay=wd, scope="Conv" + No + '_1') network = tflearn.conv_2d(inputs, channel, [3, 3], activation='relu', regularizer='L2', weight_decay=wd, scope="Conv" + No + '_2') #conv = network conv = tflearn.batch_normalization(network) #conv = tf.contrib.layers.batch_norm(network, is_training=training_phase, # decay=0.99, center=True, scale=True, # scope='BN'+No, reuse=reuse) if down: pool = tflearn.max_pool_2d(conv, 2) # pool=BatchNormalization(name='BN'+No)(pool) else: pool = tflearn.upsample_2d(conv, 2) # pool= BatchNormalization(name='BN'+No)(pool) return [conv, pool]
def generator(x, reuse=False): with tf.variable_scope('Generator', reuse=reuse): x = tflearn.fully_connected(x, n_units=7 * 7 * 128) x = tf.reshape(x, shape=[-1, 7, 7, 128]) x = tflearn.upsample_2d(x, 4) #x = tflearn.upsample_2d(x, 2) x = tf.cast(x, tf.float32) x = tflearn.conv_2d(x, 3, 1, activation='sigmoid') return x
def create_network(x,y): print('input: ',x.get_shape()) x = tf.reshape(x, [tf.shape(x)[0], height, width, 1], name='reshape_image1') print(x) x = tf.to_float(x)/max_dist print(x) print('x: ',x.get_shape()) conv1 = tflearn.conv_2d(x,n_features,patch_size,strides, padding = 'same', activation = 'leaky_relu', name='conv1') print('conv1: ', conv1.get_shape()) maxPool1 = tflearn.layers.conv.max_pool_2d (conv1, 2, padding='same') print('mPool1:', maxPool1.get_shape()) conv2 = tflearn.conv_2d(maxPool1,n_features,patch_size,strides, padding = 'same', activation = 'leaky_relu', name='conv2') print('conv2: ', conv2.get_shape()) maxPool2 = tflearn.layers.conv.max_pool_2d (conv2, 2, padding='same') print('mPool2:', maxPool2.get_shape()) conv3 = tflearn.conv_2d(maxPool2,n_features,patch_size,strides, padding = 'same', activation = 'leaky_relu', name='conv3') print('conv3: ', conv3.get_shape()) maxPool3 = tflearn.layers.conv.max_pool_2d (conv3, 2, padding='same') print('mPool3:', maxPool3.get_shape()) conv4 = tflearn.conv_2d(maxPool3,n_features,patch_size,strides, padding = 'same', activation = 'leaky_relu') # print('conv4: ', conv4.get_shape()) # maxPool4 = tflearn.layers.conv.max_pool_2d (conv4, 2, padding='same') # print('mpool4:', conv4.get_shape()) # # # fc1 = tflearn.fully_connected(conv3, 225*4*n_features, activation = 'leaky_relu') fc1 = tflearn.fully_connected(conv4, 5000, activation = 'leaky_relu') tfc1 = tflearn.fully_connected(fc1, 225*4*n_features, activation = 'leaky_relu') print('fc1: ', fc1.get_shape()) tfc1 = tf.reshape(tfc1, [-1, 225, 4, n_features]) print('tfc1: ', tfc1.get_shape()) # last = fully_connected(tfc2, tf.transpose(weights['wfc1']), biases['b3_dec']) # # tfc2 = tf.reshape(tfc2, [-1, 1160*2, 1, n_features]) # last = tf.reshape(last, [-1, 1160, 1, n_features]) # print('tfc3: ', last.get_shape()) # upsample1 = tflearn.upsample_2d(maxPool4,2) # print('usamp1:', upsample1.get_shape()) # tconv1 = tflearn.conv_2d_transpose(fc1,n_features*4,patch_size,maxPool3.get_shape().as_list()[1:4], padding = 'same', activation = 'leaky_relu') # print('tconv1:', tconv1.get_shape()) # upsample2 = tflearn.upsample_2d(tconv1,2) # print('usamp2:', upsample2.get_shape()) tconv2 = tflearn.conv_2d_transpose(tfc1,n_features,patch_size,maxPool2.get_shape().as_list()[1:4], padding = 'same', activation = 'leaky_relu', name='deconv2') print('tconv2:', tconv2.get_shape()) upsample3 = tflearn.upsample_2d(tconv2,2) print('usamp3:', upsample3.get_shape()) tconv3 = tflearn.conv_2d_transpose(upsample3,n_features,patch_size,maxPool1.get_shape().as_list()[1:4], padding = 'same', activation = 'leaky_relu', name='deconv3') print('tconv3:', tconv3.get_shape()) upsample4 = tflearn.upsample_2d(tconv3,2) print('usamp4:', upsample4.get_shape()) tconv4 = tflearn.conv_2d_transpose(upsample4,2,patch_size,y.get_shape().as_list()[1:4], padding = 'same', activation = 'leaky_relu', name='deconv4') print('tconv4:', tconv4.get_shape()) output = tf.nn.softmax(tf.reshape(tconv4,[-1,height,width,2]), name="softmax_tensor") print('output:', output.get_shape()) return output