AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' object has no attribute 'append'

房东的猫 提交于 2020-04-13 02:15:07

问题


I am building a transfer learning model on the MobileNetv2 pretrained model on Google Collab. Till yesterday, everything was fine. But, today, on executing

#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))

I get the error:


---------------------------------------------------------------------------
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'

Any idea why this happens and do I need to get into the /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py file and make some changes ? I think its related to some update issue. Any help on how to tackle it?


回答1:


If it was running fine until yesterday and you did not change anything, then check for two things- Th TF version, if it has changed bc recently they set 'default' TF version to 1.15.rc from 1.14.

If that is same then save this file and close all the colab windows even your chrome or whatever browser you are using then open again and try running the file.

EDIT: As I said above it must be because of the TF version. So revert back to the one that you used when the model was working. As you mentioned in your comments below it was working on version ‘dev20191010’, so rolling back to it will fix your issue.




回答2:


I had same error with tensorflow (version 2.2.0-dev20200128) and fixed it by upgrading protobuf (As explained in this issue):

pip install -U protobuf==3.8.0

Or if your using Notebook (like Google Colab notebook) try this:

!pip install -U protobuf==3.8.0



回答3:


Try opening 'New Python 3 notebook' from file and write code there,that solved my problem.




回答4:


I installed tensorflow and was getting same issue, what i did:

Step 1: Upgraded protobuf with:

pip install -U protobuf==3.8.0

Step 2: Closed everything or python environment and relaunch it.



来源:https://stackoverflow.com/questions/58343293/attributeerror-google-protobuf-pyext-message-repeatedcompositeco-object-has

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!