Пример #1
0
    def __getitem__(self, item) -> dict:
        is_negative_pair = (self._state["rng"].rand() <
                            self._hyper_params["negative_pair_ratio"])
        data1 = data2 = None

        while self.filt(data1) or self.filt(data2):
            if is_negative_pair:
                data1 = self._sample_track_frame()
                data2 = self._sample_track_frame()
            else:
                data1, data2 = self._sample_track_pair()
            data1["image"] = load_image(data1["image"])
            data2["image"] = load_image(data2["image"])

        sampled_data = dict(
            data1=data1,
            data2=data2,
            is_negative_pair=is_negative_pair,
        )

        return sampled_data
Пример #2
0
        from videoanalyst.utils import load_image
        datasets = dataset_buidler.build(
            task, task_cfg.data.sampler.submodules.dataset)
        dataset = datasets[0]
        while True:
            # pick a frame randomly
            seq_idx = np.random.choice(range(len(dataset)))
            seq_idx = int(seq_idx)
            seq = dataset[seq_idx]
            # video dataset
            if len(seq['image']) > 1:
                frame_idx = np.random.choice(range(len(seq['image'])))
                frame = {k: seq[k][frame_idx] for k in seq}
                # fetch & visualize data
                im = load_image(frame['image'])
                anno = frame['anno']
            # static image dataset
            else:
                im = load_image(seq['image'][0])
                num_anno = len(seq['anno'])
                if num_anno <= 0:
                    logger.info("no annotation")
                    continue
                anno_idx = np.random.choice(num_anno)
                anno = seq['anno'][anno_idx]
            cv2.rectangle(im,
                          tuple(map(int, anno[:2])),
                          tuple(map(int, anno[2:])), (0, 255, 0),
                          thickness=3)
            im = cv2.resize(im, (0, 0), fx=0.33, fy=0.33)
Пример #3
0
 datasets = dataset_buidler.build(
     task, task_cfg.data.sampler.submodules.dataset)
 dataset = datasets[0]
 while True:
     # pick a frame randomly
     seq_idx = np.random.choice(range(len(dataset)))
     seq_idx = int(seq_idx)
     seq = dataset[seq_idx]
     # for one video
     if len(seq['image']) > 1:
         frame_idx = np.random.choice(range(len(seq['image'])))
         frame = {k: seq[k][frame_idx] for k in seq}
     else:
         frame = dict(image=seq['image'][0], anno=seq['anno'])
     # fetch & visualize data
     im = load_image(frame['image'])
     if parsed_args.data_type == "bbox":
         cv2.rectangle(im,
                       tuple(map(int, frame['anno'][:2])),
                       tuple(map(int, frame['anno'][2:])), (0, 255, 0),
                       thickness=3)
         im = cv2.resize(im, (0, 0), fx=0.33, fy=0.33)
         cv2.imshow("im", im)
         cv2.waitKey(0)
     elif parsed_args.data_type == "mask":
         cv2.imshow("im", im)
         print(frame['anno'][0])
         mask = (frame['anno'][0] * 50).astype(np.uint8).copy()
         cv2.imwrite("mask_0.png", mask)
         cv2.waitKey(0)
     else: