Я подготовил собственный генератор данных для своего приложения Keras.Это работает хорошо, но у меня проблема с метками классов.Вот соответствующая часть кода:
def _get_batches_of_transformed_samples(self, index_array):
# create array to hold the images
batch_x = np.zeros((4*len(index_array),) + self.target_size+(3,), dtype='float32')
# create array to hold the labels
batch_y = np.zeros(4*len(index_array), dtype='float32')
target_angles = [0, 90, 180, 270]
for i, j in enumerate(index_array):
is_color = int(self.color_mode == 'rgb')
image = cv2.imread(self.filenames[j], is_color)
if is_color:
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
for rotation_angle in target_angles:
rotated_im = rotate(image, rotation_angle, self.target_size[:2])
if self.preprocess_func: rotated_im = self.preprocess_func(rotated_im)
batch_x[i] = rotated_im
batch_y[i] = rotation_angle
batch_y = to_categorical(batch_y, 271)
return batch_x, batch_y
Как видно из кода, я должен использовать 271 в методе to_categorical
.Однако я генерирую только 4 класса.Итак, как я могу присвоить 0,1,2,3 0,90,180 и 270 и использовать 4 вместо 271 в to_categorical
методе?