Python 具有内部预测的自定义Keras损失函数

Python 具有内部预测的自定义Keras损失函数,python,tensorflow,machine-learning,keras,Python,Tensorflow,Machine Learning,Keras,我正在使用Keras创建一个模糊神经网络,它会在输入经过训练的分类神经网络之前扭曲图像。为此,我需要根据分类网络产生的值生成损失 我创建了一个丢失函数,它将失真图像作为y\u pred,将分类标签作为y\u true class_model = load_model(model_path) def classfication_error(self, y_true, y_pred): y_pred = class_model.predict(y_pred) return kera

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

我创建了一个丢失函数,它将失真图像作为
y\u pred
,将分类标签作为
y\u 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)