Esempio n. 1
0
        path = os.path.join(os.path.dirname(__file__),
                            'VOCdevkit-matlab-wrapper')
        cmd = 'cd {} && '.format(path)
        cmd += '{:s} -nodisplay -nodesktop '.format(datasets.MATLAB)
        cmd += '-r "dbstop if error; '
        cmd += 'voc_eval(\'{:s}\',\'{:s}\',\'{:s}\',\'{:s}\',{:d}); quit;"' \
               .format(self._devkit_path, comp_id,
                       self._image_set, output_dir, int(rm_results))
        print('Running:\n{}'.format(cmd))
        status = subprocess.call(cmd, shell=True)

    def evaluate_detections(self, all_boxes, output_dir):
        comp_id = self._write_voc_results_file(all_boxes)
        # self._do_matlab_eval(comp_id, output_dir)

    def competition_mode(self, on):
        if on:
            self.config['use_salt'] = False
            self.config['cleanup'] = False
        else:
            self.config['use_salt'] = True
            self.config['cleanup'] = True


if __name__ == '__main__':
    d = datasets.kitti('trainval')
    res = d.roidb
    from IPython import embed
    embed()
Esempio n. 2
0
                for cls_ind, cls in enumerate(self.classes):
                    if cls == '__background__':
                        continue
                    dets = all_boxes[cls_ind][im_ind]
                    if dets == []:
                        continue
                    for k in xrange(dets.shape[0]):
                        f.write('{:f} {:f} {:f} {:f} {:.32f}\n'.format(\
                                 dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3], dets[k, 4]))

    def evaluate_proposals_msr(self, all_boxes, output_dir):
        # for each image
        for im_ind, index in enumerate(self.image_index):
            filename = os.path.join(output_dir, index + '.txt')
            print 'Writing KITTI results to file ' + filename
            with open(filename, 'wt') as f:
                dets = all_boxes[im_ind]
                if dets == []:
                    continue
                for k in xrange(dets.shape[0]):
                    f.write('{:f} {:f} {:f} {:f} {:.32f}\n'.format(
                        dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3],
                        dets[k, 4]))


if __name__ == '__main__':
    d = datasets.kitti('train')
    res = d.roidb
    from IPython import embed
    embed()
Esempio n. 3
0
            print 'Writing KITTI results to file ' + filename
            with open(filename, 'wt') as f:
                # for each class
                for cls_ind, cls in enumerate(self.classes):
                    if cls == '__background__':
                        continue
                    dets = all_boxes[cls_ind][im_ind]
                    if dets == []:
                        continue
                    for k in xrange(dets.shape[0]):
                        f.write('{:f} {:f} {:f} {:f} {:.32f}\n'.format(\
                                 dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3], dets[k, 4]))

    def evaluate_proposals_msr(self, all_boxes, output_dir):
        # for each image
        for im_ind, index in enumerate(self.image_index):
            filename = os.path.join(output_dir, index + '.txt')
            print 'Writing KITTI results to file ' + filename
            with open(filename, 'wt') as f:
                dets = all_boxes[im_ind]
                if dets == []:
                    continue
                for k in xrange(dets.shape[0]):
                    f.write('{:f} {:f} {:f} {:f} {:.32f}\n'.format(dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3], dets[k, 4]))


if __name__ == '__main__':
    d = datasets.kitti('train')
    res = d.roidb
    from IPython import embed; embed()
Esempio n. 4
0
        path = os.path.join(os.path.dirname(__file__), "VOCdevkit-matlab-wrapper")
        cmd = "cd {} && ".format(path)
        cmd += "{:s} -nodisplay -nodesktop ".format(datasets.MATLAB)
        cmd += '-r "dbstop if error; '
        cmd += "voc_eval('{:s}','{:s}','{:s}','{:s}',{:d}); quit;\"".format(
            self._devkit_path, comp_id, self._image_set, output_dir, int(rm_results)
        )
        print ("Running:\n{}".format(cmd))
        status = subprocess.call(cmd, shell=True)

    def evaluate_detections(self, all_boxes, output_dir):
        comp_id = self._write_voc_results_file(all_boxes)
        # self._do_matlab_eval(comp_id, output_dir)

    def competition_mode(self, on):
        if on:
            self.config["use_salt"] = False
            self.config["cleanup"] = False
        else:
            self.config["use_salt"] = True
            self.config["cleanup"] = True


if __name__ == "__main__":
    d = datasets.kitti("trainval")
    res = d.roidb
    from IPython import embed

    embed()
