In [4]:
import matplotlib.pyplot as plt
import numpy
import csv
# Change the path to csv file appropriately
beaver_positive_csv = '/Users/ishanhanda/Documents/NYU_Fall16/Comp_Vision/Project/ProjectWorkspace/DataSets/OUTPUTS/Beaver_aug.csv'
beaver_negative_csv = '/Users/ishanhanda/Documents/NYU_Fall16/Comp_Vision/Project/ProjectWorkspace/DataSets/OUTPUTS/Beaver_neg_aug.csv'
beaver_positive_augmented_csv = '/Users/ishanhanda/Documents/NYU_Fall16/Comp_Vision/Project/ProjectWorkspace/DataSets/OUTPUTS/Beaver_aug_rotated.csv'
beaver_negative_augmented_csv = '/Users/ishanhanda/Documents/NYU_Fall16/Comp_Vision/Project/ProjectWorkspace/DataSets/OUTPUTS/Beaver_neg_aug_rotated.csv'
print('Beaver Positive Images Test Results\n')
reader = csv.reader(open(beaver_positive_csv,"rt"))
temp = list(reader)
positive_data = numpy.array(temp).astype('float').flatten()
positive_length = len(positive_data)
print('\nBeaver positive test samples count: {}'.format(positive_length))
print('\n\nBeaver Negative Images Test Results\n')
reader = csv.reader(open(beaver_negative_csv,"rt"))
temp = list(reader)
negative_data = numpy.array(temp).astype('float').flatten()
negative_length = len(negative_data)
print('\nBeaver negative test samples count: {}'.format(negative_length))
# Augmented data
print('Beaver Positive Augmented Images Test Results\n')
reader = csv.reader(open(beaver_positive_augmented_csv,"rt"))
temp = list(reader)
positive_augmented_data = numpy.array(temp).astype('float').flatten()
positive_augmented_length = len(positive_augmented_data)
print('\nBeaver positive test Augmented samples count: {}'.format(positive_length))
print('\n\nBeaver Negative Augmented Images Test Results\n')
reader = csv.reader(open(beaver_negative_augmented_csv,"rt"))
temp = list(reader)
negative_augmented_data = numpy.array(temp).astype('float').flatten()
negative_augmented_length = len(negative_augmented_data)
print('\nBeaver negative test Augmented samples count: {}'.format(negative_length))
In [12]:
# Here we are defining preset threshold levels for which TPR and FPR values will be calculated
thresholds = numpy.arange(0.0,1.0,0.005)
print('Thresholds: {}'.format(thresholds))
Now calculating TPR and FNR for the first positive test
In [14]:
import pylab
TPRs = [None] * len(thresholds)
FPRs = [None] * len(thresholds)
TPRs_aug = [None] * len(thresholds)
FPRs_aug = [None] * len(thresholds)
for i in range(0, len(thresholds)):
test_positive = positive_data[positive_data >= thresholds[i]]
tpr = len(test_positive) / len(positive_data)
TPRs[i] = tpr # This is the calculated TPR value for threshold level i in sample j
test_negative = negative_data[negative_data >= thresholds[i]]
fpr = len(test_negative) / len(negative_data)
FPRs[i] = fpr # This is the calculated FPR value for threshold level i in sample j
test_positive_aug = positive_augmented_data[positive_augmented_data >= thresholds[i]]
tpr_a = len(test_positive_aug) / len(positive_augmented_data)
TPRs_aug[i] = tpr_a # This is the calculated TPR value for threshold level i in sample j
test_negative_aug = negative_augmented_data[negative_augmented_data >= thresholds[i]]
fpr_a = len(test_negative_aug) / len(negative_augmented_data)
FPRs_aug[i] = fpr_a # This is the calculated FPR value for threshold level i in sample j
print('\n\nPLOTTING ROC')
fig = plt.figure(figsize=(10,8))
p1 = plt.scatter(FPRs, TPRs, color='red', s=5)
plt.plot(FPRs, TPRs, color='red')
p2 = plt.scatter(FPRs_aug, TPRs_aug, color='green', s=5)
plt.plot(FPRs_aug, TPRs_aug, color='green')
plt.xticks(numpy.arange(0, 1.1, 0.1))
plt.yticks(numpy.arange(0, 1.1, 0.1))
plt.legend((p1, p2), ('Original', 'Augmented'))
plt.grid()
plt.ylabel('TPR')
plt.xlabel('FPR')
plt.title('Augmented Vs Original ROC')
pylab.savefig('Rotation_augmetended_ROC.png')
plt.show()
In [7]:
beaver_sift_positive_csv = '/Users/ishanhanda/Documents/NYU_Fall16/Comp_Vision/Project/ProjectWorkspace/DataSets/OUTPUTS/Beaver_sift_positive.csv'
beaver_sift_negative_csv = '/Users/ishanhanda/Documents/NYU_Fall16/Comp_Vision/Project/ProjectWorkspace/DataSets/OUTPUTS/Beaver_sift_negative.csv'
print('Beaver Positive Images Test Results\n')
reader = csv.reader(open(beaver_sift_positive_csv,"rt"))
temp = list(reader)
positive_sift_data = numpy.array(temp).astype('float').flatten()
positive_sift_length = len(positive_sift_data)
print('\nBeaver positive test samples count: {}'.format(positive_sift_length))
print('\n\nBeaver Negative Images Test Results\n')
reader = csv.reader(open(beaver_sift_negative_csv,"rt"))
temp = list(reader)
negative_sift_data = numpy.array(temp).astype('float').flatten()
negative_sift_length = len(negative_sift_data)
print('\nBeaver negative test samples count: {}'.format(negative_sift_length))
In [15]:
TPRs_sift = [None] * len(thresholds)
FPRs_sift = [None] * len(thresholds)
for i in range(0, len(thresholds)):
test_positive = positive_sift_data[positive_sift_data >= thresholds[i]]
tpr = len(test_positive) / len(positive_sift_data)
TPRs_sift[i] = tpr # This is the calculated TPR value for threshold level i in sample j
test_negative = negative_sift_data[negative_sift_data >= thresholds[i]]
fpr = len(test_negative) / len(negative_sift_data)
FPRs_sift[i] = fpr # This is the calculated FPR value for threshold level i in sample j
print('\n\nPLOTTING ROC')
fig = plt.figure(figsize=(10,8))
p1 = plt.scatter(FPRs, TPRs, color='red', s=5)
plt.plot(FPRs, TPRs, color='red')
p2 = plt.scatter(FPRs_sift, TPRs_sift, color='green', s=5)
plt.plot(FPRs_sift, TPRs_sift, color='green')
plt.xticks(numpy.arange(0, 1.1, 0.1))
plt.yticks(numpy.arange(0, 1.1, 0.1))
plt.legend((p1, p2), ('IBM Watson VR', 'Sift Matching'))
plt.grid()
plt.ylabel('TPR')
plt.xlabel('FPR')
plt.title('IBM Watson VR Sift Matching ROC')
pylab.savefig('Sift_Vs_IBM_VR.png')
plt.show()
In [ ]: