重塑张量时我得到 None 类型。当使用损失函数和优化器编译模型时(开始训练之前)会发生这种情况。我该怎么办?
错误:
TypeError: Failed to convert object of type <class 'tuple'> to Tensor. Contents: (None, -1). Consider casting elements to a supported type.
Run Code Online (Sandbox Code Playgroud)
自定义损失函数:
def custom_loss(y_true, y_pred):
y_pred = K.reshape(y_pred, (K.get_variable_shape(y_pred)[0], -1))
y_true = K.reshape(y_true, (K.get_variable_shape(y_true)[0], -1))
y_pred = K.std(y_pred, axis=0)
y_true = K.std(y_true, axis=0)
loss = (1/2) * (y_pred - y_true) ** 2
loss = K.mean(loss)
return loss
Run Code Online (Sandbox Code Playgroud)