コード例 #1
0
def script_createComparativeHtmls():
    layers = ['pool5', 'fc6', 'fc7']
    path_to_anno = '/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations'
    file_dir = '/disk2/pascal_3d/PASCAL3D+_release1.0/Images_BB'
    dirs = [
        dir[:-7] for dir in os.listdir(path_to_anno) if dir.endswith('pascal')
    ]
    file_name = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/trained/20151027204114'
    file_name_alt = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203547'
    replace_paths = ['/disk2', '../../../..']
    out_file_pre = 'nn_performance_comparison_trained_notrained'
    out_file_pre = os.path.join(
        '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d',
        out_file_pre)
    for layer in layers:
        file_name_l = file_name + '_' + layer
        [img_paths, gt_labels, indices,
         _] = pickle.load(open(file_name_l + '.p', 'rb'))

        idx_sort_binned = script_nearestNeigbourExperiment.sortByPerformance(
            indices, gt_labels, 1, perClass=True)

        img_paths = [
            x.replace(replace_paths[0], replace_paths[1]) for x in img_paths
        ]
        im_paths, captions = visualize.createImageAndCaptionGrid(
            img_paths, gt_labels, indices, dirs)

        file_name_l = file_name_alt + '_' + layer
        [img_paths_alt, gt_labels_alt, indices,
         _] = pickle.load(open(file_name_l + '.p', 'rb'))

        img_paths_alt = [
            x.replace(replace_paths[0], replace_paths[1])
            for x in img_paths_alt
        ]

        im_paths_alt, captions_alt = visualize.createImageAndCaptionGrid(
            img_paths, gt_labels, indices, dirs)

        im_paths_alt = [
            im_paths_alt[img_paths_alt.index(curr_img_path)]
            for curr_img_path in img_paths
        ]
        captions_alt = [
            captions_alt[img_paths_alt.index(curr_img_path)]
            for curr_img_path in img_paths
        ]

        im_paths_big = []
        captions_big = []
        for idx_curr in idx_sort_binned:
            im_paths_big.append(im_paths[idx_curr])
            im_paths_big.append(im_paths_alt[idx_curr])
            captions_big.append(captions[idx_curr])
            captions_big.append(captions_alt[idx_curr])

        visualize.writeHTML(out_file_pre + '_' + layer + '.html', im_paths_big,
                            captions_big)
コード例 #2
0
ファイル: pascal_3d.py プロジェクト: maheenRashid/caffe
def script_createComparativeHtmls():
    layers=['pool5','fc6','fc7'];
    path_to_anno='/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations';
    file_dir='/disk2/pascal_3d/PASCAL3D+_release1.0/Images_BB';
    dirs=[dir[:-7] for dir in os.listdir(path_to_anno) if dir.endswith('pascal')];
    file_name='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/trained/20151027204114'
    file_name_alt='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203547'
    replace_paths=['/disk2','../../../..']
    out_file_pre='nn_performance_comparison_trained_notrained'
    out_file_pre=os.path.join('/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d',out_file_pre);
    for layer in layers:
        file_name_l=file_name+'_'+layer;
        [img_paths,gt_labels,indices,_]=pickle.load(open(file_name_l+'.p','rb'));

        idx_sort_binned=script_nearestNeigbourExperiment.sortByPerformance(indices,gt_labels,1,perClass=True);
        
        img_paths=[x.replace(replace_paths[0],replace_paths[1]) for x in img_paths];
        im_paths,captions=visualize.createImageAndCaptionGrid(img_paths,gt_labels,indices,dirs)

        file_name_l=file_name_alt+'_'+layer;
        [img_paths_alt,gt_labels_alt,indices,_]=pickle.load(open(file_name_l+'.p','rb'));

        img_paths_alt=[x.replace(replace_paths[0],replace_paths[1]) for x in img_paths_alt];
        
        im_paths_alt,captions_alt=visualize.createImageAndCaptionGrid(img_paths,gt_labels,indices,dirs)        
        
        im_paths_alt=[im_paths_alt[img_paths_alt.index(curr_img_path)] for curr_img_path in img_paths];
        captions_alt=[captions_alt[img_paths_alt.index(curr_img_path)] for curr_img_path in img_paths];

        im_paths_big=[];
        captions_big=[];
        for idx_curr in idx_sort_binned:
            im_paths_big.append(im_paths[idx_curr]);
            im_paths_big.append(im_paths_alt[idx_curr]);
            captions_big.append(captions[idx_curr]);
            captions_big.append(captions_alt[idx_curr]);
            
        visualize.writeHTML(out_file_pre+'_'+layer+'.html',im_paths_big,captions_big)
