[英]How to prevent one fold to perform a lot worse than the other 9 in 10-fold cross validation for CNN classification
我目前正在Keras上進行2D CNN的MRI分類。 類比約為60/40,我有155位患者,每位患者進行一次MRI包括大約180個切片,CNN的輸入是一張MRI圖像的切片(256 * 256 px)(所以輸入總計為〜27900圖片,每個256 * 256像素)。
我測試了不同的模型,並始終使用經過改組的分層10倍交叉驗證和EarlyStopping監視器對它們進行評估,它們的表現都非常好,驗證准確率約為95%到98%。 但是每次,一兩折的表現都比其他折痕差很多(驗證准確性為70%到80%)。 由於折疊是隨機的,我希望所有折疊的表現都一樣好。
有人可以解釋這種情況如何發生以及如何預防嗎?
准確性和損失圖:
這是模型之一的一部分:
num_classes = 2
img_size = 256
batch_size = 200
# Because of EarlyStopping monitor, the number of epochs doesn't really matter
num_epochs = 1000
kfold_splits = 10
skf = StratifiedKFold(n_splits=kfold_splits, shuffle=True)
# Here the data is split
for index, (train_index, test_index) in enumerate(skf.split(x_data_paths, y_data_paths)):
x_train, x_test = np.array(x_data_paths)[train_index.astype(int)], np.array(x_data_paths)[test_index.astype(int)]
y_train, y_test = np.array(y_data_paths)[train_index.astype(int)], np.array(y_data_paths)[test_index.astype(int)]
training_batch_generator = BcMRISequence(x_train, y_train_one_hot, batch_size)
test_batch_generator = BcMRISequence(x_test, y_test_one_hot, batch_size)
# region Create model (using the functional API)
inputs = Input(shape=(img_size, img_size, 1))
conv1 = Conv2D(64, kernel_size=5, strides=1, activation='relu')(inputs)
pool1 = MaxPooling2D(pool_size=3, strides=(2, 2), padding='valid')(conv1)
conv2 = Conv2D(32, kernel_size=3, activation='relu')(pool1)
pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
conv3 = Conv2D(16, kernel_size=3, activation='relu')(pool2)
pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)
flat = Flatten()(pool3)
hidden1 = Dense(10, activation='relu')(flat)
output = Dense(num_classes, activation='softmax')(hidden1)
model = Model(inputs=inputs, outputs=output)
以防萬一其他人偶然發現了我的問題:通過使用10次迭代而不是10倍交叉驗證的分層混洗拆分,我擺脫了異常折疊。 我的猜測是由於某種“批處理效應”(10倍交叉驗證不會僅攪動患者的MRI切片)而出現這種不良折疊。 另一方面,混洗拆分會在拆分為訓練和測試之前對整個數據集進行混洗,因此避免了“不良”患者一並出現。
如果有人有興趣,這些是新的情節。 與以前相同的模型,只是混洗拆分而不是k折交叉驗證。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.