2
テンソルフローで2次元のプレースホルダを定義しようとしていますが、そのサイズは事前にわかりません。したがって、別のプレースホルダを定義しますが、まったく動作しないようです。ここでは最小の例である:テンソルフローの形状としてプレースホルダを使用する
import tensorflow as tf
batchSize = tf.placeholder(tf.int32)
input = tf.placeholder(tf.int32, [batchSize, 5])
エラーメッセージ:
Traceback (most recent call last):
File "C:/Users/v-zhaom/OneDrive/testconv/test_placeholder.py", line 5, in <module>
input = tf.placeholder(tf.int32, [batchSize, 5])
File "C:\Python35\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1579, in placeholder
shape = tensor_shape.as_shape(shape)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 821, in as_shape
return TensorShape(shape)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 457, in __init__
self._dims = [as_dimension(d) for d in dims_iter]
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 457, in <listcomp>
self._dims = [as_dimension(d) for d in dims_iter]
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 378, in as_dimension
return Dimension(value)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 33, in __init__
self._value = int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'
それから私は、形状をパックしてみましたので、私はこれがあります。
input = tf.placeholder(tf.int32, tf.pack([batchSize, 5]))
は動作しません。次のいずれか
をTraceback (most recent call last):
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 451, in __init__
dims_iter = iter(dims)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 510, in __iter__
raise TypeError("'Tensor' object is not iterable.")
TypeError: 'Tensor' object is not iterable.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/v-zhaom/OneDrive/testconv/test_placeholder.py", line 5, in <module>
input = tf.placeholder(tf.int32, tf.pack([batchSize, 5]))
File "C:\Python35\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1579, in placeholder
shape = tensor_shape.as_shape(shape)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 821, in as_shape
return TensorShape(shape)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 454, in __init__
self._dims = [as_dimension(dims)]
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 378, in as_dimension
return Dimension(value)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 33, in __init__
self._value = int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'