Ejemplo n.º 1
0
    def setUp(self):
        n_bbox = 8
        feat_size = (self.img_size[0] // 16, self.img_size[1] // 16)
        self.n_anchor = self.n_anchor_base * np.prod(feat_size)

        self.anchor = generate_random_bbox(
            self.n_anchor, self.img_size, 16, 200)
        self.bbox = generate_random_bbox(n_bbox, self.img_size, 16, 200)
        self.anchor_target_layer = AnchorTargetCreator(
            self.n_sample, pos_ratio=self.pos_ratio,
        )
Ejemplo n.º 2
0
    def setUp(self):
        n_bbox = 8
        feat_size = (self.img_size[0] // 16, self.img_size[1] // 16)
        self.n_anchor = self.n_anchor_base * np.prod(feat_size)

        self.anchor = generate_random_bbox(self.n_anchor, self.img_size, 16,
                                           200)
        self.bbox = generate_random_bbox(n_bbox, self.img_size, 16, 200)
        self.anchor_target_layer = AnchorTargetCreator(
            self.n_sample,
            pos_ratio=self.pos_ratio,
        )
    def setUp(self):

        n_roi = 1024
        n_bbox = 10
        self.roi = generate_random_bbox(n_roi, (392, 512), 16, 250)
        self.bbox = generate_random_bbox(n_bbox, (392, 512), 16, 250)
        self.label = np.random.randint(
            0, self.n_class - 1, size=(n_bbox,), dtype=np.int32)

        self.proposal_target_creator = ProposalTargetCreator(
            n_sample=self.n_sample,
            pos_ratio=self.pos_ratio,
        )
    def setUp(self):

        self.roi = generate_random_bbox(self.n_roi, (392, 512), 16, 250)
        self.bbox = generate_random_bbox(self.n_bbox, (392, 512), 16, 250)
        self.label = np.random.randint(0,
                                       self.n_class - 1,
                                       size=(self.n_bbox, ),
                                       dtype=np.int32)

        self.proposal_target_creator = ProposalTargetCreator(
            n_sample=self.n_sample,
            pos_ratio=self.pos_ratio,
        )
Ejemplo n.º 5
0
    def __call__(self, x, img_size, scale):
        B, _, H, W = x.shape
        n_anchor = self.n_anchor_base * H * W

        rpn_locs = _random_array(self.xp, (B, n_anchor, 4))
        rpn_cls_scores = _random_array(self.xp, (B, n_anchor, 2))
        rois = self.xp.asarray(
            generate_random_bbox(self.n_roi, img_size, 16, min(img_size)))
        roi_indices = self.xp.zeros((len(rois), ), dtype=np.int32)
        anchor = self.xp.asarray(
            generate_random_bbox(n_anchor, img_size, 16, min(img_size)))
        return (chainer.Variable(rpn_locs), chainer.Variable(rpn_cls_scores),
                rois, roi_indices, anchor)
Ejemplo n.º 6
0
    def __call__(self, x, img_size, scale):
        B, _, H, W = x.shape
        n_anchor = self.n_anchor_base * H * W

        rpn_locs = _random_array(self.xp, (B, n_anchor, 4))
        rpn_cls_scores = _random_array(self.xp, (B, n_anchor, 2))
        rois = self.xp.asarray(generate_random_bbox(
            self.n_roi, img_size, 16, min(img_size)))
        roi_indices = self.xp.zeros((len(rois),), dtype=np.int32)
        anchor = self.xp.asarray(generate_random_bbox(
            n_anchor, img_size, 16, min(img_size)))
        return (chainer.Variable(rpn_locs),
                chainer.Variable(rpn_cls_scores), rois, roi_indices, anchor)
Ejemplo n.º 7
0
    def setUp(self):
        self.n_anchor_base = 6
        self.feat_stride = 4
        self.n_fg_class = 3
        self.n_roi = 24
        self.n_bbox = 3
        self.model = LightHeadRCNNTrainChain(
            DummyLightHeadRCNN(
                n_anchor_base=self.n_anchor_base,
                feat_stride=self.feat_stride,
                n_fg_class=self.n_fg_class,
                n_roi=self.n_roi,
                min_size=600,
                max_size=800,
                loc_normalize_mean=(0., 0., 0., 0.),
                loc_normalize_std=(0.1, 0.1, 0.2, 0.2),
            ))

        self.bboxes = generate_random_bbox(self.n_bbox, (600, 800), 16,
                                           350)[np.newaxis]
        self.labels = np.random.randint(0,
                                        self.n_fg_class,
                                        size=(1, self.n_bbox)).astype(np.int32)
        self.imgs = _random_array((1, 3, 600, 800))
        self.scales = np.array([1.])
Ejemplo n.º 8
0
    def test_random_crop_with_bbox_constraints(self):
        img = np.random.randint(0, 256, size=(3, 480, 640)).astype(np.float32)
        bbox = generate_random_bbox(10, img.shape[1:], 0.1, 0.9)

        out, param = random_crop_with_bbox_constraints(img,
                                                       bbox,
                                                       min_scale=0.3,
                                                       max_scale=1,
                                                       max_aspect_ratio=2,
                                                       return_param=True)

        if param['constraint'] is None:
            np.testing.assert_equal(out, img)
        else:
            np.testing.assert_equal(out, img[:, param['y_slice'],
                                             param['x_slice']])

            self.assertGreaterEqual(out.size, img.size * 0.3 * 0.3)
            self.assertLessEqual(out.size, img.size * 1 * 1)

            # to ignore rounding error, add 1
            self.assertLessEqual(out.shape[1] / (out.shape[2] + 1),
                                 img.shape[1] / img.shape[2] * 2)
            self.assertLessEqual(out.shape[2] / (out.shape[1] + 1),
                                 img.shape[2] / img.shape[1] * 2)

            bb = np.array((param['y_slice'].start, param['x_slice'].start,
                           param['y_slice'].stop, param['x_slice'].stop))
            iou = bbox_iou(bb[np.newaxis], bbox)
            min_iou, max_iou = param['constraint']
            if min_iou:
                self.assertGreaterEqual(iou.min(), min_iou)
            if max_iou:
                self.assertLessEqual(iou.max(), max_iou)
Ejemplo n.º 9
0
 def setUp(self):
     self.img = np.random.randint(0, 255, size=(3, 32, 48))
     self.bbox = generate_random_bbox(self.n_bbox, (48, 32), 8, 16)
     if self.label is not None:
         self.label = np.array(self.label, dtype=int)
     if self.score is not None:
         self.score = np.array(self.score)
Ejemplo n.º 10
0
    def get_example(self, i):
        img = np.random.randint(0, 256, size=(3, 48, 64))
        n_bbox = np.random.randint(10, 20)
        bbox = generate_random_bbox(n_bbox, (48, 64), 5, 20)
        label = np.random.randint(0, 20, size=n_bbox).astype(np.int32)

        return (img, bbox, label) + self.options
Ejemplo n.º 11
0
    def test_non_maximum_suppression_consistency(self):
        bbox = generate_random_bbox(6000, (600, 800), 32, 512)

        cpu_selec = non_maximum_suppression(bbox, 0.5)
        gpu_selec = non_maximum_suppression(cuda.to_gpu(bbox), 0.5)

        np.testing.assert_equal(cpu_selec, cuda.to_cpu(gpu_selec))
Ejemplo n.º 12
0
    def test_non_maximum_suppression_consistency(self):
        bbox = generate_random_bbox(6000, (600, 800), 32, 512)

        cpu_selec = non_maximum_suppression(bbox, 0.5)
        gpu_selec = non_maximum_suppression(cuda.to_gpu(bbox), 0.5)

        np.testing.assert_equal(cpu_selec, cuda.to_cpu(gpu_selec))
    def setUp(self):
        self.comm = create_communicator('naive')

        batchsize_per_process = 5
        batchsize = batchsize_per_process * self.comm.size
        if self.comm.rank == 0:
            bboxes = [
                generate_random_bbox(5, (256, 324), 24, 120) for _ in range(10)
            ]
            labels = [
                np.random.choice(np.arange(3, dtype=np.int32), size=(5, ))
                for _ in range(10)
            ]
        else:
            bboxes = None
            labels = None
        initial_count = self.comm.rank * batchsize_per_process

        bboxes = self.comm.bcast_obj(bboxes)
        labels = self.comm.bcast_obj(labels)
        self.bboxes = bboxes
        self.labels = labels

        self.dataset = TupleDataset(np.random.uniform(size=(10, 3, 32, 48)),
                                    bboxes, labels)
        self.initial_count = initial_count
        self.batchsize = batchsize
    def get_example(self, i):
        img = np.random.randint(0, 256, size=(3, 48, 64))
        n_bbox = np.random.randint(10, 20)
        mask = np.random.randint(0, 2, size=(n_bbox, 48, 64), dtype=np.bool)
        bbox = generate_random_bbox(n_bbox, (48, 64), 5, 20)
        label = np.random.randint(0, 20, size=n_bbox).astype(np.int32)

        return (img, bbox, mask, label) + self.options
Ejemplo n.º 15
0
 def setUp(self):
     self.img = np.random.randint(0, 255, size=(3, 32, 48))
     self.bbox = generate_random_bbox(
         self.n_bbox, (48, 32), 8, 16)
     if self.label is not None:
         self.label = np.array(self.label, dtype=int)
     if self.score is not None:
         self.score = np.array(self.score)
 def setUp(self):
     n_roi = 5
     n_class = 6
     self.roi_size = 7
     self.size = (18, 24)
     self.bg_label = 0
     self.roi_mask_prob = np.random.uniform(size=(n_roi, self.roi_size,
                                                  self.roi_size))
     self.roi_prob = np.random.uniform(size=(n_roi, n_class))
     self.bbox = generate_random_bbox(n_roi, self.size, 0, 18)
Ejemplo n.º 17
0
    def test_rotate_bbox(self):
        size = (32, 24)
        bbox = generate_random_bbox(10, size, 0, 24)

        out = rotate_bbox(bbox, self.angle, size)
        if self.angle % 180 != 0:
            rotate_size = size[::-1]
        else:
            rotate_size = size
        out = rotate_bbox(out, -1 * self.angle, rotate_size)

        np.testing.assert_almost_equal(out, bbox, decimal=6)
Ejemplo n.º 18
0
    def predict(self, imgs):
        bboxes = []
        labels = []
        scores = []

        for _ in imgs:
            n_bbox = np.random.randint(0, 10)
            bboxes.append(generate_random_bbox(n_bbox, (48, 32), 4, 12))
            labels.append(np.random.randint(0, 19, size=n_bbox))
            scores.append(np.random.uniform(0, 1, size=n_bbox))

        return bboxes, labels, scores
Ejemplo n.º 19
0
 def setUp(self):
     if hasattr(self, 'no_img'):
         self.img = None
     else:
         self.img = np.random.randint(0, 255, size=(3, 32, 48))
     self.bbox = generate_random_bbox(self.n_bbox, (48, 32), 8, 16)
     if self.label is not None:
         self.label = np.array(self.label, dtype=int)
     if self.score is not None:
         self.score = np.array(self.score)
     if not hasattr(self, 'instance_colors'):
         self.instance_colors = None
Ejemplo n.º 20
0
    def predict(self, imgs):
        bboxes = []
        labels = []
        scores = []

        for _ in imgs:
            n_bbox = np.random.randint(0, 10)
            bboxes.append(generate_random_bbox(
                n_bbox, (48, 32), 4, 12))
            labels.append(np.random.randint(0, 19, size=n_bbox))
            scores.append(np.random.uniform(0, 1, size=n_bbox))

        return bboxes, labels, scores
Ejemplo n.º 21
0
 def setUp(self):
     bboxes = [generate_random_bbox(5, (256, 324), 24, 120)
               for _ in range(10)]
     labels = np.ones((10, 5))
     self.dataset = TupleDataset(
         np.random.uniform(size=(10, 3, 32, 48)),
         bboxes,
         labels)
     self.link = _DetectionStubLink(bboxes, labels)
     self.iterator = SerialIterator(
         self.dataset, 5, repeat=False, shuffle=False)
     self.evaluator = DetectionVOCEvaluator(self.iterator, self.link)
     self.expect_map = 1
Ejemplo n.º 22
0
    def setUp(self):
        feat_size = (self.img_size[0] // 16, self.img_size[1] // 16)
        n_anchor = np.int32(self.n_anchor_base * np.prod(feat_size))

        self.score = np.random.uniform(low=0, high=1,
                                       size=(n_anchor, )).astype(np.float32)
        self.bbox_d = np.random.uniform(low=-1, high=1.,
                                        size=(n_anchor, 4)).astype(np.float32)
        self.anchor = generate_random_bbox(n_anchor, self.img_size, 16, 200)
        self.proposal_creator = ProposalCreator(
            n_train_post_nms=self.n_train_post_nms,
            n_test_post_nms=self.n_test_post_nms,
            min_size=0)
Ejemplo n.º 23
0
    def predict(self, imgs):
        bboxes = []
        labels = []
        scores = []

        for img in imgs:
            n_bbox = np.random.randint(1, 10)
            bboxes.append(generate_random_bbox(n_bbox, img.shape[1:], 4, 12))
            labels.append(
                np.random.randint(0, 20, size=n_bbox).astype(np.int32))
            scores.append(
                np.random.uniform(0, 1, size=n_bbox).astype(np.float32))

        return bboxes, labels, scores
Ejemplo n.º 24
0
 def setUp(self):
     bboxes = [generate_random_bbox(5, (256, 324), 24, 120)
               for _ in range(10)]
     labels = np.ones((10, 5))
     self.dataset = TupleDataset(
         np.random.uniform(size=(10, 3, 32, 48)),
         bboxes,
         labels)
     self.link = _DetectionStubLink(bboxes, labels)
     self.iterator = SerialIterator(
         self.dataset, 5, repeat=False, shuffle=False)
     self.evaluator = DetectionVOCEvaluator(
         self.iterator, self.link, label_names=('cls0', 'cls1', 'cls2'))
     self.expected_ap = 1
Ejemplo n.º 25
0
    def setUp(self):
        faster_rcnn = FasterRCNNVGG16(
            n_fg_class=self.n_fg_class, pretrained_model=False)
        self.link = FasterRCNNTrainChain(faster_rcnn)

        self.n_bbox = 3
        self.bboxes = chainer.Variable(
            generate_random_bbox(self.n_bbox, (600, 800), 16, 350)[np.newaxis])
        _labels = np.random.randint(
            0, self.n_fg_class, size=(1, self.n_bbox)).astype(np.int32)
        self.labels = chainer.Variable(_labels)
        _imgs = np.random.uniform(
            low=-122.5, high=122.5, size=(1, 3, 600, 800)).astype(np.float32)
        self.imgs = chainer.Variable(_imgs)
        self.scale = chainer.Variable(np.array(1.))
Ejemplo n.º 26
0
    def setUp(self):

        n_roi = 1024
        n_mask = 10
        img_size = (392, 512)
        self.roi = generate_random_bbox(n_roi, img_size, 16, 250)
        self.mask = np.random.uniform(size=(n_mask, img_size[0],
                                            img_size[1])) > 0.5
        self.label = np.random.randint(0,
                                       self.n_class - 1,
                                       size=(n_mask, ),
                                       dtype=np.int32)

        self.proposal_target_creator = ProposalTargetCreator(
            n_sample=self.n_sample, pos_ratio=self.pos_ratio)
    def predict(self, imgs):
        bboxes = []
        labels = []
        scores = []

        for img in imgs:
            n_bbox = np.random.randint(1, 10)
            bboxes.append(generate_random_bbox(
                n_bbox, img.shape[1:], 4, 12))
            labels.append(np.random.randint(
                0, 20, size=n_bbox).astype(np.int32))
            scores.append(np.random.uniform(
                0, 1, size=n_bbox).astype(np.float32))

        return bboxes, labels, scores
Ejemplo n.º 28
0
    def setUp(self):
        feat_size = (self.img_size[0] // 16, self.img_size[1] // 16)
        n_anchor = np.int32(self.n_anchor_base * np.prod(feat_size))

        self.score = np.random.uniform(
            low=0, high=1, size=(n_anchor,)).astype(np.float32)
        self.bbox_d = np.random.uniform(
            low=-1, high=1., size=(n_anchor, 4)).astype(np.float32)
        self.anchor = generate_random_bbox(n_anchor, self.img_size, 16, 200)
        self.proposal_creator = ProposalCreator(
            n_train_post_nms=self.n_train_post_nms,
            n_test_post_nms=self.n_test_post_nms,
            min_size=0)

        chainer.config.train = self.train
Ejemplo n.º 29
0
 def setUp(self):
     bboxes = [generate_random_bbox(5, (256, 324), 24, 120)
               for _ in range(10)]
     areas = [[np.array([(bb[2] - bb[0]) * bb[3] - bb[0]]) for bb in bbox]
              for bbox in bboxes]
     labels = 2 * np.ones((10, 5), dtype=np.int32)
     crowdeds = np.zeros((10, 5))
     self.dataset = TupleDataset(
         np.random.uniform(size=(10, 3, 32, 48)),
         bboxes, labels, areas, crowdeds)
     self.link = _DetectionStubLink(bboxes, labels)
     self.iterator = SerialIterator(
         self.dataset, 5, repeat=False, shuffle=False)
     self.evaluator = DetectionCOCOEvaluator(
         self.iterator, self.link, label_names=('cls0', 'cls1', 'cls2'))
     self.expected_ap = 1
    def test_generate_random_bbox(self):
        img_size = (128, 256)
        min_length = 16
        max_length = 48

        bbox = generate_random_bbox(self.n, img_size, min_length, max_length)

        assert_is_bbox(bbox, img_size)
        self.assertEqual(bbox.shape[0], self.n)

        if self.n > 0:
            h = bbox[:, 2] - bbox[:, 0]
            w = bbox[:, 3] - bbox[:, 1]
            self.assertTrue(np.all(h < max_length))
            self.assertTrue(np.all(h >= min_length))
            self.assertTrue(np.all(w < max_length))
            self.assertTrue(np.all(w >= min_length))
Ejemplo n.º 31
0
    def test_generate_random_bbox(self):
        n = 32
        img_size = (128, 256)
        min_length = 16
        max_length = 48

        bbox = generate_random_bbox(n, img_size, min_length, max_length)

        assert_is_bbox(bbox, img_size)
        self.assertEqual(bbox.shape[0], n)

        h = bbox[:, 2] - bbox[:, 0]
        w = bbox[:, 3] - bbox[:, 1]
        self.assertTrue(np.all(h < max_length))
        self.assertTrue(np.all(h >= min_length))
        self.assertTrue(np.all(w < max_length))
        self.assertTrue(np.all(w >= min_length))
Ejemplo n.º 32
0
    def setUp(self):
        proposal_creator_params = {
            'n_train_post_nms': self.n_train_post_nms,
            'n_test_post_nms': self.n_test_post_nms
        }
        self.model = LightHeadRCNNTrainChain(
            LightHeadRCNNResNet101(
                self.n_fg_class,
                pretrained_model=None,
                proposal_creator_params=proposal_creator_params))

        self.bboxes = generate_random_bbox(self.n_bbox, (600, 800), 16,
                                           350)[np.newaxis]
        self.labels = np.random.randint(0,
                                        self.n_fg_class,
                                        size=(1, self.n_bbox)).astype(np.int32)
        self.imgs = _random_array((1, 3, 600, 800))
        self.scales = np.array([1.])
    def _decode(self, loc, conf):
        value = to_cpu(self._value)
        loc = to_cpu(loc)
        conf = to_cpu(conf)

        if not hasattr(self, '_count'):
            self._count = 0
        np.testing.assert_equal(loc, value[self._count, :, :4])
        np.testing.assert_equal(conf, value[self._count, :, 4:])
        self._count += 1

        n_bbox = np.random.randint(self._n_anchor - 1)
        bbox = generate_random_bbox(n_bbox, (self._insize, self._insize), 8,
                                    48)
        label = np.random.randint(self._n_fg_class - 1, size=n_bbox) \
            .astype(np.int32)
        score = np.random.uniform(size=n_bbox).astype(np.float32)
        return bbox, label, score
Ejemplo n.º 34
0
    def test_generate_random_bbox(self):
        n = 32
        img_size = (128, 256)
        min_length = 16
        max_length = 48

        bbox = generate_random_bbox(n, img_size, min_length, max_length)

        self.assertIsInstance(bbox, np.ndarray)
        self.assertEqual(bbox.shape, (n, 4))
        self.assertTrue(np.all(bbox[:, [0, 2]] < img_size[0]))
        self.assertTrue(np.all(bbox[:, [0, 2]] >= 0))
        self.assertTrue(np.all(bbox[:, [1, 3]] < img_size[1]))
        self.assertTrue(np.all(bbox[:, [1, 3]] >= 0))

        h = bbox[:, 2] - bbox[:, 0]
        w = bbox[:, 3] - bbox[:, 1]
        self.assertTrue(np.all(h < max_length))
        self.assertTrue(np.all(h >= min_length))
        self.assertTrue(np.all(w < max_length))
        self.assertTrue(np.all(w >= min_length))
Ejemplo n.º 35
0
    def test(self):
        H = 80
        W = 90
        n_inst = 10

        mask = np.zeros((n_inst, H, W), dtype=np.bool)
        bbox = generate_random_bbox(n_inst, (H, W), 10, 30).astype(np.int32)
        for i, bb in enumerate(bbox):
            y_min, x_min, y_max, x_max = bb
            m = np.random.randint(0, 2, size=(y_max - y_min, x_max - x_min))
            m[5, 5] = 1  # At least one element is one
            mask[i, y_min:y_max, x_min:x_max] = m
        bbox = mask_to_bbox(mask)
        size = H * 2
        out_H = size
        out_W = W * 2
        out_mask = scale_mask(mask, bbox, size)

        expected = resize(mask.astype(np.float32), (out_H, out_W),
                          interpolation=PIL.Image.NEAREST).astype(np.bool)
        np.testing.assert_equal(out_mask, expected)
Ejemplo n.º 36
0
    def setUp(self):
        self.n_anchor_base = 6
        self.feat_stride = 4
        self.n_fg_class = 3
        self.n_roi = 24
        self.n_bbox = 3
        self.link = FasterRCNNTrainChain(DummyFasterRCNN(
            n_anchor_base=self.n_anchor_base,
            feat_stride=self.feat_stride,
            n_fg_class=self.n_fg_class,
            n_roi=self.n_roi,
            min_size=600,
            max_size=800,
        ))

        self.bboxes = chainer.Variable(
            generate_random_bbox(self.n_bbox, (600, 800), 16, 350)[np.newaxis])
        _labels = np.random.randint(
            0, self.n_fg_class, size=(1, self.n_bbox)).astype(np.int32)
        self.labels = chainer.Variable(_labels)
        self.imgs = chainer.Variable(_random_array((1, 3, 600, 800)))
        self.scale = chainer.Variable(np.array(1.))
Ejemplo n.º 37
0
    def setUp(self):
        self.n_anchor_base = 6
        self.feat_stride = 4
        self.n_fg_class = 3
        self.n_roi = 24
        self.n_bbox = 3
        self.link = FasterRCNNTrainChain(DummyFasterRCNN(
            n_anchor_base=self.n_anchor_base,
            feat_stride=self.feat_stride,
            n_fg_class=self.n_fg_class,
            n_roi=self.n_roi,
            min_size=600,
            max_size=800,
        ))

        self.bboxes = chainer.Variable(
            generate_random_bbox(self.n_bbox, (600, 800), 16, 350)[np.newaxis])
        _labels = np.random.randint(
            0, self.n_fg_class, size=(1, self.n_bbox)).astype(np.int32)
        self.labels = chainer.Variable(_labels)
        self.imgs = chainer.Variable(_random_array((1, 3, 600, 800)))
        self.scale = chainer.Variable(np.array(1.))
Ejemplo n.º 38
0
    def _decode(self, loc, obj, conf):
        locs = to_cpu(self._locs)
        objs = to_cpu(self._objs)
        confs = to_cpu(self._confs)

        loc = to_cpu(loc)
        obj = to_cpu(obj)
        conf = to_cpu(conf)

        if not hasattr(self, '_count'):
            self._count = 0
        np.testing.assert_equal(loc, locs[self._count])
        np.testing.assert_equal(obj, objs[self._count])
        np.testing.assert_equal(conf, confs[self._count])
        self._count += 1

        n_bbox = np.random.randint(self._n_anchor - 1)
        bbox = generate_random_bbox(
            n_bbox, (self._insize, self._insize), 8, 48)
        label = np.random.randint(self._n_fg_class - 1, size=n_bbox) \
            .astype(np.int32)
        score = np.random.uniform(size=n_bbox).astype(np.float32)
        return bbox, label, score
    def test_random_crop_with_bbox_constraints(self):
        img = np.random.randint(0, 256, size=(3, 480, 640)).astype(np.float32)
        bbox = generate_random_bbox(10, img.shape[1:], 0.1, 0.9)

        out, param = random_crop_with_bbox_constraints(
            img, bbox,
            min_scale=0.3, max_scale=1,
            max_aspect_ratio=2,
            return_param=True)

        if param['constraint'] is None:
            np.testing.assert_equal(out, img)
        else:
            np.testing.assert_equal(
                out, img[:, param['y_slice'], param['x_slice']])

            # to ignore rounding error, add 1
            self.assertGreaterEqual(
                out.shape[0] * (out.shape[1] + 1) * (out.shape[2] + 1),
                img.size * 0.3 * 0.3)
            self.assertLessEqual(out.size, img.size * 1 * 1)
            self.assertLessEqual(
                out.shape[1] / (out.shape[2] + 1),
                img.shape[1] / img.shape[2] * 2)
            self.assertLessEqual(
                out.shape[2] / (out.shape[1] + 1),
                img.shape[2] / img.shape[1] * 2)

            bb = np.array((
                param['y_slice'].start, param['x_slice'].start,
                param['y_slice'].stop, param['x_slice'].stop))
            iou = bbox_iou(bb[np.newaxis], bbox)
            min_iou, max_iou = param['constraint']
            if min_iou:
                self.assertGreaterEqual(iou.min(), min_iou)
            if max_iou:
                self.assertLessEqual(iou.max(), max_iou)
Ejemplo n.º 40
0
 def setUp(self):
     self.src_bbox = generate_random_bbox(8, (64, 32), 4, 16)
     self.dst_bbox = self.src_bbox + 1
Ejemplo n.º 41
0
 def setUp(self):
     self.bbox = generate_random_bbox(6000, (600, 800), 32, 512)
     self.score = np.random.uniform(0, 100, size=(len(self.bbox), ))
     self.limit = 100
     self.threshold = 0.5
Ejemplo n.º 42
0
 def setUp(self):
     self.src_bbox = generate_random_bbox(8, (64, 32), 4, 16)
     self.dst_bbox = self.src_bbox + 1
Ejemplo n.º 43
0
 def setUp(self):
     self.bbox = generate_random_bbox(6000, (600, 800), 32, 512)
     self.score = np.random.uniform(0, 100, size=(len(self.bbox),))
     self.limit = 100
     self.threshold = 0.5