microsoft / SoftTeacher

Semi-Supervised Learning, Object Detection, ICCV2021
MIT License
899 stars 123 forks source link

question about agumentations #71

Closed songbae closed 2 years ago

songbae commented 2 years ago

using geometry augmentations , in repo u have to save the trans_matrix

Q1. in augementation does rotate and shift can be adapted at same time?

[ cos@ , -sin@ , shift_x]
[sin@, cos@ , shfit_y ]
[0,        0,                   1]

if i make this trans_matrix does it mean rotate for @ and shift (x,y) ? it's confusing because when i use cv2.warpAffine
it rotates the img by not center but by left-top .

MendelXu commented 2 years ago

Yes. It can be adopted at the same time. However, the rotation augmentation can not be simply interpreted as just

[ cos@ , -sin@ ,0]
[sin@, cos@ , 0]
[0,        0,  1]

See https://github.com/microsoft/SoftTeacher/blob/5dcbd98cb29acfea6e4da9dd72121c952cb857f4/ssod/datasets/pipelines/rand_aug.py#L488 What it really do is

  1. Translate the coordinates to the center of the image
  2. Rotate the image by selected angle
  3. Translate the coordinates to the left top of the image.

So the rotation matrix is

  alpha=cos@
  beta=sin@
  center = (w/2,h/2)
  rotation_matrix=[alpha, beta, (1 - alpha) * center[0] - beta * center[1]],
                 [-beta, alpha, beta * center[0] + (1 - alpha) * center[1]],
                 [0, 0, 1],

Maybe you have referred to https://github.com/microsoft/SoftTeacher/blob/5dcbd98cb29acfea6e4da9dd72121c952cb857f4/ssod/datasets/pipelines/geo_utils.py#L35, but I have to say it is wrong... I am sorry to have forgot to delete it.

songbae commented 2 years ago

Yes. It can be adopted at the same time. However, the rotation augmentation can not be simply interpreted as just

[ cos@ , -sin@ ,0]
[sin@, cos@ , 0]
[0,        0,  1]

See

https://github.com/microsoft/SoftTeacher/blob/5dcbd98cb29acfea6e4da9dd72121c952cb857f4/ssod/datasets/pipelines/rand_aug.py#L488

What it really do is

  1. Translate the coordinates to the center of the image
  2. Rotate the image by selected angle
  3. Translate the coordinates to the left top of the image.

So the rotation matrix is

  alpha=cos@
  beta=sin@
  center = (w/2,h/2)
  rotation_matrix=[alpha, beta, (1 - alpha) * center[0] - beta * center[1]],
                 [-beta, alpha, beta * center[0] + (1 - alpha) * center[1]],
                 [0, 0, 1],

Maybe you have referred to

https://github.com/microsoft/SoftTeacher/blob/5dcbd98cb29acfea6e4da9dd72121c952cb857f4/ssod/datasets/pipelines/geo_utils.py#L35

, but I have to say it is wrong... I am sorry to have forgot to delete it.

yeah , i was wondering about that "def _get_rotate_metrix " from the code it's just simply implemented by just

[ cos@ , -sin@ ,0]
[sin@, cos@ , 0]
[0,        0,  1]

so the right trans_matrix be the

M=cv2.cv2.getRotationMatrix2D(center, -angle, self.scale)
M= [alpha, beta, (1 - alpha) * center[0] - beta * center[1]],
                 [-beta, alpha, beta * center[0] + (1 - alpha) * center[1]]

right?

MendelXu commented 2 years ago

Yes.

M=cv2.cv2.getRotationMatrix2D(center, -angle, self.scale)

or

M= [alpha, beta, (1 - alpha) * center[0] - beta * center[1]],
                 [-beta, alpha, beta * center[0] + (1 - alpha) * center[1]]