add evaluation framework and imagenet evaluation (#69)
Browse files- README.md +11 -1
- ppresnet.py +22 -7
README.md
CHANGED
@@ -4,6 +4,15 @@ Deep Residual Learning for Image Recognition
|
|
4 |
|
5 |
This model is ported from [PaddleHub](https://github.com/PaddlePaddle/PaddleHub) using [this script from OpenCV](https://github.com/opencv/opencv/blob/master/samples/dnn/dnn_model_runner/dnn_conversion/paddlepaddle/paddle_resnet50.py).
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
## Demo
|
8 |
|
9 |
Run the following command to try the demo:
|
@@ -19,4 +28,5 @@ All files in this directory are licensed under [Apache 2.0 License](./LICENSE).
|
|
19 |
|
20 |
- https://arxiv.org/abs/1512.03385
|
21 |
- https://github.com/opencv/opencv/tree/master/samples/dnn/dnn_model_runner/dnn_conversion/paddlepaddle
|
22 |
-
- https://github.com/PaddlePaddle/PaddleHub
|
|
|
|
4 |
|
5 |
This model is ported from [PaddleHub](https://github.com/PaddlePaddle/PaddleHub) using [this script from OpenCV](https://github.com/opencv/opencv/blob/master/samples/dnn/dnn_model_runner/dnn_conversion/paddlepaddle/paddle_resnet50.py).
|
6 |
|
7 |
+
Results of accuracy evaluation with [tools/eval](../../tools/eval).
|
8 |
+
|
9 |
+
| Models | Top-1 Accuracy | Top-5 Accuracy |
|
10 |
+
| ------ | -------------- | -------------- |
|
11 |
+
| PP-ResNet | 82.28 | 96.15 |
|
12 |
+
| PP-ResNet quant | 0.22 | 0.96 |
|
13 |
+
|
14 |
+
\*: 'quant' stands for 'quantized'.
|
15 |
+
|
16 |
## Demo
|
17 |
|
18 |
Run the following command to try the demo:
|
|
|
28 |
|
29 |
- https://arxiv.org/abs/1512.03385
|
30 |
- https://github.com/opencv/opencv/tree/master/samples/dnn/dnn_model_runner/dnn_conversion/paddlepaddle
|
31 |
+
- https://github.com/PaddlePaddle/PaddleHub
|
32 |
+
|
ppresnet.py
CHANGED
@@ -9,9 +9,11 @@ import numpy as np
|
|
9 |
import cv2 as cv
|
10 |
|
11 |
class PPResNet:
|
12 |
-
def __init__(self, modelPath, labelPath, backendId=0, targetId=0):
|
13 |
self._modelPath = modelPath
|
14 |
self._labelPath = labelPath
|
|
|
|
|
15 |
self._backendId = backendId
|
16 |
self._targetId = targetId
|
17 |
|
@@ -30,9 +32,10 @@ class PPResNet:
|
|
30 |
|
31 |
def _load_labels(self):
|
32 |
labels = []
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
36 |
return labels
|
37 |
|
38 |
@property
|
@@ -65,11 +68,23 @@ class PPResNet:
|
|
65 |
outputBlob = self._model.forward(self._outputNames)
|
66 |
|
67 |
# Postprocess
|
68 |
-
results = self._postprocess(outputBlob)
|
69 |
|
70 |
return results
|
71 |
|
72 |
def _postprocess(self, outputBlob):
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
|
|
9 |
import cv2 as cv
|
10 |
|
11 |
class PPResNet:
|
12 |
+
def __init__(self, modelPath, labelPath=None, topK=1, backendId=0, targetId=0):
|
13 |
self._modelPath = modelPath
|
14 |
self._labelPath = labelPath
|
15 |
+
assert topK >= 1
|
16 |
+
self._topK = topK
|
17 |
self._backendId = backendId
|
18 |
self._targetId = targetId
|
19 |
|
|
|
32 |
|
33 |
def _load_labels(self):
|
34 |
labels = []
|
35 |
+
if self._labelPath is not None:
|
36 |
+
with open(self._labelPath, 'r') as f:
|
37 |
+
for line in f:
|
38 |
+
labels.append(line.strip())
|
39 |
return labels
|
40 |
|
41 |
@property
|
|
|
68 |
outputBlob = self._model.forward(self._outputNames)
|
69 |
|
70 |
# Postprocess
|
71 |
+
results = self._postprocess(outputBlob[0])
|
72 |
|
73 |
return results
|
74 |
|
75 |
def _postprocess(self, outputBlob):
|
76 |
+
batched_class_id_list = []
|
77 |
+
for ob in outputBlob:
|
78 |
+
class_id_list = ob.argsort()[::-1][:self._topK]
|
79 |
+
batched_class_id_list.append(class_id_list)
|
80 |
+
if len(self._labels) > 0:
|
81 |
+
batched_predicted_labels = []
|
82 |
+
for class_id_list in batched_class_id_list:
|
83 |
+
predicted_labels = []
|
84 |
+
for class_id in class_id_list:
|
85 |
+
predicted_labels.append(self._labels[class_id])
|
86 |
+
batched_predicted_labels.append(predicted_labels)
|
87 |
+
return batched_predicted_labels
|
88 |
+
else:
|
89 |
+
return batched_class_id_list
|
90 |
|