我正在研究multi-label classification问题,large-scale数据是高度imbalanced的。因此,我需要根据直觉应用stratified sampling,即我的ImageDataGenerator按比例从each class中抽取every batch中的数据。如有任何建议/解决方案,将不胜感激。
发布于 2022-01-04 13:37:22
确实是个好问题。
据我所知,在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://stackoverflow.com/questions/70579379
复制相似问题