Example #1
0
def script_testingDoNN():
    img_paths=[];
    numberOfSamples=100;
    featureVectorLength=10;
    numberOfClasses=5;
    gt_labels=np.random.random_integers(0,numberOfClasses-1,(numberOfSamples,));
    
    features_curr=np.random.random_integers(-100,100,(numberOfSamples,featureVectorLength));
    features_curr=np.array(features_curr,dtype=float);
    numberOfN=5;
    
    indices=script_nearestNeigbourExperiment.doNN(img_paths,gt_labels,features_curr,numberOfN=numberOfN)    
    print indices.shape==(numberOfSamples,numberOfN);
    
    numberOfN=None
    indices=script_nearestNeigbourExperiment.doNN(img_paths,gt_labels,features_curr,numberOfN=numberOfN)
    print indices.shape==(numberOfSamples,numberOfSamples);
    
    indices,conf_matrix=script_nearestNeigbourExperiment.doNN(img_paths,gt_labels,features_curr,numberOfN=numberOfN,conf_matrix_return=True)
    print conf_matrix.shape==(numberOfClasses,numberOfClasses)
    
    indices,distances=script_nearestNeigbourExperiment.doNN(img_paths,gt_labels,features_curr,numberOfN=numberOfN,conf_matrix_return=False,distances_return=True)
    print distances.shape==indices.shape==(numberOfSamples,numberOfSamples);

    indices,conf_matrix,distances=script_nearestNeigbourExperiment.doNN(img_paths,gt_labels,features_curr,numberOfN=numberOfN,conf_matrix_return=True,distances_return=True)
    print conf_matrix.shape==(numberOfClasses,numberOfClasses)
    print distances.shape==indices.shape==(numberOfSamples,numberOfSamples);
    plt.figure();
    plt.plot(distances[0]);
    plt.plot(distances[numberOfSamples-1]);
    plt.savefig('/disk2/temp/checkNN.png');
    plt.close();
Example #2
0
def script_saveNNDistances(file_name,layers):
    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=None;
    for layer in layers:
        file_name_l=file_name+'_'+layer+'_all_distances';
        indices,conf_matrix=script_nearestNeigbourExperiment.doNN(img_paths,gt_labels,vals[layer],numberOfN=numberOfN,distance='cosine',algo='brute',conf_matrix=False,distances=True)

        pickle.dump([img_paths,gt_labels,indices,conf_matrix],open(file_name_l+'.p','wb'));