##やりたいこと
tensorflowでニューラルネットワークを構築したい。
##発生している問題
tensorflowで任意の変数を指定する際にNoneを使うのですが、
Noneを使ったところ、
ValueError: None values not supported
が発生してしまいました。
##問題のコード
import tensorflow as tf def weight(shape = []): initial = tf.truncated_nomal(shape, stddev = 0.01) return tf.Variable(initial) def bias(dtype =tf.float32, shape = []): initial = tf.zeros(shape, dtype= dtype) return tf.Variable(initial) P,Q=5,2 X = tf.placeholder(dtype = tf.float32, shape =[None, 0]) W = weight(shape = [Q,P]) b = bias(shape = [P]) f = tf.matmul(X ,W)+b
###使用環境
Ubuntu16.
python3.x
tensorflow 0.7.1
####追記
nomal→normalに訂正したところ、
>>> def weight(shape = []): ... initial = tf.truncated_normal(shape, stddev = 0.01) ... return tf.Variable(initial) ... >>> def bias(dtype =tf.float32, shape = []): ... initial = tf.zeros(shape, dtype= dtype) ... return tf.Variable(initial) ... >>> P,Q=5,2 >>> >>> X = tf.placeholder(dtype = tf.float32, shape =[None, 0]) >>> W = weight(shape = [Q,P]) >>> b = bias(shape = [P]) >>> f = tf.matmul(X ,W)+b Traceback (most recent call last): File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 671, in _call_cpp_shape_fn_impl input_tensors_as_shapes, status) File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__ next(self.gen) File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimensions must be equal, but are 0 and 2 for 'MatMul_1' (op: 'MatMul') with input shapes: [?,0], [2,5]. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/ops/math_ops.py", line 1816, in matmul a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name) File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/ops/gen_math_ops.py", line 1217, in _mat_mul transpose_b=transpose_b, name=name) File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op op_def=op_def) File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2508, in create_op set_shapes_for_outputs(ret) File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1873, in set_shapes_for_outputs shapes = shape_func(op) File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1823, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn debug_python_shape_fn, require_shape_fn) File "/home/daisuke/.local/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 676, in _call_cpp_shape_fn_impl raise ValueError(err.message) ValueError: Dimensions must be equal, but are 0 and 2 for 'MatMul_1' (op: 'MatMul') with input shapes: [?,0], [2,5]. >>>
とより複雑なエラーが出てきました・・・
回答1件
あなたの回答
tips
プレビュー