Synthetically transformed pairs dataset for training with strong supervision Args: csv_file (string): Path to the csv file with image names and transformations. training_image_path (string): Directory with all the images. transform (callable): Transformat
| 660 | return torch.cat((points_X_prime, points_Y_prime), 3) |
| 661 | |
| 662 | class Theta_gen(): |
| 663 | """ |
| 664 | Synthetically transformed pairs dataset for training with strong supervision |
| 665 | Args: |
| 666 | csv_file (string): Path to the csv file with image names and transformations. |
| 667 | training_image_path (string): Directory with all the images. |
| 668 | transform (callable): Transformation for post-processing the training pair (eg. image normalization) |
| 669 | Returns: |
| 670 | Dict: {'image': full dataset image, 'theta': desired transformation} |
| 671 | """ |
| 672 | |
| 673 | def __init__(self, |
| 674 | output_size=(480, 640), |
| 675 | geometric_model='affine', |
| 676 | random_t=0.5, |
| 677 | random_s=0.5, |
| 678 | random_alpha=1 / 6, |
| 679 | random_t_tps=0.5, |
| 680 | four_point_hom=True): |
| 681 | |
| 682 | self.out_h, self.out_w = output_size |
| 683 | self.random_t = random_t |
| 684 | self.random_t_tps = random_t_tps |
| 685 | self.random_alpha = random_alpha |
| 686 | self.random_s = random_s |
| 687 | self.four_point_hom = four_point_hom |
| 688 | self.geometric_model = geometric_model |
| 689 | self.affineTnf = GeometricTnf(out_h=self.out_h, out_w=self.out_w, use_cuda=False) |
| 690 | |
| 691 | |
| 692 | def __call__(self): |
| 693 | # np.random.seed(1) # for debugging purposes |
| 694 | |
| 695 | if self.geometric_model == 'affine' or self.geometric_model == 'afftps': |
| 696 | ''' |
| 697 | rotate: -pi/6 ~ pi/6 |
| 698 | shear: -pi/6 ~ pi/6 |
| 699 | translation: -0.25 ~ 0.25 |
| 700 | lambda: 0.75 ~ 1.25 |
| 701 | ''' |
| 702 | rot_angle = (np.random.rand(1) - 0.5) * 2 * np.pi / 3 # between -np.pi/12 and np.pi/12 |
| 703 | sh_angle = (np.random.rand(1) - 0.5) * 2 * np.pi / 2 # between -np.pi/6 and np.pi/6 |
| 704 | lambda_1 = 1 + (2 * np.random.rand(1) - 1) * 0.2 # between 0.75 and 1.25 |
| 705 | lambda_2 = 1 + (2 * np.random.rand(1) - 1) * 0.2 # between 0.75 and 1.25 |
| 706 | tx = (2 * np.random.rand(1) - 1) * 0.75 # between -0.25 and 0.25 |
| 707 | ty = (2 * np.random.rand(1) - 1) * 0.75 |
| 708 | |
| 709 | R_sh = np.array([[np.cos(sh_angle[0]), -np.sin(sh_angle[0])], |
| 710 | [np.sin(sh_angle[0]), np.cos(sh_angle[0])]]) |
| 711 | R_alpha = np.array([[np.cos(rot_angle[0]), -np.sin(rot_angle[0])], |
| 712 | [np.sin(rot_angle[0]), np.cos(rot_angle[0])]]) |
| 713 | |
| 714 | D = np.diag([lambda_1[0], lambda_2[0]]) |
| 715 | |
| 716 | A = R_alpha @ R_sh.transpose() @ D @ R_sh |
| 717 | |
| 718 | theta_aff = np.array([A[0, 0], A[0, 1], tx, A[1, 0], A[1, 1], ty],np.float32) |
| 719 | if self.geometric_model == 'hom': |