def compute_cord_warp(source_pose_loc,
                      target_pose_loc,
                      _warp_skip='mask',
                      _image_size=(256, 192),
                      pose_dim=16):

    _image_size = (256, 192)
    if _warp_skip == 'full':
        # warp = [np.empty([1, pose_dim-10]), 1]
        warp = [np.empty([1, 8]), 1]
    else:
        # warp = [np.empty([10, pose_dim-10]),
        #         np.empty([10] + list(_image_size))]
        warp = [np.empty([10, 8]), np.empty([10] + list(_image_size))]

    kp_array1 = source_pose_loc
    kp_array2 = target_pose_loc

    if _warp_skip == 'mask':
        warp[0] = pose_transform.affine_transforms(kp_array1, kp_array2,
                                                   pose_dim)
        warp[1] = pose_transform.pose_masks(kp_array2, _image_size, pose_dim)
    else:
        warp[0] = pose_transform.estimate_uniform_transform(
            kp_array1, kp_array2, pose_dim)
    return warp
def compute_interpol_cord_warp(inp_map, interpol_pose):
    interpol_pose = [inp_map] + interpol_pose
    num_interpol = len(interpol_pose)
    interpol_warps, interpol_masks = [], []
    _warp_skip = 'mask'
    pose_dim = 18
    _image_size = (256, 192)
    # possibly causing nan error
    kp_array1 = map_to_cord(inp_map, pose_dim)

    for pose in interpol_pose:
        if _warp_skip == 'full':
            warp = [np.empty([1, 8]), 1]
        else:
            warp = [np.empty([10, 8]), np.empty([10] + list(_image_size))]
        kp_array2 = map_to_cord(pose, pose_dim)

        if _warp_skip == 'mask':
            warp[0] = pose_transform.affine_transforms(kp_array1, kp_array2,
                                                       pose_dim)
            warp[1] = pose_transform.pose_masks(kp_array2, _image_size,
                                                pose_dim)
        else:
            warp[0] = pose_transform.estimate_uniform_transform(
                kp_array1, kp_array2, pose_dim)
        interpol_warps.append(warp[0])
        interpol_masks.append(warp[1])

        kp_array1 = kp_array2

    return np.array(interpol_warps), np.array(interpol_masks)
示例#3
0
 def compute_interpol_cord_warp(self, inp_map, interpol_pose):
     interpol_pose = [inp_map] + interpol_pose
     num_interpol = len(interpol_pose)
     interpol_warps, interpol_masks = [], []
     # possibly causing nan error
     kp_array1 = pose_utils.map_to_cord(np.transpose(inp_map, [1, 2, 0]),
                                        self.pose_dim)
     for pose in interpol_pose:
         if self._warp_skip == 'full':
             warp = [np.empty([1, 8]), 1]
         else:
             warp = [
                 np.empty([10, 8]),
                 np.empty([10] + list(self._image_size))
             ]
         kp_array2 = pose_utils.map_to_cord(np.transpose(pose, [1, 2, 0]),
                                            self.pose_dim)
         if self._warp_skip == 'mask':
             warp[0] = pose_transform.affine_transforms(
                 kp_array1, kp_array2, self.pose_dim)
             warp[1] = pose_transform.pose_masks(kp_array2,
                                                 self._image_size,
                                                 self.pose_dim)
         else:
             warp[0] = pose_transform.estimate_uniform_transform(
                 kp_array1, kp_array2, self.pose_dim)
         interpol_warps.append(warp[0])
         interpol_masks.append(warp[1])
         kp_array1 = kp_array2
     return np.array(interpol_warps), np.array(interpol_masks)
示例#4
0
 def compute_cord_warp(self, pair):
     if self._warp_skip == 'full':
         warp = [np.empty([1, 8])]
     else:
         warp = [np.empty([10, 8]), np.empty([10] + list(self._image_size))]
     fr = self._annotations_file.loc[p['from']]
     to = self._annotations_file.loc[p['to']]
     kp_array1 = pose_utils.load_pose_cords_from_strings(
         fr['keypoints_y'], fr['keypoints_x'])
     kp_array2 = pose_utils.load_pose_cords_from_strings(
         to['keypoints_y'], to['keypoints_x'])
     if self._warp_skip == 'mask':
         warp[0] = pose_transform.affine_transforms(kp_array1, kp_array2)
         warp[1] = pose_transform.pose_masks(kp_array2, self._image_size)
     else:
         warp[0] = pose_transform.estimate_uniform_transform(
             kp_array1, kp_array2)
     return warp
示例#5
0
    def compute_cord_warp_batch(self, pair_data):
        if self._use_warp == 'full':
            warp = [np.empty([self._batch_size] + [1, 8])]
        elif self._use_warp == 'mask':
            warp = [
                np.empty([self._batch_size] + [10, 8]),
                np.empty([self._batch_size, 10] + list(self._im_size))
            ]
        elif self._use_warp == 'stn':
            warp = [np.empty([self._batch_size] + [72])]
        else:
            return []

        for i, p in enumerate(pair_data):

            pairs = p.split(',')
            from_d = '_'.join(pairs[0].split('/'))
            to_d = '_'.join(pairs[1].split('/'))

            from_row = self._annotations_file.loc[from_d]
            to_row = self._annotations_file.loc[to_d]

            from_pose_corordinates = pose_utils.load_pose_cords_from_strings(
                from_row['keypoints_y'], from_row['keypoints_x'])
            to_pose_corordinates = pose_utils.load_pose_cords_from_strings(
                to_row['keypoints_y'], to_row['keypoints_x'])

            if self._use_warp == 'mask':
                warp[0][i] = pose_transform.affine_transforms(
                    from_pose_corordinates, to_pose_corordinates)
                warp[1][i] = pose_transform.pose_masks(to_pose_corordinates,
                                                       self._im_size)
            elif self._use_warp == 'full':
                warp[0][i] = pose_transform.estimate_uniform_transform(
                    from_pose_corordinates, to_pose_corordinates)
            else:  # sel._use_warp == 'stn'
                warp[0][i][:36] = from_pose_corordinates.reshape((-1, ))
                warp[0][i][36:] = to_pose_corordinates.reshape((-1, ))
        return warp