I ran my code and saved saved my model using the following code:
model_json = model.to_json()
with open(inFilePath+".json", "w") as json_file:
json_file.write(model_json)
modWeightsFilepath=inFilePath+".weights.hdf5"
checkpoint = ModelCheckpoint(modWeightsFilepath, monitor='val_accuracy', verbose=1, save_best_only=True, save_weights_only=True, mode='auto')
And then I wanted to load my model again to make predictions:
from keras.models import model_from_json
json_file = open('/home/models/final_model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
#load weights into new model
model.load_weights('/home/models/final_model.weights.hdf5')
print("Loaded model from disk")
But this gives me the following error:
TypeError: __init__() got an unexpected keyword argument 'ragged'
Full traceback:
And I don't quite know what's wrong. My Keras gpu version is 2.1.6-tf.
Edit:
In order to create the model I used:
import json
import numpy as np
from generator import DataGenerator
import tensorflow
KERAS_BACKEND=tensorflow
import keras
from keras.preprocessing import sequence
from keras.models import Sequential, Model
from keras import optimizers
from keras.layers import Dense, Dropout, Activation, Flatten, Input
from keras.layers import Conv1D, AveragePooling1D, MaxPooling1D
from keras.layers.merge import concatenate
from keras.optimizers import SGD
import os
import sys
from itertools import chain
#import matplotlib.pyplot as plt
from functools import reduce
from keras.callbacks import EarlyStopping,ModelCheckpoint
from sklearn.utils import class_weight
And in order to load the model, I imported: from keras.models import model_from_json
after which I got the error that I told you about. And then I changed it to:
from tensorflow.keras.models import model_from_json
And the error persisted.