Beispiel #1
0
    def by_dataset(self, vid_path='./data/freeman1/'):
        assert os.path.exists(vid_path)

        gt_boxes = BoundingBox.read_vid_gt(vid_path)

        curr_bbox = None
        self.stopwatch.start('total')
        _logger.info('---- start dataset l=%d' % (len(gt_boxes)))
        for idx, gt_box in enumerate(gt_boxes):
            img = commons.imread(
                os.path.join(vid_path, 'img', '%04d.jpg' % (idx + 1)))
            self.imgwh = Coordinate.get_imgwh(img)
            if idx == 0:
                # initialization : initial fine-tuning
                self.initial_finetune(img, gt_box)
                curr_bbox = gt_box

            # tracking
            predicted_box = self.tracking(img, curr_bbox)
            self.show(img, gt_box=gt_box, predicted_box=predicted_box)
            # cv2.imwrite('/Users/ildoonet/Downloads/aaa/%d.jpg' % self.iteration, img)
            curr_bbox = predicted_box
        self.stopwatch.stop('total')

        _logger.info('----')
        _logger.info(self.stopwatch)
        _logger.info('%.3f FPS' %
                     (len(gt_boxes) / self.stopwatch.get_elapsed('total')))
Beispiel #2
0
 def __call__(self, results):
     filename = osp.join(results['img_prefix'],
                         results['img_info']['filename'])
     img = commons.imread(filename)
     if self.to_float32:
         img = img.astype(np.float32)
     results['filename'] = filename
     results['img'] = img
     results['img_shape'] = img.shape
     results['ori_shape'] = img.shape
     return results
Beispiel #3
0
    def show(self, img, delay=1, predicted_box=None, gt_box=None):
        if isinstance(img, str):
            img = commons.imread(img)

        if gt_box is not None:
            gt_box.draw(img, BoundingBox.COLOR_GT)
        if predicted_box is not None:
            predicted_box.draw(img, BoundingBox.COLOR_PREDICT)

        visualizer.image('result', img)
        # cv2.imshow('result', img)
        cv2.waitKey(delay)
Beispiel #4
0
    def show(self, img,idx, delay=1, predicted_box=None, gt_box=None):
        if isinstance(img, str):
            img = commons.imread(img)

        if gt_box is not None:
            gt_box.draw(img, BoundingBox.COLOR_GT)
        if predicted_box is not None:
            predicted_box.draw(img, BoundingBox.COLOR_PREDICT)

        cv2.imshow('result', img)
        path = './result/'
        os.path.join(path)
        cv2.imwrite( '%06d.jpg' % (idx + 1), img)
        cv2.waitKey(delay)
Beispiel #5
0
    def __call__(self, results):
        filename1 = osp.join(results['img_prefix'],
                             results['img_info']['filename1'])
        img1 = commons.imread(filename1)

        filename2 = osp.join(results['img_prefix'],
                             results['img_info']['filename2'])
        img2 = commons.imread(filename2)

        if self.to_float32:
            img1 = img1.astype(np.float32)
            img2 = img2.astype(np.float32)

        results['filename1'] = filename1
        results['img1'] = img1
        results['img1_shape'] = img1.shape
        results['ori1_shape'] = img1.shape

        results['filename2'] = filename2
        results['img2'] = img2
        results['img2_shape'] = img2.shape
        results['ori2_shape'] = img2.shape

        return results
def img_label(lb_dir_dict):
    img_label = {}
    train_img = {}
    test_img = {}
    for key in lb_dir_dict:
        imgs = []
        img_dir = glob.glob(lb_dir_dict[key]+'/*.bmp')
        for idx, dir in enumerate(img_dir):
            print("Read: ", dir)
            img = commons.imread(dir)
            img = commons.extract_region(img)
            imgs.append(img)
        img_label[key] = imgs
        train_size = int(len(imgs)*0.8)
        train_img[key] = imgs[:train_size]
        test_img[key] = imgs[train_size:]

    return img_label, train_img, test_img
Beispiel #7
0
    def by_dataset(self, vid_path='./data/LT52/'):
        """
        './data/BlurCar2/'
        LT52

        """
        assert os.path.exists(vid_path)
        id=0
        gt_boxes = BoundingBox.read_vid_gt(vid_path,id)
        print("gt_boxes>>", gt_boxes)

        curr_bbox = None
        self.stopwatch.start('total')
        _logger.info('---- start dataset l=%d' % (len(gt_boxes)))
        for idx, gt_box in enumerate(gt_boxes):
            print('\nimage number : %04d.jpg' %(idx+1))
            print('vid path is %s' %vid_path)
            if idx!=1:
                img = commons.imread(os.path.join(vid_path, 'img', '%04d.jpeg' % (idx + 1)))
                self.imgwh = Coordinate.get_imgwh(img)
                if idx == 0:
                    # initialization : initial fine-tuning
                    # print("gt_box >", gt_box)
                    self.initial_finetune(img, gt_box)
                    curr_bbox = gt_box

                # tracking
                # print("curr_bbox>>", curr_bbox, idx)
                predicted_box = self.tracking(img, curr_bbox,idx)
                # print("predicted_box>>", predicted_box, predicted_box.xy.x, predicted_box.xy.y)
                self.show(img, idx,gt_box=gt_box, predicted_box=predicted_box)
                # cv2.imwrite('/Users/ildoonet/Downloads/aaa/%d.jpg' % self.iteration, img)
                curr_bbox = predicted_box
        self.stopwatch.stop('total')

        _logger.info('----')
        _logger.info(self.stopwatch)
        _logger.info('%.3f FPS' % (len(gt_boxes) / self.stopwatch.get_elapsed('total')))
Beispiel #8
0
    from conf.configs import ADNetConf
    ADNetConf.get('./conf/dylan.yaml')
    
    input_node = tf.placeholder(tf.float32, shape=(None, 2, 107, 107, 3), name='patch')
    tensor_lb_action = tf.placeholder(tf.float32, shape=(None, 4), name='lb_action')    # actions
    tensor_lb_class = tf.placeholder(tf.int32, shape=(None, ), name='lb_class')      # 2 actions
    is_training = tf.placeholder(tf.bool, name='is_training')

    adnet = ADNetwork()
    adnet.create_network(input_node, tensor_lb_action, tensor_lb_class, is_training)

    config = tf.ConfigProto(allow_soft_placement=True, log_device_placement=False)
    with tf.Session(config=config) as sess:
        # load all pretrained weights
        adnet.read_original_weights(sess)
        
        variables = tf.trainable_variables()
        ps = sess.run(variables)

        # zero input
        zeros = np.zeros(shape=(1, 2, 107, 107, 3), dtype=np.float32)
        from commons import imread
        img1 = imread(r'./dataset/OTB/Car4/img/0009.jpg')
        from boundingbox import crop_resize
        zeros = crop_resize(img1, (70, 51, 103, 87))[None]
        

        action_out, class_out = sess.run([adnet.layer_actions, adnet.layer_scores], feed_dict={input_node: zeros})
        print(action_out, class_out)