4

我正在使用 Keras 创建一个混淆神经网络,它会在输入经过训练的分类神经网络之前扭曲图像。为此,我需要根据分类网络产生的值生成损失。

我创建了一个损失函数,将失真图像输入为y_pred,分类标签输入为y_true

class_model = load_model(model_path)

def classfication_error(self, y_true, y_pred):
    y_pred = class_model.predict(y_pred)
    return keras.losses.categorical_crossentropy(y_true, y_pred)

编译模型时,由于形状的原因,我收到以下错误y_pred = (?, 32, 32, 3)

ValueError: When feeding symbolic tensors to a model, we expect thetensors to have a static batch size. Got tensor with shape: (None, 32, 32, 3)

在损失函数中完成预测以避免错误的另一种方法是什么?

4

0 回答 0