今TensorFlow公式のチュートリアルを実行しているのですが、自分が使っているTensorFlow2.0には存在しない「placeholder」が使われており、進みません。
発生している問題・エラーメッセージ
AttributeError Traceback (most recent call last)
<ipython-input-14-160ddb0d1902> in <module>
----> 1 x = tf.placeholder(tf.zeros([None,784]))
AttributeError: module 'tensorflow' has no attribute 'placeholder'
該当のソースコード
linux ubuntu18.04.3 Python3.6.8-TensorFlow2.0-gpu NVIDIA-SMI 430.50 Driver Version: 430.50 CUDA Version: 10.1 `` tf.TensorSpecを試してみましたが以下のようなエラーが出 import tensorflow as tf from tensorflow import keras from matplotlib import pyplot as plt from matplotlib import cm import numpy as np (trainX,trainY),(testX,testY) = keras.datasets.mnist.load_data() w = tf.Variable(tf.zeros([784,10])) b = tf.Variable(tf.zeros([10])) x = tf.TensorSpec([None], tf.float32) y = tf.nn.softmax(tf.matmul(x, w)+b) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-17-9ff920be21e1> in <module> ----> 1 y = tf.nn.softmax(tf.matmul(x, w)+b) ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/util/dispatch.py in wrapper(*args, **kwargs) 178 """Call target, and fall back on dispatchers if there is a TypeError.""" 179 try: --> 180 return target(*args, **kwargs) 181 except (TypeError, ValueError): 182 # Note: convert_to_eager_tensor currently raises a ValueError, not a ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/ops/math_ops.py in matmul(a, b, transpose_a, transpose_b, adjoint_a, adjoint_b, a_is_sparse, b_is_sparse, name) 2693 if context.executing_eagerly(): 2694 if not isinstance(a, (ops.EagerTensor, _resource_variable_type)): -> 2695 a = ops.convert_to_tensor(a, name="a") 2696 if not isinstance(b, (ops.EagerTensor, _resource_variable_type)): 2697 b = ops.convert_to_tensor(b, name="b") ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in convert_to_tensor(value, dtype, name, preferred_dtype, dtype_hint) 1182 preferred_dtype = deprecation.deprecated_argument_lookup( 1183 "dtype_hint", dtype_hint, "preferred_dtype", preferred_dtype) -> 1184 return convert_to_tensor_v2(value, dtype, preferred_dtype, name) 1185 1186 ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in convert_to_tensor_v2(value, dtype, dtype_hint, name) 1240 name=name, 1241 preferred_dtype=dtype_hint, -> 1242 as_ref=False) 1243 1244 ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx, accept_composite_tensors) 1294 1295 if ret is None: -> 1296 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) 1297 1298 if ret is NotImplemented: ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref) 284 as_ref=False): 285 _ = as_ref --> 286 return constant(v, dtype=dtype, name=name) 287 288 ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py in constant(value, dtype, shape, name) 225 """ 226 return _constant_impl(value, dtype, shape, name, verify_shape=False, --> 227 allow_broadcast=True) 228 229 ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast) 233 ctx = context.context() 234 if ctx.executing_eagerly(): --> 235 t = convert_to_eager_tensor(value, ctx, dtype) 236 if shape is None: 237 return t ~/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype) 94 dtype = dtypes.as_dtype(dtype).as_datatype_enum 95 ctx.ensure_initialized() ---> 96 return ops.EagerTensor(value, ctx.device_name, dtype) 97 98 ValueError: Attempt to convert a value (TensorSpec(shape=(None,), dtype=tf.float32, name=None)) with an unsupported type (<class 'tensorflow.python.framework.tensor_spec.TensorSpec'>) to a Tensor. ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/11/20 04:21