这是我的图像处理模型代码 -
import os
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
from keras.layers import Input, Lambda, Dense, Flatten
from keras.models import Model
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input
from keras.preprocessing import image
from keras.src.legacy.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
import numpy as np
from glob import glob
import matplotlib.pyplot as plt
# create a model object
model = Model(inputs=vgg.input, outputs=prediction)
# view the structure of the model
model.summary()
# tell the model what cost and optimization method to use
model.compile(optimizer="adam", loss="categorical_crossentropy", metrics=['accuracy'])
'''r=model.fit_generator(training_set,
samples_per_epoch = 8000,
nb_epoch = 5,
validation_data = test_set,
nb_val_samples = 2000)'''
# fit the model
r = model.fit_generator(
training_set,
validation_data=test_set,
epochs=5,
steps_per_epoch=len(training_set),
validation_steps=len(test_set)
)
r = model.fit_generator(training_set,
但它显示属性错误错误为:
AttributeError: 'Functional' object has no attribute 'fit_generator'
我将我的模型编译为:我已经与此处的其他答案进行了交叉检查,但没有一个与我的错误相符
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
从tensorflow 2.1.0开始,fit_generator已被折旧并且不再存在。您可以直接使用 fit 来代替。