0
$\begingroup$

Given a computational graph in tensorflow find errors if any in the underlying code.

import tensorflow as tf
import numpy as np
input = tf.placeholder(shape=(1, 224, 224, 3), dtype=tf.float32)
output = input + 5
with tf.Session() as sess:
  network_input = np.random.randint(5,  size=(700, 350, 3))
  out = sess.run(output, feed_dict = {input : network_input})  

The code is throwing error as the shape of the placeholder and the input given is not matching.
So for fixing it I am changing the shape of the place holder.
Is it the correct approach or the input given should be reshaped to the placeholder shape?

$\endgroup$

1 Answer 1

0
$\begingroup$

According to me, reshaping of the input in perfectly ok. If you are changing the shape of the parameter just to fulfill the requirements of the method parameter or for further processing of the logic, it is perfectly ok, as long as you know what you are sending and how it will be processed by further code.

But in feed_dict, input and placeholder dimensions should be same otherwise you will get the compilation error.

Note: In case you are not sure about the exact dimensions of your placeholder, you can use [None] as a dimension value while declaring a placeholder

$\endgroup$
2
  • $\begingroup$ Got it Thanks for the reply $\endgroup$
    – ten do
    Commented Jul 6, 2019 at 3:51
  • $\begingroup$ Your welcome @ten do. $\endgroup$ Commented Jul 8, 2019 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.