AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' 对象没有属性 'append'

Pe *_*Dro 13 python protocol-buffers tensorflow google-colaboratory

我正在 Google Collab 上的 MobileNetv2 预训练模型上构建迁移学习模型。直到昨天,一切都很好。但是,今天,在执行

#Create the base model(feature_extractor) from the pre-trained model MobileNet V2
_URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/2"
feature_extractor = hub.KerasLayer(_URL, input_shape=(_TARGET_SIZE, _TARGET_SIZE,3))
Run Code Online (Sandbox Code Playgroud)

我收到错误:


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-663d4cbb70df> in <module>()
      2 _TARGET_SIZE = 224
      3 _URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/2"
----> 4 feature_extractor = hub.KerasLayer(_URL, input_shape=(_TARGET_SIZE, _TARGET_SIZE,3))
      5 #print(feature_extractor._layers)


/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py in _variable_handle_from_shape_and_dtype(shape, dtype, shared_name, name, graph_mode, initial_value)
    165     handle_data = cpp_shape_inference_pb2.CppShapeInferenceResult.HandleData()
    166     handle_data.is_set = True
--> 167     handle_data.shape_and_type.append(
    168         cpp_shape_inference_pb2.CppShapeInferenceResult.HandleShapeAndType(
    169             shape=shape.as_proto(), dtype=dtype.as_datatype_enum))

AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' object has no attribute 'append'
Run Code Online (Sandbox Code Playgroud)

知道为什么会发生这种情况吗,我是否需要进入/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py文件并进行一些更改?我认为它与一些更新问题有关。有关如何解决它的任何帮助?

Mas*_*eki 10

我在使用 tensorflow(版本 2.2.0-dev20200128)时遇到了同样的错误,并通过升级 protobuf 来修复它(如本期所述):

pip install -U protobuf==3.8.0
Run Code Online (Sandbox Code Playgroud)

或者,如果您使用 Notebook(如 Google Colab notebook),请尝试以下操作:

!pip install -U protobuf==3.8.0
Run Code Online (Sandbox Code Playgroud)


Ris*_*wat 2

如果直到昨天它都运行良好并且您没有更改任何内容,则检查两件事 - \nTh TF 版本,如果最近更改了 bc,他们将“默认”TF 版本从 1.14 设置为 1.15.rc。

\n\n

如果相同,则保存此文件并关闭所有 Colab 窗口,甚至您的 chrome 或您正在使用的任何浏览器,然后再次打开并尝试运行该文件。

\n\n

编辑:\n正如我上面所说,这一定是因为 TF 版本。因此,请恢复到模型运行时使用的模型。正如您在下面的评论中提到的,它正在版本 \xe2\x80\x98dev20191010\xe2\x80\x99 上工作,因此回滚到它可以解决您的问题。

\n