Keras ImageDataGenerator validation_split - PullRequest
0 голосов
/ 14 марта 2019

Я пытаюсь обучить модель для определения лицевых точек по серии кадров из видео.Поскольку эти кадры имеют почти одинаковую позицию для ключевых точек, модель выдает одинаковые выходные данные для каждого изображения, которое я вставляю для прогнозирования.Я пытался использовать ImageDataGenerator для поворота изображений, чтобы они отличались друг от друга, однако я не могу заставить его работать.

Первоначально, когда я вызываю fit наВ модели, у меня есть возможность разбить данные обучения на поезд и проверку, но я не понимаю, как использовать параметр validation_split в ImageDataGenerator.Может кто-нибудь объяснить, как его использовать, или, может быть, предложить мне способ использования этого класса?

Прямо сейчас у меня есть тензор размера [total_images, width, height, channels] и соответствующий ему [total_images, output].Как использовать ImageDataGenerator для поворота изображений, а также для разделения их на данные обучения и проверки?

1 Ответ

0 голосов
/ 16 марта 2019

Оказалось, я могу создать это сам, используя матрицы преобразования. Чтобы правильно вращать изображения в OpenCV, я использовал этот код (изменил матрицу преобразования, чтобы сохранить все углы изображения при вращении)

Код кредита: Cristian Perez Brokate Вы можете найти объяснение математики этой реализации. rotate_bound точно такой же, как я нашел, rotate_points - это модифицированная версия rotate_box

def rotate_bound(image, angle):
    # grab the dimensions of the image and then determine the
    # center
    (h, w) = image.shape[:2]
    (cX, cY) = (w // 2, h // 2)

    # grab the rotation matrix (applying the negative of the
    # angle to rotate clockwise), then grab the sine and cosine
    # (i.e., the rotation components of the matrix)
    M = cv2.getRotationMatrix2D((cX, cY), -angle, 1.0)
    cos = np.abs(M[0, 0])
    sin = np.abs(M[0, 1])

    # compute the new bounding dimensions of the image
    nW = int((h * sin) + (w * cos))
    nH = int((h * cos) + (w * sin))

    # adjust the rotation matrix to take into account translation
    M[0, 2] += (nW / 2) - cX
    M[1, 2] += (nH / 2) - cY

    # perform the actual rotation and return the image
    return cv2.warpAffine(image, M, (nW, nH))

И чтобы соответственно повернуть координаты точек, я использовал этот код:

def rotate_points(image, points, angle):
        # grab the dimensions of the image and then determine the
    # center
    (h, w) = image.shape[:2]
    (cX, cY) = (w // 2, h // 2)

    # grab the rotation matrix (applying the negative of the
    # angle to rotate clockwise), then grab the sine and cosine
    # (i.e., the rotation components of the matrix)
    M = cv2.getRotationMatrix2D((cX, cY), -angle, 1.0)
    cos = np.abs(M[0, 0])
    sin = np.abs(M[0, 1])

    # compute the new bounding dimensions of the image
    nW = int((h * sin) + (w * cos))
    nH = int((h * cos) + (w * sin))

    # adjust the rotation matrix to take into account translation
    M[0, 2] += (nW / 2) - cX
    M[1, 2] += (nH / 2) - cY

    v = np.ones((points.shape[0], points.shape[1] + 1))
    v[:,:-1] = points
    return np.dot(M, v.T).T
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...