Python 我可以禁用keras中的val_损失计算吗?

Python 我可以禁用keras中的val_损失计算吗?,python,tensorflow,keras,loss-function,loss,Python,Tensorflow,Keras,Loss Function,Loss,实际上,我想在培训和验证阶段使用不同的损失函数。我试过了,但没用 所以我想知道我可以禁用val_损耗计算吗?下面有一个自定义损耗功能: # Build a model inputs = Input(shape=(128,)) layer1 = Dense(64, activation='relu')(inputs) layer2 = Dense(64, activation='relu')(layer1) predictions = Dense(10, activation='softmax')

实际上,我想在培训和验证阶段使用不同的损失函数。我试过了,但没用


所以我想知道我可以禁用val_损耗计算吗?

下面有一个自定义损耗功能:

# Build a model
inputs = Input(shape=(128,))
layer1 = Dense(64, activation='relu')(inputs)
layer2 = Dense(64, activation='relu')(layer1)
predictions = Dense(10, activation='softmax')(layer2)
model = Model(inputs=inputs, outputs=predictions)

# Define custom loss
def custom_loss(layer):

    # Create a loss function that adds the MSE loss to the mean of all squared activations of a specific layer
    def loss(y_true,y_pred):
        return K.mean(K.square(y_pred - y_true) + K.square(layer), axis=-1)

    # Return a function
    return loss

# Compile the model
model.compile(optimizer='adam',
              loss=custom_loss(layer), # Call the loss function with the selected layer
              metrics=['accuracy'])

# train
model.fit(data, labels) 

你为什么要这样做?除了常规损失之外,您能否创建keras将评估的自定义指标?