Pe Dro
Pe Dro

Reputation: 3033

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

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?

Upvotes: 20

Views: 44779

Answers (10)

Anjana P Das
Anjana P Das

Reputation: 1

I encountered the same issue. I uninstalled protobuf and then reinstalled. Issue Solved.

Upvotes: -1

Matt Allen
Matt Allen

Reputation: 522

I had a running sample code which loads a model and makes predictions on some image inputs. I wanted to call the predictions from C# code that's why I had to install an ONNX conversion package called winmltools. I have installed winmltools and after the installation on my python environment (ver 3.6), I start getting this message while tempted to run the previously running python code. Obviously the winmltools package must have changed versions of some support packages of tensorflow (possibly protobuf or else). I have simply reinstalled tensorflow, by using "pip install tensorflow" and the installation process cleared the issue.

In short, first try to re-install tensorflow and see if this fixes your problem.

Upvotes: 0

Taehwan Koh
Taehwan Koh

Reputation: 1

Today Jun 23th 2020, I fix this problem by upgrading tensorboard bt 2.2.2 Thank you for your Question that make

Upvotes: 0

sujithramanathan
sujithramanathan

Reputation: 1201

Today Jun 19th 2020, TF Version 2.2.0. I Ran the below command inside jupyter notebook and then properly closed the opened notebooks and shutdown the jupyter server then restarted Anaconda Navigator. Finally worked !!!

Protobuf upgrade:-

!pip install --upgrade protobuf

Upvotes: 0

Phuoc Thanh
Phuoc Thanh

Reputation: 1

I had the same problem. I re-installed protobuf = 3.11.3 and it worked fine again. By using :

!pip install -U protobuf==3.11.3

Then restart your kernel as well .

Upvotes: 0

user13379915
user13379915

Reputation: 1

today is April 22, 2020. Tensorflow 2.1 seems to require protobuf 3.11.3, so use: pip install -U protobuf==3.11.3 worked for me

Upvotes: 0

Usman Mushtaq
Usman Mushtaq

Reputation: 21

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.

Upvotes: 2

Masoud Maleki
Masoud Maleki

Reputation: 873

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

Upvotes: 12

Progga Ilma
Progga Ilma

Reputation: 635

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

Upvotes: 2

Rishabh Sahrawat
Rishabh Sahrawat

Reputation: 2507

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.

Upvotes: 2

Related Questions