Я следую этому учебнику о увеличении данных для этого набора данных
о обнаружении лицевых ключевых точек (обозначается (x, y) координатами цели).
Я хочу перевернуть изображения по горизонтали, поэтому некоторые цели необходимо поменять местами следующим образом:
left_eye_center_x --------->> right_eye_center_x
left_eye_center_y --------->> right_eye_center_y
left_eye_inner_corner_x --------->> right_eye_inner_corner_x
left_eye_inner_corner_y --------->> right_eye_inner_corner_y
...
Переворачивание изображения и переупорядочение координат кажутся хорошими при печати , но не при печати .
Код:
# target indices to swap
flip_indices = [(0, 2), (1, 3),(4, 8), (5, 9), (6, 10), (7, 11), (12, 16),
(13, 17), (14, 18), (15, 19),(22, 24), (23, 25)]
# permutation that represents the target coordinates reordering
permutation = [2, 3, 0, 1, 8, 9, 10, 11, 4, 5,
6, 7 ,16, 17, 18, 19, 12, 13, 14, 15,
20, 21, 24, 25, 22, 23, 26, 27, 28, 29]
X_train_flipped = np.flip(X_train, axis=2) # flips images horizontally
Y_train_flipped = np.copy(Y_train)[:,permutation] # flips targets according to permutation
print (Y_train[1,permutation] == Y_train_flipped[1]) # permutation seems successful
fig = plt.figure(figsize=(10, 10))
# original image, original targets
ax = fig.add_subplot(1, 3, 1, xticks=[], yticks=[])
plot_sample(X_train[1], Y_train[1], ax)
# flipped image, original targets
ax = fig.add_subplot(1, 3, 2, xticks=[], yticks=[])
plot_sample(X_train_flipped[1], Y_train[1], ax)
# flipped image, flipped targets
ax = fig.add_subplot(1, 3, 3, xticks=[], yticks=[])
plot_sample(X_train_flipped[1], Y_train_flipped[1], ax)
Выход:
[ True True ... True True]
На третьем рисунке должны быть правильно расположены цели.

Функция plot_sample()
определена в руководстве следующим образом:
def plot_sample(x, y, axis):
img = x.reshape(96, 96)
axis.imshow(img, cmap='gray')
axis.scatter(y[0::2] * 48 + 48, y[1::2] * 48 + 48, marker='x', s=10)