我正在使用DensetNet121
预训练模型对乳腺癌图像进行分类。我将数据集分为训练,测试和验证。我想应用k-fold cross validation
。我使用sklearn
库中的cross_validation
,但当我运行代码时,我得到了下面的错误。我试图解决它,但没有解决错误。任何人都知道如何解决这个问题。
in_model = tf.keras.applications.DenseNet121(input_shape=(224,224,3),
include_top=False,
weights='imagenet',classes = 2)
in_model.trainable = False
inputs = tf.keras.Input(shape=(224,224,3))
x = in_model(inputs)
flat = Flatten()(x)
dense_1 = Dense(1024,activation = 'relu')(flat)
dense_2 = Dense(1024,activation = 'relu')(dense_1)
prediction = Dense(2,activation = 'softmax')(dense_2)
in_pred = Model(inputs = inputs,outputs = prediction)
validation_data=(valid_data,valid_labels)
#16
in_pred.summary()
in_pred.compile(optimizer = tf.keras.optimizers.Adagrad(learning_rate=0.0002), loss=tf.keras.losses.CategoricalCrossentropy(from_logits = False), metrics=['accuracy'])
history=in_pred.fit(train_data,train_labels,epochs = 3,batch_size=32,validation_data=validation_data)
model_result=cross_validation(in_pred, train_data, train_labels, 5)
错误:
TypeError: Cannot clone object '<keras.engine.functional.Functional object at 0x000001F82E17E3A0>'
(type <class 'keras.engine.functional.Functional'>):
it does not seem to be a scikit-learn estimator as it does not implement a 'get_params' method.
1条答案
按热度按时间ijnw1ujt1#
由于您的模型不是scikit-learn估计器,因此无法使用sklearn的内置
cross_validate
方法。但是,你可以使用k-fold将数据分割成k个折叠,并获得每个折叠的指标。我们可以使用
model.evaluate
中内置的TF,或者在这里使用sklearn的指标。