我正在處理multi-label classification我的large-scale資料高度的問題imbalanced。因此,我需要stratified sampling根據直覺來應用我ImageDataGenerator從each classin 中按比例采樣資料的直覺every batch。任何建議/解決方案將不勝感激。
uj5u.com熱心網友回復:
確實是個好問題。
據我所知,ImageDataGenerator().
我將建議兩種可能的方法:
您可以對類進行子
Sequence()類化,以便能夠準確控制您在網路中的每一步提供的內容。您可以覆寫該__getitem__()方法,并確保批次在每個批次中按比例采樣。您可以使用外部庫在將資料提供給網路之前對其進行預處理。通過這種方式,您可以預處理資料并使用
tf.data.Dataset()管道將資料提供給您的網路。
(2) 的一個例子是這個:
from iterstrat.ml_stratifiers import MultilabelStratifiedKFold
import numpy as np
X = np.array([[1,2], [3,4], [1,2], [3,4], [1,2], [3,4], [1,2], [3,4]])
y = np.array([[0,0], [0,0], [0,1], [0,1], [1,1], [1,1], [1,0], [1,0]])
mskf = MultilabelStratifiedKFold(n_splits=2, shuffle=True, random_state=0)
for train_index, test_index in mskf.split(X, y):
print("TRAIN:", train_index, "TEST:", test_index)
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/403778.html
標籤:
