Beispiel #1
0
    def __init__(self, size, image_size, crop_size, variance):
        super(ExtractHandPose, self).__init__()
        self.unwrap_inputs = pr.UnpackDictionary(
            ['image', 'segmentation_label', 'annotations'])
        self.preprocess_image = pr.SequentialProcessor(
            [pr.LoadImage(), pr.ResizeImage((size, size))])

        self.preprocess_segmentation_map = pr.SequentialProcessor(
            [pr.LoadImage(),
             pr.ResizeImage((size, size)),
             ExtractHandmask()])

        self.extract_annotations = pr.UnpackDictionary(['xyz', 'uv_vis', 'K'])
        self.extract_2D_keypoints = Extract2DKeypoints()
        self.keypoints_to_palm = KeypointstoPalmFrame()
        self.visibility_to_palm = TransformVisibilityMask()
        self.extract_hand_side = ExtractHandsideandKeypoints()
        self.to_one_hot = ToOneHot(num_classes=2)
        self.normaliza_keypoints = NormalizeKeypoints()
        self.to_relative_frame = TransformtoRelativeFrame()
        self.canonical_transformations = GetCanonicalTransformation()
        self.flip_right_hand = FlipRightHandToLeftHand()
        self.get_matrix_inverse = CalculatePseudoInverse()

        self.extract_hand_visibility = ExtractDominantHandVisibility()
        self.extract_dominant_keypoints = ExtractDominantKeypoints2D()

        self.crop_image_from_mask = CropImageFromMask()
        self.create_scoremaps = CreateScoremaps(image_size=image_size,
                                                crop_size=crop_size,
                                                variance=variance)

        self.wrap = pr.WrapOutput(
            ['score_maps', 'hand_side', 'keypoints3D', 'rotation_matrix'])
Beispiel #2
0
    def __init__(self, image_shape, num_classes, input_name='input_1', dataset='CityScapes'):
        super(PreprocessSegmentationIds, self).__init__()
        self.add(pr.UnpackDictionary(['image_path', 'label_path']))
        preprocess_image = pr.SequentialProcessor()
        preprocess_image.add(pr.LoadImage())
        preprocess_image.add(pr.ResizeImage(image_shape))
        preprocess_image.add(pr.ConvertColorSpace(pr.RGB2BGR))
        preprocess_image.add(pr.SubtractMeanImage(pr.BGR_IMAGENET_MEAN))

        preprocess_label = pr.SequentialProcessor()
        preprocess_label.add(pr.LoadImage())
        preprocess_label.add(ResizeImageWithNearestNeighbors(image_shape))
        preprocess_label.add(FromIdToMask(dataset))

        self.add(pr.ControlMap(preprocess_image, [0], [0]))
        self.add(pr.ControlMap(preprocess_label, [1], [1]))
        H, W = image_shape[:2]
        self.add(pr.SequenceWrapper({0: {input_name: [H, W, 3]}},
                                    {1: {'masks': [H, W, num_classes]}}))
Beispiel #3
0
 def __init__(self, base, mean_face, shape=(48, 48), with_crop=True):
     super(CalculateFaceWeights, self).__init__()
     self.base, self.mean_face = base, mean_face
     self.preprocess = pr.SequentialProcessor()
     self.convert_to_gray = pr.ConvertColorSpace(pr.RGB2GRAY)
     if with_crop:
         self.preprocess.add(pe.CropFrontalFace())
     self.preprocess.add(pr.ResizeImage(shape))
     self.preprocess.add(pr.ExpandDims(-1))
     self.subtract = pe.SubtractMeanFace()
     self.project = pe.ProjectToBase(self.base)
Beispiel #4
0
 def __init__(self,
              model,
              flipped_keypoint_order,
              with_flip,
              data_with_center,
              scale_output=True,
              axes=[0, 3, 1, 2]):
     super(GetHeatmapsAndTags, self).__init__()
     self.with_flip = with_flip
     self.predict = pr.SequentialProcessor(
         [pr.Predict(model),
          pr.TransposeOutput(axes),
          pr.ScaleOutput(2)])
     self.get_heatmaps = pr.GetHeatmaps(flipped_keypoint_order)
     self.get_tags = pr.GetTags(flipped_keypoint_order)
     self.postprocess = pr.SequentialProcessor()
     if data_with_center:
         self.postprocess.add(pr.RemoveLastElement())
     if scale_output:
         self.postprocess.add(pr.ScaleOutput(2, full_scaling=True))
