pycharm运行错误如何解决?

AttributeError: 'RepeatedCompositeFieldContainer' object has no attribute 'append'

在pycharm中导入tensorflow模块,测试GradientTape函数

相关代码

import tensorflow as tf

with tf.GradientTape() as tape:
    x = tf.Variable(tf.constant(3.0))
    y = tf.pow(x, 2)
grad = tape.gradient(y, x)
print(grad)

出现如下错误

Traceback (most recent call last):
File "E:/MOOCTF2.1/class1/p34_GradientTape.py", line 4, in <module>

x = tf.Variable(tf.constant(3.0))

File "G:PYTHONlibsite-packagestensorflowpythonopsvariables.py", line 261, in call

return cls._variable_v2_call(*args, **kwargs)

File "G:PYTHONlibsite-packagestensorflowpythonopsvariables.py", line 255, in _variable_v2_call

shape=shape)

File "G:PYTHONlibsite-packagestensorflowpythonopsvariables.py", line 236, in <lambda>

previous_getter = lambda **kws: default_variable_creator_v2(None, **kws)

File "G:PYTHONlibsite-packagestensorflowpythonopsvariable_scope.py", line 2647, in default_variable_creator_v2

shape=shape)

File "G:PYTHONlibsite-packagestensorflowpythonopsvariables.py", line 263, in call

return super(VariableMetaclass, cls).__call__(*args, **kwargs)

File "G:PYTHONlibsite-packagestensorflowpythonopsresource_variable_ops.py", line 1434, in init

distribute_strategy=distribute_strategy)

File "G:PYTHONlibsite-packagestensorflowpythonopsresource_variable_ops.py", line 1582, in _init_from_args

graph_mode=self._in_graph_mode)

File "G:PYTHONlibsite-packagestensorflowpythonopsresource_variable_ops.py", line 243, in eager_safe_variable_handle

shape, dtype, shared_name, name, graph_mode, initial_value)

File "G:PYTHONlibsite-packagestensorflowpythonopsresource_variable_ops.py", line 179, in _variable_handle_from_shape_and_dtype

handle_data.shape_and_type.append(

AttributeError: 'RepeatedCompositeFieldContainer' object has no attribute 'append'

Process finished with exit code 1
百度几乎没有类似问题,请教各位大佬,这是怎么回事,应该如何解决呢?

阅读 2.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进