fit_generator()缺少1个必需的位置参数:“generator”

hmmo2u0o  于 2021-08-25  发布在  Java
关注(0)|答案(2)|浏览(722)

我需要帮助来解决这个问题。我不确定出了什么问题,但错误依然存在。环顾四周,但没有发现类似的问题。

import matplotlib.pyplot as plt
from PIL import Image
import os
import numpy as np
from skimage import io
from keras.preprocessing.image import ImageDataGenerator
from matplotlib import cm
from mpl_toolkits.axes_grid1 import ImageGrid
import math
%matplotlib inline
import keras
import tensorflow as tf
from keras.models import Model

batch_size=32
datagen_args = dict(rotation_range=20,
    width_shift_range=0.2,
    height_shift_range=0.2,
                   rescale=1./255)
datagen = ImageDataGenerator(**datagen_args)
train_datagenerator = datagen.flow_from_directory('/content/drive/MyDrive/cats_dogs_small/train',target_size=(128,128),
                                            batch_size=batch_size,interpolation="lanczos",shuffle=True)
valid_datagenerator = datagen.flow_from_directory('/content/drive/MyDrive/cats_dogs_small/validation',target_size=(128,128),
                                            batch_size=batch_size,interpolation="lanczos",shuffle=True)

epochs = 25
hist = Model.fit_generator(train_datagenerator, 
                           steps_per_epoch= math.ceil(train_datagenerator.samples//batch_size),
                           epochs=epochs, validation_data=valid_datagenerator, validation_steps=math.ceil(valid_datagenerator.samples//batch_size),verbose = 1, workers=8)

错误消息如下所示:

TypeError                                 Traceback (most recent call last)
<ipython-input-69-178574fd407f> in <module>()
      2 hist = Model.fit_generator(train_datagenerator, 
      3                            steps_per_epoch= math.ceil(train_datagenerator.samples//batch_size),
----> 4                            epochs=epochs, validation_data=valid_datagenerator, validation_steps=math.ceil(valid_datagenerator.samples//batch_size),verbose = 1, workers=8)

TypeError: fit_generator() missing 1 required positional argument: 'generator'
ndasle7k

ndasle7k1#

fit生成器已折旧,请使用model.fit。注意:您使用了model.fit\u生成器。您应该使用model.fit。

z3yyvxxp

z3yyvxxp2#

我意识到我没有定义什么是模型。添加图层,编译并重试。这次可以了。我是新手,还有很多东西要学!

相关问题