Created
October 26, 2017 17:03
-
-
Save twmht/209d5a2433a0065edd8254d6e2182b3b to your computer and use it in GitHub Desktop.
deconv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import tensorflow as tf | |
| # # part1 | |
| # #case 2 | |
| # input = tf.Variable(tf.random_normal([3,97,97,10])) | |
| # filter = tf.Variable(tf.random_normal([3,3,10,20])) | |
| # x = tf.nn.conv2d(input, filter, strides=[1, 4, 4, 1], padding='SAME') | |
| # # y = tf.nn.conv2d_transpose(x, filter, output_shape=[1,5,5,3], strides=[1,2,2,1],padding="SAME") | |
| # with tf.Session() as sess: | |
| # sess.run(tf.initialize_all_variables()) | |
| # res = (sess.run(x)) | |
| # print (res.shape) | |
| # part2 | |
| import tensorflow as tf | |
| from tensorflow.contrib import slim | |
| import numpy as np | |
| inputs = tf.placeholder(tf.float32, shape=[None, None, None, 3]) | |
| conv1 = slim.conv2d(inputs, num_outputs=20, kernel_size=3, stride=4) | |
| de_weight = tf.get_variable('de_weight', shape=[3, 3, 3, 20]) | |
| deconv1 = tf.nn.conv2d_transpose(conv1, filter=de_weight, output_shape=tf.shape(inputs), | |
| strides=[1, 4, 4, 1], padding='SAME') | |
| loss = deconv1 - inputs | |
| train_op = tf.train.GradientDescentOptimizer(0.001).minimize(loss) | |
| with tf.Session() as sess: | |
| tf.global_variables_initializer().run() | |
| for i in range(10): | |
| data_in = np.random.normal(size=[3, 97, 97, 3]) | |
| aa, los_ = sess.run([train_op, loss], feed_dict={inputs: data_in}) | |
| print(aa.shape) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment