예제 #1
0
def roidbToFeatures(roidb,
                    pyloader=roidbSampleHOG,
                    calcHog=False,
                    roidbSizes=None):
    pyroidb = RoidbDataset(roidb, [0, 1, 2, 3, 4, 5, 6, 7],
                           loader=pyloader,
                           transform=None)
    if roidbSizes is not None:
        pyroidb.roidbSizes = np.arange(len(roidb)) + 1
    l_feat,l_idx,y = extract_pyroidb_features(pyroidb, 'hog', cfg.clsToSet, calc_feat = calcHog, \
                                              spatial_size=(32, 32),hist_bins=32, \
                                              orient=9, pix_per_cell=8, cell_per_block=2, \
                                              hog_channel=0)
    return l_feat, l_idx, y
예제 #2
0
                for size in datasetSizes:
                    # create a file for each dataset size
                    idlist_filename = createFilenameID(setID, str(r),
                                                       str(size))
                    repo_roidbs, roidbs_anno_counts = createMixtureDataset(
                        setID, size)
                    assert len(repo_roidbs) == setID.count('1')
                    # write pickle file of the roidb
                    allRoidb = combined_roidb(repo_roidbs)
                    onlyNewRoidb = combineOnlyNew(repo_roidbs, pc)
                    appendHOGtoRoidb(onlyNewRoidb)
                    pklName = idlist_filename + ".pkl"
                    print(pklName, roidbs_anno_counts, size)

                    pyroidb = RoidbDataset(allRoidb, [0, 1, 2, 3, 4, 5, 6, 7],
                                           loader=roidbSampleBox,
                                           transform=None)
                    printPyroidbSetCounts(pyroidb)

                    pyroidb = RoidbDataset(onlyNewRoidb,
                                           [0, 1, 2, 3, 4, 5, 6, 7],
                                           loader=roidbSampleBox,
                                           transform=None)
                    printPyroidbSetCounts(pyroidb)

                    saveInfo = {
                        "allRoidb": onlyNewRoidb,
                        "annoCounts": roidbs_anno_counts
                    }
                    if osp.exists(pklName) is False:
                        with open(pklName, "wb") as f:
예제 #3
0
       print("size: {}".format(size))
       print_each_size(sizedRoidb)
    print("-="*50)


    # issue: we are getting zeros area for 5343 of bboxes for pascal_voc_2007

    path = osp.join(prefix_path,"areas.dat")
    np.savetxt(path,areas,fmt='%.18e',delimiter=' ')
    path = osp.join(prefix_path,"widths.dat")
    np.savetxt(path,widths,fmt='%.18e',delimiter=' ')
    path = osp.join(prefix_path,"heights.dat")
    np.savetxt(path,heights,fmt='%.18e',delimiter=' ')

    pyroidb = RoidbDataset(roidb,[0,1,2,3,4,5,6,7],
                           loader=roidbSampleImageAndBox,
                           transform=pyroidbTransform_cropImageToBox)

    if args.save:
        index = imdb._get_roidb_index_at_size(30)
        print("saving 30 imdb annotations to output folder...")        
        print(prefix_path)
        for i in range(index):
            boxes = roidb[i]['boxes']
            if len(boxes) == 0: continue
            im = cv2.imread(roidb[i]['image'])
            if roidb[i]['flipped']:
                im = im[:, ::-1, :]
            cls = roidb[i]['gt_classes']
            fn = osp.join(prefix_path,"{}_{}.png".format(imdb.name,i))
            print(fn)
예제 #4
0
    path = osp.join(prefix_path, "areas.dat")
    np.savetxt(path, areas, fmt='%.18e', delimiter=' ')
    path = osp.join(prefix_path, "widths.dat")
    np.savetxt(path, widths, fmt='%.18e', delimiter=' ')
    path = osp.join(prefix_path, "heights.dat")
    np.savetxt(path, heights, fmt='%.18e', delimiter=' ')

    print("-=-=-=-=-=-")

    clsToSet = loadDatasetIndexDict()

    print("as pytorch friendly ")

    pyroidb = RoidbDataset(roidb, [1, 2, 3, 4, 5, 6, 7, 8],
                           loader=cv2.imread,
                           transform=cropImageToAnnoRegion)

    if args.save:
        print("save 30 cropped annos in output folder.")
        saveDir = "./output/mixedDataReport/"
        if not osp.exists(saveDir):
            print("making directory: {}".format(saveDir))
            os.makedirs(saveDir)

        for i in range(30):
            cls = roidb[i]['set']
            ds = clsToSet[cls]
            fn = osp.join(saveDir, "{}_{}.jpg".format(i, ds))
            print(fn)
            cv2.imwrite(fn, pyroidb[i][0])
예제 #5
0
    path = osp.join(prefix_path, "heights.dat")
    np.savetxt(path, heights, fmt='%.18e', delimiter=' ')

    print("-=" * 50)

    clsToSet = loadDatasetIndexDict()

    print("as pytorch friendly ")

    train_size = 500
    test_size = 500

    #cropped hog image input

    pyroidb = RoidbDataset(roidb, [0, 1, 2, 3, 4, 5, 6, 7],
                           loader=roidbSampleHOG,
                           transform=None)

    print('this is the annocount', annoCount)

    l_feat,l_idx,y = extract_pyroidb_features(pyroidb, 'hog', clsToSet, calc_feat = False, \
                                              spatial_size=(32, 32),hist_bins=32, \
                                              orient=9, pix_per_cell=8, cell_per_block=2, \
                                              hog_channel=0)

    X_train, X_test, y_train, y_test, X_idx = split_data(train_size, test_size, \
                                                         l_feat,l_idx, y,\
                                                         clsToSet)
    print(X_train.shape)
    print(y_train.shape)
    X_train, X_test = scale_data(X_train, X_test)
