18

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?

Pe Dro
  • 2,651
  • 3
  • 24
  • 44

10 Answers10

12

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
Masoud Maleki
  • 813
  • 6
  • 13
  • 1
    If you want to install a certain version, two consecutive equal signs are required. E.g.: pip install -U protobuf==3.8.0 – Daniel B. Feb 08 '20 at 12:49
2

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.

Rishabh Sahrawat
  • 2,437
  • 1
  • 15
  • 32
  • The TF version is : '2.1.0-dev20191011' – Pe Dro Oct 11 '19 at 14:43
  • YOu must have then used 'dev20191010' Also, these nightly builds gets changed everyday so take care or roll back to stable 2.0 – Rishabh Sahrawat Oct 11 '19 at 14:44
  • Yes it was the same version yesterday! Actually, there was an update some days ago and then I began facing some issues due to some broken features in the new TF version. I had to use: !pip install tf-hub-nightly alongwith !pip install tf-nightly-gpu. – Pe Dro Oct 11 '19 at 14:45
  • Today is 11 october, and yesterday was 10, so you must have used `dev20191010` yesterday. Rollback to this version and test. – Rishabh Sahrawat Oct 11 '19 at 14:46
2

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

Progga Ilma
  • 578
  • 6
  • 8
2

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.

Progga Ilma
  • 578
  • 6
  • 8
0

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

0

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 .

0

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
0

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

0

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.

Matt Allen
  • 492
  • 5
  • 12
-1

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

shrivallabha.redij
  • 5,832
  • 1
  • 12
  • 27