Skip to content

Instantly share code, notes, and snippets.

@bzamecnik
Created August 11, 2017 14:45
Show Gist options
  • Save bzamecnik/d6769fa4c5b0ff017b76b2dfe7886a19 to your computer and use it in GitHub Desktop.
Save bzamecnik/d6769fa4c5b0ff017b76b2dfe7886a19 to your computer and use it in GitHub Desktop.
TensorFlow - feeding & shapes
# Question: can we replicate https://github.com/rossumai/keras-multi-gpu/issues/2
# InvalidArgumentError: Shape [-1] has negative dimensions
# [[Node: replica_0_1/model_1_sample_weights = Placeholder[dtype=DT_FLOAT, shape=[?], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
import tensorflow as tf
a = tf.placeholder(dtype=tf.int8, shape=(None, None))
b = tf.placeholder(dtype=tf.int8, shape=(None, None))
c = tf.add(a, b)
print(a, b, c)
# Tensor("Placeholder_4:0", shape=(?, ?), dtype=int8) Tensor("Placeholder_5:0", shape=(?, ?), dtype=int8) Tensor("Add_1:0", shape=(?, ?), dtype=int8)
with tf.Session() as sess:
print(sess.run(c, {a: [[1], [3]], b: [[2], [4], [6]]}))
# InvalidArgumentError (see above for traceback): Incompatible shapes: [2,1] vs. [3,1]
# [[Node: Add_1 = Add[T=DT_INT8, _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_Placeholder_4_0_0, _arg_Placeholder_5_0_1)]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment