In [1]:
from Tools import get_image_path, visualize_annotations, \
visualize_prediction, load_prediction_txt, \
evaluate, precision_recall_11points, recall_FPPI
In [2]:
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = (15, 15)
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray' # use grayscale output rather than a (potentially misleading) color heatmap
In [3]:
image_id = 27
print get_image_path(image_id)
plt.subplot(2,1,1)
visualize_annotations(image_id, vehicle_shape='ellipse')
plt.subplot(2,1,2)
visualize_annotations(image_id, vehicle_shape='polygon', image_type='ir')
In [4]:
prediction = load_prediction_txt('example_det_results/car_01.txt')
In [5]:
# Because the example detection result is made for MATLAB, the left-top pixel for the result is (1, 1).
# So let's convert it into python/C/C++ style
# If your own prediction file is already in python/C/C++ style, i.e. the left-top pixel is (0, 0), you should skip this step.
prediction['x'] -= 1
prediction['y'] -= 1
In [6]:
visualize_prediction(image_id, prediction, thres=0.0, vehicle_marker='D', verbose=True)
We can even make a collision detection!
In [7]:
# (Optional) Firstly let's show the annotations.
visualize_annotations(image_id, vehicle_shape='ellipse')
# And then visualize detection results.
visualize_prediction(image_id, prediction, thres=-0.5, vehicle_marker='D', collision_detection=True)
The example result files are made for MATLAB. So the index starts from 1 instead of 0. So "car_01.txt" is actually for fold 0 here.
In [8]:
eval_results= evaluate(prediction, 'car', fold=0)
If you see a SettingWithCopyWarning
here, please just ignore it.
The results are recorded in a pandas DataFrame, including precision vs. recall vs. FPPI.
Let's show it below:
In [9]:
eval_results.head(10)
Out[9]:
In [10]:
plt.rcParams['figure.figsize'] = (5, 5)
In [11]:
eval_results.plot(y='precision', x='recall', grid=True)
Out[11]:
In [12]:
precisions, recalls, ap = precision_recall_11points(eval_results)
In [13]:
plt.figure()
plt.plot(recalls, precisions, marker='+')
plt.grid()
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.ylabel('Precision')
plt.xlabel('Recall')
plt.title('Precision-Recall Curve')
print 'AP:', ap
In [14]:
eval_results.plot(x='FPPI', y='recall', logx=True, grid=True)
Out[14]:
In [15]:
recalls, FPPIs = recall_FPPI(eval_results)
In [16]:
for fppi, recall in zip(FPPIs, recalls):
print 'FPPI: {}\tRecall:{}'.format(fppi, recall)
In [ ]: