【发布时间】:2019-09-28 21:31:22
【问题描述】:
我可以使用“categorical_crossentropy”作为损失函数而不会出错,但是当我用“mse”替换它时,会出现此错误:
检查目标时出错:预期dense_2 的形状为(2,),但得到的数组的形状为(1,)
如果我使用下面的方法
labels = np_utils.to_categorical(labels, num_classes = 2)
另一个错误引发:
支持的目标类型有:('binary', 'multiclass')。改为使用“多标签指示符”。
问题是如何将“mse”与 cross_val_score() 函数一起使用?
这是github link,这是麻烦的代码:
model = KerasClassifier(build_fn=customXceptionBuild, epochs=epochs, batch_size=batch_size)
kfold = StratifiedKFold(n_splits=folds, shuffle=True, random_state=random_state)
def classification_report_with_accuracy_score(y_true, y_pred):
originalclass.extend(y_true)
predictedclass.extend(y_pred)
return accuracy_score(y_true, y_pred) # return accuracy score
scoring = make_scorer(classification_report_with_accuracy_score)
scores = cross_val_score(model, data, labels, cv=kfold, error_score="raise", scoring=scoring )
customXceptionBuild 函数实现了 Xception 预训练模型,并使用“mse”作为损失函数。
【问题讨论】:
标签: python keras scikit-learn deep-learning loss-function