C3W3_Assignment in Advanced Computer Vision with TensorFlow - cannot downgrade TensorFlow and Keras to submit my trained model

I have trained a model in the Week 3 assessment of Advanced Computer Vision with TensorFlow and I have saved it as temp_model.h5

Now I need to downgrade Keras and TensorFlow in Google Colab to convert the model to a version that the grader understands

I run the

!pip install tensorflow==2.8.0 --quiet
!pip install keras==2.8.0 --quiet

and the output seems OK. I do “Runtime > Restart Session”. Then I run the code to check the downgrade

import tensorflow as tf

Check if you have the correct Tensorflow version

assert tf.version == ‘2.8.0’, f’You have TF{tf.version}. Please install the grader-compatible Tensorflow and select Runtime > Restart Session’

I get an error - but not an AssertionError - a TypeError - and it’s triggering on the line “import tensorflow as tf”


TypeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 import tensorflow as tf
2
3 # Check if you have the correct Tensorflow version
4 assert tf.version == ‘2.8.0’, f’You have TF{tf.version}. Please install the grader-compatible Tensorflow and select Runtime > Restart Session’

8 frames
/usr/local/lib/python3.10/dist-packages/google/protobuf/descriptor.py in new(cls, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options, serialized_options, has_default_value, containing_oneof, json_name, file, create_key)
551 has_default_value=True, containing_oneof=None, json_name=None,
552 file=None, create_key=None): # pylint: disable=redefined-builtin
→ 553 _message.Message._CheckCalledFromGeneratedFile()
554 if is_extension:
555 return _message.default_pool.FindExtensionByName(full_name)

TypeError: Descriptors cannot be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:

  1. Downgrade the protobuf package to 3.20.x or lower.
  2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: Changes announced May 6, 2022 | Protocol Buffers Documentation

Can anyone help?

Thanks,

Chris

I get the same TypeError if I start from a completely blank Colab workbook, running on CPU, and run

!pip install tensorflow==2.8.0 --quiet
!pip install keras==2.8.0 --quiet

then Runtime > Restart Session

then run

import tensorflow as tf

you need to just downgrade the protobuf. According to the last time this issue occurred, the lab was updated with the necessary change. Try to go back to your classroom page, refresh it and then open. check if that includes the changes. Do not add anything by yourself

The lab has not been updated. What is the necessary change?

Try with


!pip install protobuf==3.20.*

and then restart the kernel

but make sure you start this, from classroom page, not from the already opened classroom page where you have pip install tf and keras quiet

1 Like

OK - I’m not sure what you mean by “make sure you start this, from classroom page, not from the already opened classroom page”. I started a new blank Colab notebook and ran

!pip install protobuf==3.20.*

then Runtime > Restart Session

then
!pip install tensorflow==2.8.0 --quiet
!pip install keras==2.8.0 --quiet

then Runtime > Restart Session

and now “import tensorflow as tf” runs - so I can load my saved “temp_model.h5” into this session and copy across the conversion code from the assignment.

Thank you!

1 Like