예제 #1
0
def get_YOLOv2_Predictor():
    # has been trained with coco
    file_yolov2_cfg = getDataFile("yolov2/yolov2.cfg")

    yolov2_training_ctx = TrainingContext(
        n_classes = 80,
        trainfile = "/home/pjreddie/data/coco/trainvalno5k.txt",
        validfile = "coco_testdev",
        namefile = getDataFile("yolov3/coco.names"), # all the other values don't make any difference when predicting
        backup_dir ="/home/pjreddie/backup/",
        setname = "coco"
    )

    return Predictor(training_ctx = yolov2_training_ctx, weight_file = get_yolov2_weights_file(), config_file = file_yolov2_cfg, thresh = 0.6)
예제 #2
0
    def __init__(self,
                 training_ctx=None,
                 config_file=None,
                 weight_file=None,
                 thresh=0.9,
                 hier_thresh=0.5,
                 verbose=False,
                 gpu_index=-1):
        # datacfg(datacfg), cfgfile(cfgfile), weightfile(weightfile), datadir(datadir), thresh(thresh), hier_thresh(hier_thresh)
        """
        DarknetContext ctx = DarknetContext(
        darkdir + std::string("cfg/coco.data"),     # how the weights were trained?
        darkdir + std::string("cfg/yolov3.cfg"),    # convoluted neural network scheme
        darkdir + std::string("yolov3.weights"),    # neural network weights. has been trained with the "coco" data
        darkdir + std::string("data/labels/"),      # alphabet bitmaps
        0.1, 0.5);
        """
        self.pre = pre_mod + self.__class__.__name__ + " : "

        assert (isinstance(training_ctx, TrainingContext))
        assert (isinstance(config_file, str))
        assert (isinstance(weight_file, str))
        assert (isinstance(thresh, float))
        assert (isinstance(hier_thresh, float))

        assert (os.path.exists(config_file))
        assert (os.path.exists(weight_file))

        self.verbose = verbose

        if (self.verbose):
            print(self.pre)
            print(self.pre, str(training_ctx))
            print(self.pre)
            print(self.pre, config_file)
            print(self.pre, weight_file)
            print(self.pre, getDataFile("labels/"))

        self.thresh = thresh
        self.hier_thresh = hier_thresh

        # return

        self.ctx = core.DarknetContext(str(training_ctx), config_file,
                                       weight_file, getDataFile("labels/"))

        self.predictor = core.DarknetPredictor(self.ctx, thresh, hier_thresh)
        if (gpu_index >= 0):
            self.predictor.setGpuIndex(gpu_index)