示例#1
0
    def __init__(self, detector, keypoint_estimator, radius=3):
        super(ProbabilisticKeypointPrediction, self).__init__()
        # face detector
        RGB2GRAY = pr.ConvertColorSpace(pr.RGB2GRAY)
        self.detect = pr.Predict(detector, RGB2GRAY, pr.ToBoxes2D(['face']))

        # creating pre-processing pipeline for keypoint estimator
        preprocess = SequentialProcessor()
        preprocess.add(pr.ResizeImage(keypoint_estimator.input_shape[1:3]))
        preprocess.add(pr.ConvertColorSpace(pr.RGB2GRAY))
        preprocess.add(pr.NormalizeImage())
        preprocess.add(pr.ExpandDims(0))
        preprocess.add(pr.ExpandDims(-1))

        # creating post-processing pipeline for keypoint esimtator
        # postprocess = SequentialProcessor()
        # postprocess.add(ToNumpyArray())
        # postprocess.add(pr.Squeeze(1))

        # keypoint estimator predictions
        self.estimate_keypoints = PredictMeanDistribution(
            keypoint_estimator, preprocess)

        # self.estimate_keypoints = pr.Predict(
        # keypoint_estimator, preprocess, postprocess)

        # used for drawing up keypoints in original image
        self.change_coordinates = pr.ChangeKeypointsCoordinateSystem()
        self.denormalize_keypoints = pr.DenormalizeKeypoints()
        self.crop_boxes2D = pr.CropBoxes2D()
        self.num_keypoints = len(keypoint_estimator.output_shape)
        self.draw = pr.DrawKeypoints2D(self.num_keypoints, radius, False)
        self.draw_boxes2D = pr.DrawBoxes2D(['face'], colors=[[0, 255, 0]])
        self.wrap = pr.WrapOutput(['image', 'boxes2D'])
示例#2
0
    def __init__(self,
                 prior_boxes,
                 split=pr.TRAIN,
                 num_classes=21,
                 size=300,
                 mean=pr.BGR_IMAGENET_MEAN,
                 IOU=.5,
                 variances=[0.1, 0.1, 0.2, 0.2]):
        super(AugmentDetection, self).__init__()

        # image processors
        self.augment_image = AugmentImage()
        self.augment_image.add(pr.ConvertColorSpace(pr.RGB2BGR))
        self.preprocess_image = PreprocessImage((size, size), mean)

        # box processors
        self.augment_boxes = AugmentBoxes()
        args = (num_classes, prior_boxes, IOU, variances)
        self.preprocess_boxes = PreprocessBoxes(*args)

        # pipeline
        self.add(pr.UnpackDictionary(['image', 'boxes']))
        self.add(pr.ControlMap(pr.LoadImage(), [0], [0]))
        if split == pr.TRAIN:
            self.add(pr.ControlMap(self.augment_image, [0], [0]))
            self.add(pr.ControlMap(self.augment_boxes, [0, 1], [0, 1]))
        self.add(pr.ControlMap(self.preprocess_image, [0], [0]))
        self.add(pr.ControlMap(self.preprocess_boxes, [1], [1]))
        self.add(
            pr.SequenceWrapper({0: {
                'image': [size, size, 3]
            }}, {1: {
                'boxes': [len(prior_boxes), 4 + num_classes]
            }}))
示例#3
0
 def __init__(self, renderer, image_paths, num_occlusions, split=pr.TRAIN):
     super(DomainRandomizationProcessor, self).__init__()
     self.copy = pr.Copy()
     self.render = pr.Render(renderer)
     self.augment = RandomizeRenderedImage(image_paths, num_occlusions)
     preprocessors = [pr.ConvertColorSpace(pr.RGB2BGR), pr.NormalizeImage()]
     self.preprocess = SequentialProcessor(preprocessors)
     self.split = split
示例#4
0
文件: pipelines.py 项目: oarriaga/paz
 def __init__(self, shape, bkg_paths, mean=pr.BGR_IMAGENET_MEAN):
     super(AugmentImage, self).__init__()
     # self.add(LoadImage(4))
     self.add(pr.ResizeImage(shape))
     self.add(pr.BlendRandomCroppedBackground(bkg_paths))
     self.add(pr.RandomContrast())
     self.add(pr.RandomBrightness())
     self.add(pr.RandomSaturation(0.7))
     self.add(pr.RandomHue())
     self.add(pr.ConvertColorSpace(pr.RGB2BGR))
示例#5
0
文件: pipelines.py 项目: oarriaga/paz
 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)
示例#6
0
 def __init__(self, model_names):
     super(HaarCascadeDetectors, self).__init__()
     self.model_names = model_names
     self.detectors = []
     for class_arg, model_name in enumerate(self.model_names):
         detector = pr.Predict(HaarCascadeDetector(model_name, class_arg),
                               pr.ConvertColorSpace(pr.RGB2GRAY),
                               pr.ToBoxes2D(args.models))
         self.detectors.append(detector)
     self.draw_boxes2D = pr.DrawBoxes2D(args.models)
     self.wrap = pr.WrapOutput(['image', 'boxes2D'])
示例#7
0
 def __init__(self, model, draw=True):
     super(GMMKeypoints, self).__init__()
     self.num_keypoints = len(model.output_shape)
     preprocess = SequentialProcessor()
     preprocess.add(pr.ResizeImage(model.input_shape[1:3]))
     preprocess.add(pr.ConvertColorSpace(pr.RGB2GRAY))
     preprocess.add(pr.NormalizeImage())
     preprocess.add(pr.ExpandDims(0))
     preprocess.add(pr.ExpandDims(-1))
     self.estimate_keypoints = PredictDistributions(model, preprocess)
     self.to_grid = ToProbabilityGrid(GRID)
     self.draw = draw
     self.draw_probabilities = DrawProbabilities(self.num_keypoints)
     self.wrap = pr.WrapOutput(['image', 'probabilities', 'distributions'])
示例#8
0
文件: demo.py 项目: niqbal996/paz
 def __init__(self, model, colors=None):
     super(PostprocessSegmentation, self).__init__()
     self.add(pr.UnpackDictionary(['image_path']))
     self.add(pr.LoadImage())
     self.add(pr.ResizeImage(model.input_shape[1:3]))
     self.add(pr.ConvertColorSpace(pr.RGB2BGR))
     self.add(pr.SubtractMeanImage(pr.BGR_IMAGENET_MEAN))
     self.add(pr.ExpandDims(0))
     self.add(pr.Predict(model))
     self.add(pr.Squeeze(0))
     self.add(Round())
     self.add(MasksToColors(model.output_shape[-1], colors))
     self.add(pr.DenormalizeImage())
     self.add(pr.CastImage('uint8'))
     self.add(pr.ShowImage())
示例#9
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]}}))
示例#10
0
 def __init__(self, mean=pr.BGR_IMAGENET_MEAN):
     super(PreprocessImage, self).__init__()
     self.add(pr.ConvertColorSpace(pr.RGB2BGR))
     self.add(pr.SubtractMeanImage(mean))
示例#11
0
 def __init__(self):
     super(PostProcessImage, self).__init__()
     self.add(pr.AddMeanImage(pr.BGR_IMAGENET_MEAN))
     self.add(pr.CastImage('uint8'))
     self.add(pr.ConvertColorSpace(pr.BGR2RGB))