从我的 .h5 转换后,我的 tflite 输出出现问题,我很确定这与我的模型设置方式有关,有人可以看看并指出我哪里出错了吗? ?
base_model=vgg16.VGG16(weights='imagenet',include_top=False) #imports the VGG model and discards the last 1000 neuron layer.
x=base_model.output
x=GlobalAveragePooling2D()(x)
#x=Dense(1024,activation='relu')(x) #we add dense layers so that the model can learn more complex #functions and classify for better results.
#x=Dense(1024,activation='relu')(x) #dense layer 2
#Dense(512,activation='relu')(x) #dense layer 3
preds=Dense(1085,activation='softmax')(x) #final layer with softmax activation
model=Model(inputs=base_model.input,outputs=preds)
model.summary()
#now a model has been created based on our architecture
for layer in model.layers[:20]:
layer.trainable=False
for layer in model.layers[20:]:
layer.trainable=True
train_datagen=ImageDataGenerator(preprocessing_function=preprocess_input) #included in our dependencies
train_generator=train_datagen.flow_from_directory(r'D:/Desktop/4doors', # this is where you specify the path to the main data folder
target_size=(224,224),
color_mode='rgb',
batch_size=10,
class_mode='categorical',
shuffle=True)
opt = SGD(lr= 0.001, momentum=0.9)
model.compile(optimizer=opt,loss='categorical_crossentropy',metrics=['accuracy'])
checkpoint = keras.callbacks.ModelCheckpoint(r'D:/Desktop/5wcars/model{epoch:08d}.h5', period=1)
# Adam optimizer
# loss function will be categorical cross entropy
# evaluation metric will be accuracy
step_size_train=train_generator.n//train_generator.batch_size
model.fit_generator(generator=train_generator,
steps_per_epoch=step_size_train,
epochs=200,callbacks=[checkpoint])