3

I have created an image classification model using TensorFlow and Keras in google colab. It is saved there with GPU versions 1.15 and 2.2.4 for both respectively. Now I want to load them in my remote machine with CPU and versions 1.10 and 2.2.2 I am unable to do that and getting error.This is my first experience with CNN as well as tf and keras so I am not able to figure out what is the exact reason and how to solve this. I have mentioned the code and error below:

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import load_model
from tensorflow.keras.models import model_from_json

json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)

Error : ValueError: ('Unrecognized keyword arguments:', dict_keys(['ragged']))

Rudra Patel
  • 31
  • 1
  • 2

1 Answers1

2

Tensorflow 1.15 contains breaking changes like ragged tensor support, so it does not support backwards compatibility(Tf 1.10). This is the issue. Please try to load it using Tensorflow 1.15 and it should work.

You can load tf1.15+ model using tf1.15-2.1. Then save only weights to open in tf1.10
___________________________________________________________________
# In tensorflow 1.15-2.1
# Load model
model = load_model("my_model.h5")

# Save weights and architecture
model.save_weights("weights_only.h5")

# Save model config
json_config = model.to_json()
with open('model_config.json', 'w') as json_file:
json_file.write(json_config)
___________________________________________________________________
# In tensorflow 1.10
# Reload the model from the 2 files we saved
with open('model_config.json') as json_file:
json_config = json_file.read()
new_model = tf.keras.models.model_from_json(json_config)

# Load weights
new_model.load_weights('weights_only.h5')

You can refer the link for better understanding on this LINK

kumar_ai
  • 143
  • 3
  • Thank you. I am able to load it with 1.15 on Google colab but I want to do the same in my laptop offline. Can I install TensorFlow 1.15 in a laptop with CPU? I tried with Anaconda but I am unable to install that version. Is it anything like that this version is available only for GPU? – Rudra Patel Mar 25 '20 at 18:19