Beispiel #5
0
    def __init__(self, size=320):
        super(ExtractHandSegmentation, self).__init__()
        self.add(
            pr.UnpackDictionary(['image', 'segmentation_label',
                                 'annotations']))

        preprocess_image = pr.SequentialProcessor(
            [pr.LoadImage(), pr.ResizeImage((size, size))])

        preprocess_segmentation_map = pr.SequentialProcessor(
            [pr.LoadImage(),
             pr.ResizeImage((size, size)),
             ExtractHandmask()])

        self.add(pr.ControlMap(preprocess_image, [0], [0]))
        self.add(pr.ControlMap(preprocess_segmentation_map, [1], [1]))
        self.add(
            pr.SequenceWrapper({0: {
                'image': [size, size, 3]
            }}, {1: {
                'hand_mask': [size, size]
            }}))
Beispiel #6
0
 def __init__(self,
              right_hand=False,
              input_config=MANOHandJoints,
              output_config=MPIIHandJoints):
     super(CalculateRelativeAngles, self).__init__()
     output_labels = output_config.labels
     origin_labels = input_config.labels
     links_origin = input_config.links_origin
     self.parents = input_config.parents
     self.children = output_config.children
     if right_hand:
         links_origin = flip_along_x_axis(links_origin)
     self.links_orientation = compute_orientation_vector(
         links_origin, self.parents)
     self.quaternions_to_rotations = pr.SequentialProcessor([
         pr.ChangeLinkOrder(output_labels, origin_labels),
         quaternions_to_rotation_matrices
     ])
     self.calculate_relative_angle = pr.SequentialProcessor([
         calculate_relative_angle,
         pr.ChangeLinkOrder(origin_labels, output_labels)
     ])
Beispiel #7
0
    def __init__(self, size, image_size, crop_size, variance):
        super(ExtractHandPose2D, self).__init__()
        self.unwrap_inputs = pr.UnpackDictionary(
            ['image', 'segmentation_label', 'annotations'])
        self.preprocess_image = pr.SequentialProcessor(
            [pr.LoadImage(), pr.ResizeImage((size, size))])

        self.preprocess_segmentation_map = pr.SequentialProcessor(
            [pr.LoadImage(),
             pr.ResizeImage((size, size)),
             ExtractHandmask()])
        self.extract_annotations = pr.UnpackDictionary(['xyz', 'uv_vis', 'K'])
        self.extract_2D_keypoints = Extract2DKeypoints()
        self.keypoints_to_palm = KeypointstoPalmFrame()
        self.visibility_to_palm = TransformVisibilityMask()
        self.extract_hand_side = ExtractHandsideandKeypoints()

        self.extract_visibility_dominant_hand = ExtractDominantHandVisibility()
        self.create_scoremaps = CreateScoremaps(image_size, crop_size,
                                                variance)
        self.crop_image_from_mask = CropImageFromMask()
        self.wrap = pr.WrapOutput(
            ['cropped_image', 'score_maps', 'keypoints_vis21'])
Beispiel #8
0
 def __init__(self, links_origin=MPIIHandJoints.links_origin,
              parents=MPIIHandJoints.parents, right_hand=False):
     super(IKNetHandJointAngles, self).__init__()
     self.calculate_orientation = pr.ComputeOrientationVector(parents)
     self.links_origin = links_origin
     self.right_hand = right_hand
     if self.right_hand:
         self.links_origin = flip_along_x_axis(self.links_origin)
     self.links_delta = self.calculate_orientation(self.links_origin)
     self.concatenate = pr.Concatenate(0)
     self.compute_absolute_angles = pr.SequentialProcessor(
         [pr.ExpandDims(0), IKNet(), pr.Squeeze(0)])
     self.compute_relative_angles = pr.CalculateRelativeAngles()
     self.wrap = pr.WrapOutput(['absolute_angles', 'relative_angles'])