Gerges
Gerges

Reputation: 6499

Tensorflow placeholder shape

In tensorflow, we specify a placeholder as, say:

X = tf.placeholder(tf.float32, (None, 64, 64, 3))

to indicate unknown number of batches of 64x64x3 images.

Sometimes we don't know the dimensions of the placeholder, and we can just say:

X = tf.placeholder(tf.float32)

What are advantages and disadvantages of specifying shapes whenever we can?

E.g. are there performance gains, is it only for defensive programming (throw errors when feeded arrays have wrong dims), etc...

Upvotes: 2

Views: 81

Answers (1)

Marianne Linhares
Marianne Linhares

Reputation: 96

I think this was already answered in this question: Are there any downsides of creating TensorFlow placeholders for variable sized vs. fixed sized inputs?.

But in summary: for efficiency and debugging reasons, you probably want to specify the shapes whenever you can. The disadvantage is that your code probably will not be so reusable.

Upvotes: 2

Related Questions