1

I am wondering whether it is possible to end up with the same tensor after propagating it through a convolutional and then deconvolutional filter. For example:

random_image = np.random.rand(1, 6, 6, 3)
input_image = tf.placeholder(shape=[1, 6, 6, 3], dtype=tf.float32)
conv = tf.layers.conv2d(input_image, filters=6, kernel_size=[3, 3], strides=(1, 1), data_format="channels_last")
deconv = tf.layers.conv2d_transpose(conv, filters=3, kernel_size=[3, 3], strides=(1, 1), data_format="channels_last")
sess = tf.Session()
sess.run(tf.global_variables_initializer())
print(random_image)
# Get an output which will be same as:
print(sess.run(deconv, feed_dict={input_image: random_image}))

In other words, if the generated random_image vector is for example: [1,2,3,4,5], after convolution and deconvolution the deconv vector to be [1,2,3,4,5].

However, I am not able to get it to work.

Looking forward to you answers!

gorjan
  • 5,405
  • 2
  • 20
  • 40
  • Define 'same'. Are you after exact same array values or some kind of visual similarity? Maybe you test it on actual image and share results? – Sharky Apr 03 '19 at 12:43
  • What I mean is the random image vector is: `[1,2,3,4,5]`, after convolution and deconvolution the output to be: `[1,2,3,4,5]`. I also updated the question based on your comment. – gorjan Apr 03 '19 at 12:46
  • It's possible to get some degree of visual similarity, but math equality, i guess no. Take a look https://stackoverflow.com/questions/37890989/why-isnt-this-conv2d-transpose-deconv2d-returning-the-original-input-in-tenso – Sharky Apr 03 '19 at 13:20
  • Thanks for the help! That's the clarification that I needed. Feel free to post an answer so I can accept it as correct. – gorjan Apr 03 '19 at 13:26

1 Answers1

1

It's possible to get some degree of visual similarity, by using VarianceScaling initialization for example. Or even with completely custom initializer. But transposed convolution isn't mathematically deconvolution. So you can't get math equality with conv2d_transpose.

Take a look Why isn't this Conv2d_Transpose / deconv2d returning the original input in tensorflow?

Sharky
  • 4,473
  • 2
  • 19
  • 27