M1 最大 Tensorflow model.fit() InvalidArgumentError

M1 Max Tensorflow model.fit() InvalidArgumentError

这是我在 M1 Mac 上的第一个 CNN 项目,当我 运行 model.fit().

时遇到 InvalidArgumentError

我正在使用 tensorflow-metal 3.0、tensorflow-macos 2.7 和 运行ning MacOS 12.1.

early_stop = EarlyStopping(monitor="val_accuracy", patience=10)
optimizer = tf.keras.optimizers.Adam(learning_rate=lr, amsgrad=True)

model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])

train_datagen = ImageDataGenerator(rescale = 1./255,
                                   shear_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True)

train_set = train_datagen.flow_from_directory(train_path,
                                              target_size = (224, 224),
                                              batch_size = batch_size,
                                              class_mode = 'categorical')                                                                        

res = model.fit(train_set,
                validation_data=test_set,
                batch_size=batch_size,
                epochs=epochs,
                steps_per_epoch=len(train_set),
                validation_steps=len(test_set),
                callbacks=[ckpt_saver, early_stop]
                )

我已经通过使用其他优化器(不是 Adam)暂时解决了问题。