Convolutional Neural Network W4A1

Hello. When I tried the W4A1 th assignment of the Convolutional Neural Network course on my own computer, in the following model_from_json code:

from tensorflow.keras.models import model_from_json

json_file = open(‘keras-facenet-h5/model.json’, ‘r’)
loaded_model_json =
model = model_from_json(loaded_model_json)

I get this error:

ValueError: bad marshal data (unknown type code)

How can i solve this.

You should first compare python versions of the two environments. Likely your local is newer (eg Python 3.x) and incorporates a non-backwards compatible change. One fix is to use virtual environments to run locally so you can match the release level of the modules that run the code successfully (eg Python 2.x).

To add on what ai_curious mentioned, check the compatibility of the python version and the TF version. Ideally, you should be using the versions that are on Coursera.

Good advice for the entire environment, not just the several explicitly mentioned already in this thread.

However, specifically for the marshal error…

Details of the format are undocumented on purpose; it may change between Python versions (although it rarely does). 1

This is not a general “persistence” module. For general persistence and transfer of Python objects through RPC calls, see the modules pickle and shelve. The marshal module exists mainly to support reading and writing the “pseudo-compiled” code for Python modules of .pyc files. Therefore, the Python maintainers reserve the right to modify the marshal format in backward incompatible ways should the need arise.

My emphasis added

Which is why I believe Python the culprit here. Cheers

1 Like