Я имею дело с мульти-Siemens CNN, который состоит из 3 подсетей, CNN принимает 6 изображений в качестве входных данных, каждые 3 изображения представляют человека. Я обозначил данные следующим образом: 2000 пар как положительные и 2000 пар как отрицательные, но я хочу убедиться, что партии также сбалансированы, например: 64 партии означают 32 положительных и 32 отрицательных.
взятие модели 6 входов следующей формы: (3024, 1, 192, 192) y_train shape = (1008, 1)
Однако, когда я попытался сбалансировать партии, fit_gen ожидал вывода следующего (x, y ) и мне нужен следующий вывод (x [: 0] .. X [: 5], y), чтобы он соответствовал модели
Произошла следующая ошибка
Output of generator should be a tuple `(x, y, sample_weight)` or `(x, y)`. Found: (array([[[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]],
Я использовал следующую формулу для баланса партий:
img_1 = x_train[:, 0]
img_2 = x_train[:, 1]
img_3 = x_train[:, 2]
img_4 = x_train[:, 3]
img_5 = x_train[:, 4]
img_6 = x_train[:, 5]
gen = balanced_generator(x_train,img_1, img_2, img_3, img_4, img_5, img_6, y_train, 64)
modelMerged.fit_generator(gen, steps_per_epoch=1, epochs=epochs)
def balanced_generator(x,x1,x2,x3,x4,x5,x6, y, batch_size):
batch_x_shape = (batch_size, x.shape[1], x.shape[2], x.shape[3],x.shape[4])
batch_y_shape = (batch_size, )
batch_size1 = int(batch_size/2)
batch_x = np.ndarray(shape=batch_x_shape, dtype=x.dtype)
batch_y = np.zeros(shape=batch_y_shape, dtype=y.dtype)
for i in range(batch_size1):
ind1 = np.random.randint(0,y.shape[0])
while y[ind1] == 0:
ind1 = np.random.randint(0,y.shape[0])
batch_x[i,0,:,:,:] = x1[ind1,:,:,:]
batch_x[i,1,:,:,:] = x2[ind1,:,:,:]
batch_x[i,2,:,:,:] = x3[ind1,:,:,:]
batch_x[i,3,:,:,:] = x4[ind1,:,:,:]
batch_x[i,4,:,:,:] = x5[ind1,:,:,:]
batch_x[i,5,:,:,:] = x6[ind1,:,:,:]
batch_y[i] = y[ind1]
for i in range(batch_size):
i = int(batch_size/2)
ind2 = np.random.randint(0,y.shape[0])
while y[ind2] == 0:
ind2 = np.random.randint(0,y.shape[0])
batch_x[i,0,:,:,:] = x1[ind2,:,:,:]
batch_x[i,1,:,:,:] = x2[ind2,:,:,:]
batch_x[i,2,:,:,:] = x3[ind2,:,:,:]
batch_x[i,3,:,:,:] = x4[ind2,:,:,:]
batch_x[i,4,:,:,:] = x5[ind2,:,:,:]
batch_x[i,5,:,:,:] = x6[ind2,:,:,:]
batch_y[i] = y[ind2]
print("batch #")
yield(batch_x[:, 0],batch_x[:, 1],batch_x[:, 2],batch_x[:, 3],batch_x[:, 4],batch_x[:, 5], batch_y)