예제 #6
0
    if args.size != -1:
        datasetSizes = [args.size]

    repeatRange = range(10)
    if args.repeat != -1:
        repeatRange = [args.repeat]

    ## load svm
    for size in datasetSizes:
        for repeat in range(repeatRange):
            roidb,annoCount = load_mixture_set(setID,repeat,size)
            print(annoCount)
            numAnnos = computeTotalAnnosFromAnnoCount(annoCount)
            clsToSet = loadDatasetIndexDict()
            pyroidb = RoidbDataset(roidb,[0,1,2,3,4,5,6,7],
                           loader=roidbSampleBox,
                           transform=pyroidbTransform_normalizeBox)

            annoMaps = annotationDensityPlot(pyroidb)
            for idx,annoMap in enumerate(annoMaps):
                print(" -=-=-=- dataset {} -=-=-=-=- ".format(clsToSet[idx]))
                print("M1: {}".format(metric_1(annoMap,10)))
                fnPrefix = "{}_{}_{}".format(clsToSet[idx],size,repeat)
                plotDensityPlot(annoMap,fnPrefix)
                saveRawAnnoPlot(annoMap,fnPrefix)

                fnPrefix = "{}_{}_{}_hog_a".format(clsToSet[idx],size,repeat)
                hogFts = HOGFromImage(annoMap.astype(np.float32))
                saveHogFeatures(hogFts,fnPrefix)

                fnPrefix = "{}_{}_{}_hog_b".format(clsToSet[idx],size,repeat)
    path = osp.join(prefix_path, "areas.dat")
    np.savetxt(path, areas, fmt='%.18e', delimiter=' ')
    path = osp.join(prefix_path, "widths.dat")
    np.savetxt(path, widths, fmt='%.18e', delimiter=' ')
    path = osp.join(prefix_path, "heights.dat")
    np.savetxt(path, heights, fmt='%.18e', delimiter=' ')

    print("-=-=-=-=-=-")

    clsToSet = loadDatasetIndexDict()

    print("as pytorch friendly ")

    pyroidb = RoidbDataset(roidb, [0, 1, 2, 3, 4, 5, 6, 7],
                           loader=cv2.imread,
                           transform=cropImageToAnnoRegion,
                           returnBox=False)
    print(annoCount)

    # printPyroidbSetCounts(pyroidb)
    # print_each_size(roidb)

    if args.save:
        print("save 30 cropped annos in output folder.")
        saveDir = "./output/mixedDataReport/"
        if not osp.exists(saveDir):
            print("making directory: {}".format(saveDir))
            os.makedirs(saveDir)

        print("pyroidb length: {}".format(len(pyroidb)))
        randIdx = npr.permutation(len(pyroidb))
예제 #8
0
    print_report(roidbTr, annoCountTr, roidbTe, annoCountTe, setID, repeat,
                 size)

    print("-=" * 50)

    clsToSet = loadDatasetIndexDict()

    # add the "HOG" field to pyroidb
    if args.appendHog:
        resaveWithHog(setID, repeat)

    print("as pytorch friendly ")

    if args.pyroidb_type == "mixture":
        pyroidb = RoidbDataset(roidbTr, [0, 1, 2, 3, 4, 5, 6, 7],
                               loader=roidbSampleImageAndBox,
                               transform=pyroidbTransform_cropImageToBox)
    elif args.pyroidb_type == "hog":
        pyroidb = RoidbDataset(roidbTr, [0, 1, 2, 3, 4, 5, 6, 7],
                               loader=roidbSampleHOG,
                               transform=None)
    if args.save:
        print("save 30 cropped annos in output folder.")
        saveDir = "./output/mixedDataReport/"
        if not osp.exists(saveDir):
            print("making directory: {}".format(saveDir))
            os.makedirs(saveDir)

        print("pyroidb length: {}".format(len(pyroidb)))
        # randIdx = npr.permutation(len(pyroidb))
        randIdx = np.arange(len(pyroidb))
예제 #9
0
                # create the repeat folder
                path_repeat = createPathRepeat(setID,str(r))
                if osp.isdir(path_repeat) == False:
                    os.makedirs(path_repeat)
                # shuffle imdbs
                shuffle_imdbs()
                # reset previuos counters
                zeroPreviousCounts()
                for size in datasetSizes:
                    # create a file for each dataset size
                    idlist_filename = createFilenameID(setID,str(r),str(size))
                    repo_roidbs,roidbs_anno_counts = createMixtureDataset(setID,size)
                    assert len(repo_roidbs) == setID.count('1')
                    # write pickle file of the roidb
                    allRoidb = combined_roidb(repo_roidbs)
                    onlyNewRoidb = combineOnlyNew(repo_roidbs)
                    pklName = idlist_filename + ".pkl"
                    print(pklName,roidbs_anno_counts,size)
                    pyroidb = RoidbDataset(allRoidb,[0,1,2,3,4,5,6,7],loader=None,transform=None,returnBox=True)
                    printPyroidbSetCounts(pyroidb)
                    pyroidb = RoidbDataset(onlyNewRoidb,[0,1,2,3,4,5,6,7],loader=None,transform=None,returnBox=True)
                    printPyroidbSetCounts(pyroidb)

                    saveInfo = {"allRoidb":onlyNewRoidb,"annoCounts":roidbs_anno_counts}
                    if osp.exists(pklName) is False:
                        with open(pklName,"wb") as f:
                            pickle.dump(saveInfo,f)
                    else:
                        print("{} exists".format(pklName))
                    updatePreviousCounts(repo_roidbs)