I am trying to fine tune and save a model in Keras and load it, but I am getting this error:
Value Error: You are trying to load a weight file containing 16 layers into a model with 0 layers.
I tried another model for number I made it save and load mode work without error
when I tried to adopt vgg16, it gave that error
I want load model but can't load because of this error. Can anyone help?
import keras
from keras.models import Sequential,load_model,model_from_json
from keras import backend as K
from keras.layers import Activation,Conv2D,MaxPooling2D,Dropout
from keras.layers.core import Dense,Flatten
from keras.optimizers import Adam
from keras.metrics import categorical_crossentropy
from keras.layers.normalization import BatchNormalization
from keras.layers.convolutional import *
from keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
import itertools
from sklearn.metrics import confusion_matrix
import numpy as np
train_path='dataset/train'
test_path='dataset/test'
valid_path='dataset/valid'
train_batches=ImageDataGenerator()
.flow_from_directory(train_path,batch_size=1,target_size=(224,224),classes=
['dog','cat'])
valid_batches=ImageDataGenerator()
.flow_from_directory(valid_path,batch_size=4,target_size=(224,224),classes=
['dog','cat'])
test_batches=ImageDataGenerator()
.flow_from_directory(test_path,target_size=(224,224),classes=['dog','cat'])
vgg16_model=keras.applications.vgg16.VGG16();
vgg16_model.summary()
type(vgg16_model)
model=Sequential()
for layer in vgg16_model.layers[:-1]:
model.add(layer)
for layer in model.layers:
layer.trainable=False
model.add(Dense(2,activation='softmax'))
model.compile(Adam(lr=.0001),loss='categorical_crossentropy',metrics=
['accuracy'])
model.fit_generator(train_batches,validation_data=valid_batches,epochs=1)
model.save('test.h5')
model.summary()
xx=load_model('test.h5')