Esempio n. 5
0
                        f.write('{:s} -1 -1 {:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.3f}\n' \
                                .format(cls.lower(), alpha, \
                                dets[k, 0], dets[k, 1], dets[k, 2], dets[k, 3], \
                                dets3D[k, 2], dets3D[k, 3], dets3D[k, 1], \
                                dets3D[k, 4], dets3D[k, 5], dets3D[k, 6], dets3D[k, 0], dets[k, 4]))

        return path

    def _do_eval(self, path, output_dir='output'):
        cmd = os.path.join(datasets.ROOT_DIR, 'kitti/eval/cpp/evaluate_object {}'.format(os.path.dirname(path)))
        print('Running:\n{}'.format(cmd))
        status = subprocess.call(cmd, shell=True)

    def evaluate_detections(self, all_boxes, all_boxes3D, output_dir):
        path = self._write_kitti_results_file(all_boxes, all_boxes3D)
        if self._image_set != 'test':
            self._do_eval(path)

    def competition_mode(self, on):
        if on:
            self.config['use_salt'] = False
            self.config['cleanup'] = False
        else:
            self.config['use_salt'] = True
            self.config['cleanup'] = True

if __name__ == '__main__':
    d = datasets.kitti('train', 'car')
    res = d.roidb
    from IPython import embed; embed()
Esempio n. 6
0
def main():
    ''' Main function'''
    parser = argparse.ArgumentParser(
        description=
        'Convert from datasets (COCO, UA-DETRAC, MOT2020, Bdd100k, AIHub, CrowdHuman, VisDrone, kitti) to YOLO format.'
    )
    parser.add_argument(
        '--mode',
        type=str,
        help='type of program. e.g. parse/convert/both/analysis')
    parser.add_argument(
        '--datasets',
        type=str,
        help=
        'type of datasets (COCO, DETRAC, MOT2020, Bdd100k, AIHub, CrowdHuman, VisDrone, kitti)'
    )
    parser.add_argument('--datasetsDir',
                        type=str,
                        help='directory of datasets')

    parser.add_argument('--save', action='store_true', help='Save the file.')
    parser.add_argument('--manipastFile',
                        type=str,
                        help='manipast file',
                        default="manipast.txt")

    parser.add_argument('--copy', action='store_true', help='Copy of images')
    parser.add_argument('--copyDir',
                        type=str,
                        help='directory of save target images',
                        default='./copy')

    parser.add_argument('--negative', action='store_true', help='')

    config = parser.parse_args()

    config.imgNum = [0 for i in range(5)]
    config.classNum = [0 for i in range(5)]
    # Car, Van, Truck, Tram, Pedestrian, Cyclist
    config.labelDict = {
        "Van": 0,
        "Car": 0,
        "van": 0,
        "car": 0,
        "bus": 1,
        "Truck": 2,
        "truck": 2,
        "others": 2,
        "motorcycle": 3,
        "motor": 3,
        "motorbike": 3,
        "Cyclist": 4,
        "people": 4,
        "person": 4,
        "rider": 4,
        "pedestrian": 4
    }
    # config.labelDict = {"Cyclist": 0, "people": 0, "person": 0, "rider": 0, "pedestrian": 0}
    # config.labelDict = {"Van": 0, "Car": 0, "van": 0, "car": 0, "bus": 1, "Truck": 2, "truck": 2, "others": 2, "motorcycle": 3, "motor": 3, "motorbike":3}

    if config.datasets == "detrac":
        config.copy == True

    commonData = None
    if config.mode == 'parse' or config.mode == 'both':
        if config.datasets == "coco":
            model = coco(config)
        elif config.datasets == "aihub":
            model = aihub(config)
        elif config.datasets == "bdd100k":
            model = bdd100k(config)
        elif config.datasets == "detrac":
            model = detrac(config)
        elif config.datasets == "crowdhuman":
            model = crowdhuman(config)
        elif config.datasets == "detrac":
            model = detrac(config)
        elif config.datasets == "visdrone":
            model = visdrone(config)
        elif config.datasets == "kitti":
            model = kitti(config)
        elif config.datasets == "testworks":
            config.labelDict = {
                "pedestrian": 0,
                "vehicle": 1,
                "suv": 2,
                "van": 3,
                "small_truck": 4,
                "large_truck": 5,
                "bus": 6,
                "bike": 7,
                "motor_cycle": 8,
                "ambulance": 9,
                "fire_truck": 10,
                "police_car": 11,
                "special_car": 12,
                "wheel_chair": 13,
                "wreck_car": 14,
                "smart_mobility": 15
            }
            model = testworks(config)
        commonData = model.parse()
        save_commonData(commonData, config.datasets)

    if config.mode == 'convert' or config.mode == 'both':
        converter = Converter(config)
        if commonData == None:
            commonData = load_commonData(config.datasets)
        converter.yolo(commonData, save=config.save, copy=config.copy)

    if config.mode == 'analysis':
        converter = Converter(config)
        if commonData == None:
            commonData = load_commonData(config.datasets)
        converter.analysis(commonData)