Tensorflow Keras:TypeError:';浮动';对象不可调用。无法在非常简单的CNN模型上调用model.fit()或model.fit\u生成器()

Tensorflow Keras:TypeError:';浮动';对象不可调用。无法在非常简单的CNN模型上调用model.fit()或model.fit\u生成器(),tensorflow,keras,deep-learning,computer-vision,conv-neural-network,Tensorflow,Keras,Deep Learning,Computer Vision,Conv Neural Network,我正在处理MNIST手语数据集进行分类。我的(28*28)图像像素以numpy数组显示,如下所示: X_train.shape, X_val.shape >> ((2496, 28, 28, 1), (996, 28, 28, 1)) 我使用了ImageDataGenerator进行批量生产和模型培训。我已收到以下指示: Batch size =50, epoch=20 All filter (kernel) sizes are 3x3 Initial Conv2D layer w

我正在处理
MNIST手语数据集
进行分类。我的(28*28)图像像素以numpy数组显示,如下所示:

X_train.shape, X_val.shape
>>
((2496, 28, 28, 1), (996, 28, 28, 1))
我使用了
ImageDataGenerator
进行批量生产和模型培训。我已收到以下指示:

Batch size =50, epoch=20
All filter (kernel) sizes are 3x3
Initial Conv2D layer with 64 filters
MaxPooling layer following this
Second Conv2D layer with 128 filters
Dense output layer after this
我的模型如下:

datagen = ImageDataGenerator(preprocessing_function=1./255.0)
train_gen = datagen.flow(X_train, y_train, batch_size=50)
val_gen = datagen.flow(X_val,y_val, batch_size=50)

input_ = Input(shape=(28,28,1))
x = Conv2D(64,kernel_size=(3,3))(input_)
x = ELU()(x)
x = MaxPooling2D(pool_size=(3,3))(x)
x = Conv2D(128,kernel_size=(3,3))(input_)
x = ELU()(x)
x = Flatten()(x)
out = Dense(24,activation='softmax')(x)

model = Model(inputs=input_,outputs=out)
model.compile(loss=sparse_categorical_crossentropy,optimizer=Adam(lr=0.001),metrics=['accuracy'])

model.fit(train_gen,epochs=20,) 

我使用了
稀疏分类交叉熵
,因为我的y_标签中缺少一些类值。0-24之间有24个类,但缺少类=9

有人能告诉我为什么会这样吗

我认为问题出在
train\u gen
上,因为
next(train\u gen)
给了我同样的错误

误差的下半部分是:

/opt/conda/lib/python3.7/site-packages/keras/utils/data_utils.py in get_index(uid, i)
    404         The value at index `i`.
    405     """
--> 406     return _SHARED_SEQUENCES[uid][i]
    407 
    408 

/opt/conda/lib/python3.7/site-packages/keras_preprocessing/image/iterator.py in __getitem__(self, idx)
     63         index_array = self.index_array[self.batch_size * idx:
     64                                        self.batch_size * (idx + 1)]
---> 65         return self._get_batches_of_transformed_samples(index_array)
     66 
     67     def __len__(self):

/opt/conda/lib/python3.7/site-packages/keras_preprocessing/image/numpy_array_iterator.py in _get_batches_of_transformed_samples(self, index_array)
    152             x = self.image_data_generator.apply_transform(
    153                 x.astype(self.dtype), params)
--> 154             x = self.image_data_generator.standardize(x)
    155             batch_x[i] = x
    156 

/opt/conda/lib/python3.7/site-packages/keras_preprocessing/image/image_data_generator.py in standardize(self, x)
    702         """
    703         if self.preprocessing_function:
--> 704             x = self.preprocessing_function(x)
    705         if self.rescale:
    706             x *= self.rescale

TypeError: 'float' object is not callable


问题在于这一部分:

datagen = ImageDataGenerator(preprocessing_function=1./255.0)
preprocessing_函数
参数需要函数,而不是浮点值。您可能会将其与
重缩放
参数混淆:

datagen = ImageDataGenerator(rescale=1./255.0)

你应该包括完整的回溯,没有上下文的错误是没有意义的。@Dr.Snoopy请看一看哦!我的错。对不起,我浪费了你的时间。事情就是这样。