コード例 #3
0
def main():
    train_file = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/trained/20151027204114'
    non_train_file = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203547'
    layers = ['pool5', 'fc6', 'fc7']
    out_dir = '/disk2/octoberExperiments/nn_pascal3d'
    db_file = os.path.join(out_dir, 'nn_pascal3d_new.db')
    if not os.path.exists(out_dir):
        os.mkdir(out_dir)

    path_to_anno = '/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations'
    class_ids = [
        dir[:-7] for dir in os.listdir(path_to_anno) if dir.endswith('pascal')
    ]

    file_pre = train_file
    trainFlag = True
    caffe_model = '/home/maheenrashid/Downloads/caffe/caffe-rc2/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'

    # exceptions=script_populateDB(db_file,file_pre,trainFlag,layers,class_ids,caffe_model)
    # for ex in exceptions:
    #     print len(ex)
    # pickle.dump([exceptions],open(file_pre+'_db_exceptions.p','wb'));

    file_pre = non_train_file
    trainFlag = False
    caffe_model = '/disk2/octoberExperiments/nn_performance_without_pascal/snapshot_iter_450000.caffemodel'
    script_populateDB(db_file, file_pre, trainFlag, layers, class_ids,
                      caffe_model)

    return
    script_saveIndicesAll(train_file, layers)
    script_saveIndicesAll(non_train_file, layers)
    # script_testingDoNN();

    return
    script_createHistComparative()
    # script_createHistsWithSpecificAngle()
    return
    script_createHistComparative()
    # script_createHistDifferenceHTML()
    # script_savePerClassPerDegreeHistograms()
    return
    script_visualizePerClassAzimuthPerformance()
    return
    train_file = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/trained/20151027204114'
    non_train_file = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203547'
    layers = ['pool5', 'fc6', 'fc7']
    path_to_anno = '/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations'

    for file_name in [train_file, non_train_file]:
        [img_paths, gt_labels,
         azimuths] = pickle.load(open(file_name + '_azimuths.p', 'rb'))
        for layer in layers:
            print layer
            file_name_l = file_name + '_' + layer + '_all'
            out_file = file_name_l + '_azimuths.p'

            t = time.time()
            [img_paths, gt_labels, indices,
             _] = pickle.load(open(file_name_l + '.p', 'rb'))
            t = time.time() - t
            print t
            # raw_input();

            diffs_all, dists_all = getAzimuthInfo(img_paths, gt_labels,
                                                  indices, azimuths)
            pickle.dump([img_paths, gt_labels, azimuths, diffs_all, dists_all],
                        open(out_file, 'wb'))

    return
    text_labels = [
        dir[:-7] for dir in os.listdir(path_to_anno) if dir.endswith('pascal')
    ]
    for file_name in [train_file, non_train_file]:
        [img_paths, gt_labels,
         azimuths] = pickle.load(open(file_name + '_azimuths.p', 'rb'))
        for layer in layers:
            print layer
            file_name_l = file_name + '_' + layer + '_all'
            out_dir = file_name_l + '_azimuths'
            if not os.path.exists(out_dir):
                os.mkdir(out_dir)
            t = time.time()
            [img_paths, gt_labels, indices,
             _] = pickle.load(open(file_name_l + '.p', 'rb'))
            t = time.time() - t
            print t
            # raw_input();
            createAzimuthGraphs(img_paths, gt_labels, indices, azimuths,
                                out_dir, text_labels)

    for layer in layers:
        print layer
        out_file = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/azimuths_' + layer + '_all' + '_comparison.html'
        rel_train = 'trained/20151027204114_' + layer + '_all' + '_azimuths'
        rel_notrain = 'no_trained/20151027203547_' + layer + '_all' + '_azimuths'
        out_dir = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203547_' + layer + '_all' + '_azimuths'

        im_paths = [[
            os.path.join(rel_train, file_curr),
            os.path.join(rel_notrain, file_curr)
        ] for file_curr in os.listdir(out_dir) if file_curr.endswith('.jpg')]

        captions = [['train', 'no_train']] * len(im_paths)
        visualize.writeHTML(out_file,
                            im_paths,
                            captions,
                            height=500,
                            width=500)

    # script_saveAzimuthInfo(train_file,path_to_anno);
    # script_saveAzimuthInfo(non_train_file,path_to_anno);
    # script_saveIndicesAll(train_file,layers)
    # script_saveIndicesAll(non_train_file,layers)

    return
    out_dir = '/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d'
    if not os.path.exists(out_dir):
        os.mkdir(out_dir)
    # out_dir=os.path.join(out_dir,'no_trained');
    out_dir = os.path.join(out_dir, 'trained')
    if not os.path.exists(out_dir):
        os.mkdir(out_dir)

    path_to_anno = '/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations'
    file_dir = '/disk2/pascal_3d/PASCAL3D+_release1.0/Images_BB'
    dirs = [
        dir[:-7] for dir in os.listdir(path_to_anno) if dir.endswith('pascal')
    ]
    test_set = []
    for dir_idx, dir in enumerate(dirs):
        ims = [
            filename for filename in glob.glob(file_dir + '/*' + dir + '*.jpg')
        ]
        test_set.extend(zip(ims, [dir_idx] * len(ims)))

    print len(test_set)

    layers = ['pool5', 'fc6', 'fc7']
    gpu_no = 1
    path_to_classify = '..'
    numberOfN = 5
    relativePaths = ['/disk2', '../../../../..']
    deployFile = '/disk2/octoberExperiments/nn_performance_without_pascal/deploy.prototxt'
    meanFile = '/disk2/octoberExperiments/nn_performance_without_pascal/mean.npy'
    modelFile = '/disk2/octoberExperiments/nn_performance_without_pascal/snapshot_iter_450000.caffemodel'
    # file_name=script_nearestNeigbourExperiment.runClassificationTestSet(test_set,out_dir,path_to_classify,gpu_no,layers,deployFile=deployFile,meanFile=meanFile,modelFile=modelFile,ext='jpg')
    # file_name=script_nearestNeigbourExperiment.runClassificationTestSet(test_set,out_dir,path_to_classify,gpu_no,layers,ext='jpg')
    file_name = os.path.join(out_dir, '20151027204114')
    test_set, _ = pickle.load(open(file_name + '.p', 'rb'))
    vals = np.load(file_name + '.npz')

    test_set = sorted(test_set, key=lambda x: x[0])
    test_set = zip(*test_set)

    img_paths = list(test_set[0])
    gt_labels = list(test_set[1])

    numberOfN = 5

    # file_name_alt='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203004'
    for layer in layers:
        print layer
        file_name_l = file_name + '_' + layer
        # indices,conf_matrix=script_nearestNeigbourExperiment.doNN(img_paths,gt_labels,vals[layer],numberOfN=numberOfN,distance='cosine',algo='brute')
        # pickle.dump([img_paths,gt_labels,indices,conf_matrix],open(file_name_l+'.p','wb'));
        [img_paths, gt_labels, indices,
         _] = pickle.load(open(file_name_l + '.p', 'rb'))

        idx_sort_binned = script_nearestNeigbourExperiment.sortByPerformance(
            indices, gt_labels, 0, perClass=True)

        img_paths = [x.replace('/disk2', '../../../../..') for x in img_paths]
        im_paths, captions = visualize.createImageAndCaptionGrid(
            img_paths, gt_labels, indices, dirs)
        im_paths = [im_paths[idx] for idx in idx_sort_binned]
        captions = [captions[idx] for idx in idx_sort_binned]

        visualize.writeHTML(file_name_l + '_sorted.html', im_paths, captions)

    return
    path_to_anno = '/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations'
    path_to_im = '/disk2/pascal_3d/PASCAL3D+_release1.0/Images'
    dirs = [dir for dir in os.listdir(path_to_anno) if dir.endswith('pascal')]

    out_dir = '/disk2/pascal_3d/PASCAL3D+_release1.0/Images_BB'
    if not os.path.exists(out_dir):
        os.mkdir(out_dir)

    for dir in dirs:
        file_names = [
            os.path.join(dir, file_name)[:-4]
            for file_name in os.listdir(os.path.join(path_to_im, dir))
            if file_name.endswith('.jpg')
        ]
        saveBBImages(path_to_im, path_to_anno, file_names, out_dir)
