Пример #1
0
 def getDetectionData(self,modelName,prototxtName,cls_order,cls_mapper,gpu_id,testSets,datasetName="openImages_v4"):
     imgIdx = []
     GT = []
     CLASSES = self.processClass(cls_order,cls_mapper)
     name = "eval"
     for target in testSets:
         dataset = openImageData(name,cls_order,cls_mapper,sets=target)
         for i in dataset._image_index:
             target_img = "/root/data/data-{}/{}/{}.jpg".format(datasetName,target,i)
             imgIdx += [target_img]
             label = dataset._load_boxes(i)['gt_classes']
             bbox = dataset._load_boxes(i)['boxes']
             for j,k in zip(label,bbox):
                 GT.append(([target_img,k[0],k[1],k[2],k[3],CLASSES[j]]))
     GTdata = {}
     gtCounterPerCls = {}
     for re in GT:
         if gtCounterPerCls.has_key(re[5]):
             gtCounterPerCls[re[5]]+=1
         else:
             gtCounterPerCls[re[5]] = 1
         hit = {"label":re[5],"bbox":[x for x in re[1:5]],"used":False}
         if GTdata.has_key(re[0]):
             GTdata.get(re[0]).append(hit)
         else:
             GTdata[re[0]] = []
             GTdata.get(re[0]).append(hit)   
     weightPath = modelName#"/root/pva-faster-rcnn/models/output/{}/{}_iter_{}.caffemodel".format(modelName,modelName,str(iteration))
     modelPath = prototxtName#"/root/pva-faster-rcnn/models/pvanet/lite/{}_test.prototxt".format(modelName)
     print weightPath
     print modelPath
     caffe.set_mode_gpu()
     caffe.set_device(gpu_id)
     cfg_from_file("models/pvanet/cfgs/submit_0716.yml")
     cfg.GPU_ID = gpu_id
     det = {}
     totalImg = len(imgIdx)                       
     if not os.path.isfile(weightPath):
         raise IOError(('Caffemodel: {:s} not found').format(weightPath))
     net = caffe.Net(modelPath, weightPath, caffe.TEST)
     print '\n\nLoaded network {:s}'.format(modelPath)
     print "Total testing images: {}".format(len(imgIdx))
     for idx,targetImg in enumerate(imgIdx):
         timer = Timer()
         timer.tic()
         _t = {'im_preproc': Timer(), 'im_net' : Timer(), 'im_postproc': Timer(), 'misc' : Timer()}
         res = self.detect(CLASSES,net,targetImg,15)
         timer.toc()
         print "Processing: {}/{},time usage is {:.3f}s".format(idx,totalImg,timer.average_time)
         for re in res:
             hit = {"confidence":re[5],"fileName":re[0],"bbox":[x for x in re[1:5]]}
             if det.has_key(re[6]):
                 det.get(re[6]).append(hit)
             else:
                 det[re[6]] = []
                 det.get(re[6]).append(hit)             
     for i in CLASSES:
         if det.has_key(i) == False:
             det[i] = []
     return det,GTdata,gtCounterPerCls
Пример #2
0
def prepare_data():
    #Set the training configuration first
    cfg_path = "models/pvanet/lite/train.yml"
    cfg_from_file(cfg_path)
    """
     1. PREPARING DATASET
    """

    #Firstly, prepare the dataset for fine-tuning
    #Different kind of dataset is wrapped by the IMDB class, originally designed by Ross Girshick

    #You need to put coco data directory(soft-link works as well) under the PVA-NET directory
    #COCO IMDB needs two parameter: data-split and year

    #coco_train = coco("train", "2014")
    #coco_val = coco("val", "2014")

    #Fetch the classes of coco dataet, this will be useful in the following section

    #classes = coco_val._classes
    #Next, we import the VOC dataset via pascal_voc wrapper
    #Since VOC and COCO data have different naming among classes, a naming mapper is needed to unify the class names

    #mapper = {"tvmonitor":"tv", "sofa":"couch", "aeroplane":"airplane",
    #              "motorbike":"motorcycle", "diningtable":"dining table", "pottedplant":"potted plant"}

    #Finnaly, let's wrap datasets from Vatic.
    #A vatic dataset directory should be located under ~/data/ directory in the naming of data-*
    #For example: ~/data/data-YuDa,  ~/data/data-A1HighwayDay
    #vatic_names = ["A1HighwayDay", "B2HighwayNight", "airport", "airport2"]

    #    mapper = {"van":"car", "trailer-head":"truck",\
    #              "sedan/suv":"car", "scooter":"motorcycle", "bike":"bicycle"}

    #    vatics = [VaticData(vatic_name, classes, CLS_mapper=mapper, train_split="all") for vatic_name in vatic_names]

    #openImages = [openImageData(dataName, classes, CLS_mapper=mapperList, train_split="train") for dataName in dataNames]

    #Combine all the IMDBs into one single IMDB for training
    #    datasets = vatics + [coco_train, coco_val]
    datasets = openImageData("test", "/root/pva-faster-rcnn/smallSample.json")
    #imdb_group = IMDBGroup(datasets)
    imdb, roidb = combined_roidb(datasets)

    total_len = float(len(datasets.gt_roidb()))

    #Show the dataset percentage in the whole composition
    img_nums = len(datasets.gt_roidb())
    print(datasets.name, img_nums,
          "{0:.2f}%".format(img_nums / total_len * 100))

    return roidb
Пример #3
0
def prepare_data(model_name, classPath, cls_order):
    #Set the training configuration first
    cfg_path = "models/pvanet/lite/train.yml"
    cfg_from_file(cfg_path)

    datasets = openImageData(model_name, classPath, cls_order)
    #imdb_group = IMDBGroup(datasets)
    imdb, roidb = combined_roidb(datasets)

    total_len = float(len(datasets.gt_roidb()))

    #Show the dataset percentage in the whole composition
    img_nums = len(datasets.gt_roidb())
    print(datasets.name, img_nums,
          "{0:.2f}%".format(img_nums / total_len * 100))

    return roidb
Пример #4
0
            'boxes': boxes,
            'gt_classes': gt_classes,
            'gt_overlaps': overlaps,
            'flipped': False,
            'seg_areas': seg_areas
        }


if __name__ == '__main__':
    from datasets.openImage import openImageData
    from datasets.openImage import IMDBGroup

    name = "test"
    configPath = '/root/pva-faster-rcnn/sample.json'
    jsonInput = open(configPath)
    config = json.load(jsonInput)
    cls_order = config.get("cls_order")
    cls_mapper = config.get("cls_mapper")
    tempClass = []
    for cls in cls_order:
        if cls_mapper.has_key(cls):
            if cls_mapper.get(cls) not in tempClass:
                tempClass.append(cls_mapper.get(cls))
        else:
            if cls not in tempClass:
                tempClass.append(cls)
    dataset = openImageData(name, cls_order, cls_mapper)
    gtDb = dataset.gt_roidb()
    #B = openImageData("Monkey", class_set_name)
    #imdb_group = IMDBGroup([A,B])