コード例 #4
0
ファイル: pascal_3d.py プロジェクト: maheenRashid/caffe
def main():
    train_file='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/trained/20151027204114'
    non_train_file='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203547'
    layers=['pool5','fc6','fc7'];
    out_dir='/disk2/octoberExperiments/nn_pascal3d'
    db_file=os.path.join(out_dir,'nn_pascal3d_new.db');
    if not os.path.exists(out_dir):
        os.mkdir(out_dir);

    path_to_anno='/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations';
    class_ids=[dir[:-7] for dir in os.listdir(path_to_anno) if dir.endswith('pascal')];

    file_pre=train_file
    trainFlag=True
    caffe_model='/home/maheenrashid/Downloads/caffe/caffe-rc2/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'
    
    # exceptions=script_populateDB(db_file,file_pre,trainFlag,layers,class_ids,caffe_model)
    # for ex in exceptions:
    #     print len(ex)
    # pickle.dump([exceptions],open(file_pre+'_db_exceptions.p','wb'));

    file_pre=non_train_file
    trainFlag=False
    caffe_model='/disk2/octoberExperiments/nn_performance_without_pascal/snapshot_iter_450000.caffemodel'
    script_populateDB(db_file,file_pre,trainFlag,layers,class_ids,caffe_model)

    return
    script_saveIndicesAll(train_file,layers);
    script_saveIndicesAll(non_train_file,layers);
    # script_testingDoNN();


    return
    script_createHistComparative();
    # script_createHistsWithSpecificAngle()
    return
    script_createHistComparative()
    # script_createHistDifferenceHTML()
    # script_savePerClassPerDegreeHistograms()
    return
    script_visualizePerClassAzimuthPerformance();
    return
    train_file='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/trained/20151027204114'
    non_train_file='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203547'
    layers=['pool5','fc6','fc7'];
    path_to_anno='/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations'

    for file_name in [train_file,non_train_file]:
        [img_paths,gt_labels,azimuths]=pickle.load(open(file_name+'_azimuths.p','rb'));
        for layer in layers:
            print layer;
            file_name_l=file_name+'_'+layer+'_all';
            out_file=file_name_l+'_azimuths.p';

            t=time.time()
            [img_paths,gt_labels,indices,_]=pickle.load(open(file_name_l+'.p','rb'));
            t=time.time()-t
            print t
            # raw_input();
            
            diffs_all,dists_all=getAzimuthInfo(img_paths,gt_labels,indices,azimuths)
            pickle.dump([img_paths,gt_labels,azimuths,diffs_all,dists_all],open(out_file,'wb'));

    return    
    text_labels=[dir[:-7] for dir in os.listdir(path_to_anno) if dir.endswith('pascal')];
    for file_name in [train_file,non_train_file]:
        [img_paths,gt_labels,azimuths]=pickle.load(open(file_name+'_azimuths.p','rb'));
        for layer in layers:
            print layer;
            file_name_l=file_name+'_'+layer+'_all';
            out_dir=file_name_l+'_azimuths';
            if not os.path.exists(out_dir):
                os.mkdir(out_dir);
            t=time.time()
            [img_paths,gt_labels,indices,_]=pickle.load(open(file_name_l+'.p','rb'));
            t=time.time()-t
            print t
            # raw_input();
            createAzimuthGraphs(img_paths,gt_labels,indices,azimuths,out_dir,text_labels)

    for layer in layers:
        print layer
        out_file='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/azimuths_'+layer+'_all'+'_comparison.html';
        rel_train='trained/20151027204114_'+layer+'_all'+'_azimuths'
        rel_notrain='no_trained/20151027203547_'+layer+'_all'+'_azimuths';
        out_dir='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203547_'+layer+'_all'+'_azimuths'

        im_paths=[[os.path.join(rel_train,file_curr),os.path.join(rel_notrain,file_curr)] for file_curr in os.listdir(out_dir) if file_curr.endswith('.jpg')];
        
        captions=[['train','no_train']]*len(im_paths);
        visualize.writeHTML(out_file,im_paths,captions,height=500,width=500)


    # script_saveAzimuthInfo(train_file,path_to_anno);
    # script_saveAzimuthInfo(non_train_file,path_to_anno);
    # script_saveIndicesAll(train_file,layers)
    # script_saveIndicesAll(non_train_file,layers)

    return
    out_dir='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d';
    if not os.path.exists(out_dir):
        os.mkdir(out_dir);
    # out_dir=os.path.join(out_dir,'no_trained');
    out_dir=os.path.join(out_dir,'trained');
    if not os.path.exists(out_dir):
        os.mkdir(out_dir);

    path_to_anno='/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations';
    file_dir='/disk2/pascal_3d/PASCAL3D+_release1.0/Images_BB';
    dirs=[dir[:-7] for dir in os.listdir(path_to_anno) if dir.endswith('pascal')];
    test_set=[];
    for dir_idx,dir in enumerate(dirs):
        ims=[filename for filename in glob.glob(file_dir + '/*'+dir+'*.jpg')]
        test_set.extend(zip(ims,[dir_idx]*len(ims)));
    
    print len(test_set);

    layers=['pool5','fc6','fc7'];
    gpu_no=1
    path_to_classify='..';
    numberOfN=5
    relativePaths=['/disk2','../../../../..'];
    deployFile='/disk2/octoberExperiments/nn_performance_without_pascal/deploy.prototxt'
    meanFile='/disk2/octoberExperiments/nn_performance_without_pascal/mean.npy'
    modelFile='/disk2/octoberExperiments/nn_performance_without_pascal/snapshot_iter_450000.caffemodel'
    # file_name=script_nearestNeigbourExperiment.runClassificationTestSet(test_set,out_dir,path_to_classify,gpu_no,layers,deployFile=deployFile,meanFile=meanFile,modelFile=modelFile,ext='jpg')
    # file_name=script_nearestNeigbourExperiment.runClassificationTestSet(test_set,out_dir,path_to_classify,gpu_no,layers,ext='jpg')
    file_name=os.path.join(out_dir,'20151027204114');
    test_set,_=pickle.load(open(file_name+'.p','rb'));
    vals=np.load(file_name+'.npz');

    test_set=sorted(test_set,key=lambda x: x[0])
    test_set=zip(*test_set);
    
    img_paths=list(test_set[0]);
    gt_labels=list(test_set[1]);
    
    numberOfN=5;


    # file_name_alt='/disk2/octoberExperiments/nn_performance_without_pascal/pascal_3d/no_trained/20151027203004'
    for layer in layers:
        print layer
        file_name_l=file_name+'_'+layer;
        # indices,conf_matrix=script_nearestNeigbourExperiment.doNN(img_paths,gt_labels,vals[layer],numberOfN=numberOfN,distance='cosine',algo='brute')
        # pickle.dump([img_paths,gt_labels,indices,conf_matrix],open(file_name_l+'.p','wb'));
        [img_paths,gt_labels,indices,_]=pickle.load(open(file_name_l+'.p','rb'));
        
        idx_sort_binned=script_nearestNeigbourExperiment.sortByPerformance(indices,gt_labels,0,perClass=True);

        img_paths=[x.replace('/disk2','../../../../..') for x in img_paths];
        im_paths,captions=visualize.createImageAndCaptionGrid(img_paths,gt_labels,indices,dirs)
        im_paths=[im_paths[idx] for idx in idx_sort_binned];
        captions=[captions[idx] for idx in idx_sort_binned];

        visualize.writeHTML(file_name_l+'_sorted.html',im_paths,captions)





    return
    path_to_anno='/disk2/pascal_3d/PASCAL3D+_release1.0/Annotations';
    path_to_im='/disk2/pascal_3d/PASCAL3D+_release1.0/Images';
    dirs=[dir for dir in os.listdir(path_to_anno) if dir.endswith('pascal')];
    
    out_dir='/disk2/pascal_3d/PASCAL3D+_release1.0/Images_BB';
    if not os.path.exists(out_dir):
        os.mkdir(out_dir);
    
    for dir in dirs:
        file_names=[os.path.join(dir,file_name)[:-4] for file_name in os.listdir(os.path.join(path_to_im,dir)) if file_name.endswith('.jpg')];
        saveBBImages(path_to_im,path_to_anno,file_names,out_dir);