Yuantao Feng
commited on
Commit
·
e0b3895
1
Parent(s):
9d96bb5
Add PPResNet from PaddleHub conversion (#4)
Browse files* add PPResNet impl and demo
* add benchmark impl and results for PPResNet
- README.md +3 -2
- benchmark/benchmark.py +29 -8
- benchmark/config/image_classification_ppresnet.yaml +20 -0
- benchmark/download_data.py +4 -0
- models/__init__.py +3 -1
- models/image_classification_ppresnet/LICENSE +203 -0
- models/image_classification_ppresnet/README.md +22 -0
- models/image_classification_ppresnet/demo.py +41 -0
- models/image_classification_ppresnet/imagenet_labels.txt +1000 -0
- models/image_classification_ppresnet/ppresnet.py +67 -0
README.md
CHANGED
@@ -16,8 +16,8 @@ Hardware Setup:
|
|
16 |
-->
|
17 |
|
18 |
***Important Notes***:
|
19 |
-
- The time data that shown on the following
|
20 |
-
- The time data that shown on the following
|
21 |
- View [benchmark/config](./benchmark/config) for more details on benchmarking different models.
|
22 |
|
23 |
<!--
|
@@ -33,6 +33,7 @@ Hardware Setup:
|
|
33 |
| [DB](./models/text_detection_db) | 640x480 | 137.38 | 2780.78 |
|
34 |
| [CRNN](./models/text_recognition_crnn) | 100x32 | 50.21 | 234.32 |
|
35 |
| [SFace](./models/face_recognition_sface) | 112x112 | 8.69 | 96.79 |
|
|
|
36 |
|
37 |
|
38 |
## License
|
|
|
16 |
-->
|
17 |
|
18 |
***Important Notes***:
|
19 |
+
- The time data that shown on the following table presents the time elapsed from preprocess (resize is excluded), to a forward pass of a network, and postprocess to get final results.
|
20 |
+
- The time data that shown on the following table is the median of 10 runs. Different metrics may be applied to some specific models.
|
21 |
- View [benchmark/config](./benchmark/config) for more details on benchmarking different models.
|
22 |
|
23 |
<!--
|
|
|
33 |
| [DB](./models/text_detection_db) | 640x480 | 137.38 | 2780.78 |
|
34 |
| [CRNN](./models/text_recognition_crnn) | 100x32 | 50.21 | 234.32 |
|
35 |
| [SFace](./models/face_recognition_sface) | 112x112 | 8.69 | 96.79 |
|
36 |
+
| [PP-ResNet](./models/image_classification_ppresnet) | 224x224 | 56.05 | 602.58
|
37 |
|
38 |
|
39 |
## License
|
benchmark/benchmark.py
CHANGED
@@ -75,6 +75,10 @@ class Data:
|
|
75 |
if self._use_label:
|
76 |
self._labels = self._load_label()
|
77 |
|
|
|
|
|
|
|
|
|
78 |
def _load_label(self):
|
79 |
labels = dict.fromkeys(self._files, None)
|
80 |
for filename in self._files:
|
@@ -83,6 +87,19 @@ class Data:
|
|
83 |
|
84 |
def __getitem__(self, idx):
|
85 |
image = cv.imread(os.path.join(self._path, self._files[idx]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
if self._use_label:
|
87 |
return self._files[idx], image, self._labels[self._files[idx]]
|
88 |
else:
|
@@ -113,7 +130,10 @@ class Metric:
|
|
113 |
if len(args) == 1:
|
114 |
for size in self._sizes:
|
115 |
img_r = cv.resize(img, size)
|
116 |
-
|
|
|
|
|
|
|
117 |
# TODO: batched inference
|
118 |
# input_data = [img] * self._batch_size
|
119 |
input_data = img_r
|
@@ -192,11 +212,13 @@ def build_from_cfg(cfg, registery):
|
|
192 |
obj = registery.get(obj_name)
|
193 |
return obj(**cfg)
|
194 |
|
195 |
-
def prepend_pythonpath(cfg
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
200 |
|
201 |
if __name__ == '__main__':
|
202 |
assert args.cfg.endswith('yaml'), 'Currently support configs of yaml format only.'
|
@@ -204,8 +226,7 @@ if __name__ == '__main__':
|
|
204 |
cfg = yaml.safe_load(f)
|
205 |
|
206 |
# prepend PYTHONPATH to each path
|
207 |
-
prepend_pythonpath(cfg
|
208 |
-
prepend_pythonpath(cfg, key1='Model', key2='modelPath')
|
209 |
|
210 |
# Instantiate benchmarking
|
211 |
benchmark = Benchmark(**cfg['Benchmark'])
|
|
|
75 |
if self._use_label:
|
76 |
self._labels = self._load_label()
|
77 |
|
78 |
+
self._to_rgb = kwargs.pop('toRGB', False)
|
79 |
+
self._resize = tuple(kwargs.pop('resize', []))
|
80 |
+
self._center_crop = kwargs.pop('centerCrop', None)
|
81 |
+
|
82 |
def _load_label(self):
|
83 |
labels = dict.fromkeys(self._files, None)
|
84 |
for filename in self._files:
|
|
|
87 |
|
88 |
def __getitem__(self, idx):
|
89 |
image = cv.imread(os.path.join(self._path, self._files[idx]))
|
90 |
+
|
91 |
+
if self._to_rgb:
|
92 |
+
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
|
93 |
+
if self._resize:
|
94 |
+
image = cv.resize(image, self._resize)
|
95 |
+
if self._center_crop:
|
96 |
+
h, w, _ = image.shape
|
97 |
+
w_crop = int((w - self._center_crop) / 2.)
|
98 |
+
assert w_crop >= 0
|
99 |
+
h_crop = int((h - self._center_crop) / 2.)
|
100 |
+
assert h_crop >= 0
|
101 |
+
image = image[w_crop:w-w_crop, h_crop:h-h_crop, :]
|
102 |
+
|
103 |
if self._use_label:
|
104 |
return self._files[idx], image, self._labels[self._files[idx]]
|
105 |
else:
|
|
|
130 |
if len(args) == 1:
|
131 |
for size in self._sizes:
|
132 |
img_r = cv.resize(img, size)
|
133 |
+
try:
|
134 |
+
model.setInputSize(size)
|
135 |
+
except:
|
136 |
+
pass
|
137 |
# TODO: batched inference
|
138 |
# input_data = [img] * self._batch_size
|
139 |
input_data = img_r
|
|
|
212 |
obj = registery.get(obj_name)
|
213 |
return obj(**cfg)
|
214 |
|
215 |
+
def prepend_pythonpath(cfg):
|
216 |
+
for k, v in cfg.items():
|
217 |
+
if isinstance(v, dict):
|
218 |
+
prepend_pythonpath(v)
|
219 |
+
else:
|
220 |
+
if 'path' in k.lower():
|
221 |
+
cfg[k] = os.path.join(os.environ['PYTHONPATH'], v)
|
222 |
|
223 |
if __name__ == '__main__':
|
224 |
assert args.cfg.endswith('yaml'), 'Currently support configs of yaml format only.'
|
|
|
226 |
cfg = yaml.safe_load(f)
|
227 |
|
228 |
# prepend PYTHONPATH to each path
|
229 |
+
prepend_pythonpath(cfg)
|
|
|
230 |
|
231 |
# Instantiate benchmarking
|
232 |
benchmark = Benchmark(**cfg['Benchmark'])
|
benchmark/config/image_classification_ppresnet.yaml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Benchmark:
|
2 |
+
name: "Image Classification Benchmark"
|
3 |
+
data:
|
4 |
+
path: "benchmark/data/image_classification"
|
5 |
+
files: ["coffee_mug.jpg", "umbrella.jpg", "wall_clock.jpg"]
|
6 |
+
toRGB: True
|
7 |
+
resize: [256, 256]
|
8 |
+
centerCrop: 224
|
9 |
+
metric:
|
10 |
+
warmup: 3
|
11 |
+
repeat: 10
|
12 |
+
batchSize: 1
|
13 |
+
reduction: 'median'
|
14 |
+
backend: "default"
|
15 |
+
target: "cpu"
|
16 |
+
|
17 |
+
Model:
|
18 |
+
name: "PPResNet"
|
19 |
+
modelPath: "models/image_classification_ppresnet/image_classification_ppresnet50.onnx"
|
20 |
+
labelPath: "models/image_classification_ppresnet/imagenet_labels.txt"
|
benchmark/download_data.py
CHANGED
@@ -173,6 +173,10 @@ data_downloaders = dict(
|
|
173 |
url='https://drive.google.com/u/0/uc?id=1lTQdZUau7ujHBqp0P6M1kccnnJgO-dRj&export=download',
|
174 |
sha='a40cf095ceb77159ddd2a5902f3b4329696dd866',
|
175 |
filename='text.zip'),
|
|
|
|
|
|
|
|
|
176 |
)
|
177 |
|
178 |
if __name__ == '__main__':
|
|
|
173 |
url='https://drive.google.com/u/0/uc?id=1lTQdZUau7ujHBqp0P6M1kccnnJgO-dRj&export=download',
|
174 |
sha='a40cf095ceb77159ddd2a5902f3b4329696dd866',
|
175 |
filename='text.zip'),
|
176 |
+
image_classification=Downloader(name='image_classification',
|
177 |
+
url='https://drive.google.com/u/0/uc?id=1qcsrX3CIAGTooB-9fLKYwcvoCuMgjzGU&export=download',
|
178 |
+
sha='987546f567f9f11d150eea78951024b55b015401',
|
179 |
+
filename='image_classification.zip'),
|
180 |
)
|
181 |
|
182 |
if __name__ == '__main__':
|
models/__init__.py
CHANGED
@@ -2,6 +2,7 @@ from .face_detection_yunet.yunet import YuNet
|
|
2 |
from .text_detection_db.db import DB
|
3 |
from .text_recognition_crnn.crnn import CRNN
|
4 |
from .face_recognition_sface.sface import SFace
|
|
|
5 |
|
6 |
class Registery:
|
7 |
def __init__(self, name):
|
@@ -18,4 +19,5 @@ MODELS = Registery('Models')
|
|
18 |
MODELS.register(YuNet)
|
19 |
MODELS.register(DB)
|
20 |
MODELS.register(CRNN)
|
21 |
-
MODELS.register(SFace)
|
|
|
|
2 |
from .text_detection_db.db import DB
|
3 |
from .text_recognition_crnn.crnn import CRNN
|
4 |
from .face_recognition_sface.sface import SFace
|
5 |
+
from .image_classification_ppresnet.ppresnet import PPResNet
|
6 |
|
7 |
class Registery:
|
8 |
def __init__(self, name):
|
|
|
19 |
MODELS.register(YuNet)
|
20 |
MODELS.register(DB)
|
21 |
MODELS.register(CRNN)
|
22 |
+
MODELS.register(SFace)
|
23 |
+
MODELS.register(PPResNet)
|
models/image_classification_ppresnet/LICENSE
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved
|
2 |
+
|
3 |
+
Apache License
|
4 |
+
Version 2.0, January 2004
|
5 |
+
http://www.apache.org/licenses/
|
6 |
+
|
7 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8 |
+
|
9 |
+
1. Definitions.
|
10 |
+
|
11 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
12 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
13 |
+
|
14 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
15 |
+
the copyright owner that is granting the License.
|
16 |
+
|
17 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
18 |
+
other entities that control, are controlled by, or are under common
|
19 |
+
control with that entity. For the purposes of this definition,
|
20 |
+
"control" means (i) the power, direct or indirect, to cause the
|
21 |
+
direction or management of such entity, whether by contract or
|
22 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
23 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
24 |
+
|
25 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
26 |
+
exercising permissions granted by this License.
|
27 |
+
|
28 |
+
"Source" form shall mean the preferred form for making modifications,
|
29 |
+
including but not limited to software source code, documentation
|
30 |
+
source, and configuration files.
|
31 |
+
|
32 |
+
"Object" form shall mean any form resulting from mechanical
|
33 |
+
transformation or translation of a Source form, including but
|
34 |
+
not limited to compiled object code, generated documentation,
|
35 |
+
and conversions to other media types.
|
36 |
+
|
37 |
+
"Work" shall mean the work of authorship, whether in Source or
|
38 |
+
Object form, made available under the License, as indicated by a
|
39 |
+
copyright notice that is included in or attached to the work
|
40 |
+
(an example is provided in the Appendix below).
|
41 |
+
|
42 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
43 |
+
form, that is based on (or derived from) the Work and for which the
|
44 |
+
editorial revisions, annotations, elaborations, or other modifications
|
45 |
+
represent, as a whole, an original work of authorship. For the purposes
|
46 |
+
of this License, Derivative Works shall not include works that remain
|
47 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
48 |
+
the Work and Derivative Works thereof.
|
49 |
+
|
50 |
+
"Contribution" shall mean any work of authorship, including
|
51 |
+
the original version of the Work and any modifications or additions
|
52 |
+
to that Work or Derivative Works thereof, that is intentionally
|
53 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
54 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
55 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
56 |
+
means any form of electronic, verbal, or written communication sent
|
57 |
+
to the Licensor or its representatives, including but not limited to
|
58 |
+
communication on electronic mailing lists, source code control systems,
|
59 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
60 |
+
Licensor for the purpose of discussing and improving the Work, but
|
61 |
+
excluding communication that is conspicuously marked or otherwise
|
62 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
63 |
+
|
64 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
65 |
+
on behalf of whom a Contribution has been received by Licensor and
|
66 |
+
subsequently incorporated within the Work.
|
67 |
+
|
68 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
69 |
+
this License, each Contributor hereby grants to You a perpetual,
|
70 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
71 |
+
copyright license to reproduce, prepare Derivative Works of,
|
72 |
+
publicly display, publicly perform, sublicense, and distribute the
|
73 |
+
Work and such Derivative Works in Source or Object form.
|
74 |
+
|
75 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
76 |
+
this License, each Contributor hereby grants to You a perpetual,
|
77 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
78 |
+
(except as stated in this section) patent license to make, have made,
|
79 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
80 |
+
where such license applies only to those patent claims licensable
|
81 |
+
by such Contributor that are necessarily infringed by their
|
82 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
83 |
+
with the Work to which such Contribution(s) was submitted. If You
|
84 |
+
institute patent litigation against any entity (including a
|
85 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
86 |
+
or a Contribution incorporated within the Work constitutes direct
|
87 |
+
or contributory patent infringement, then any patent licenses
|
88 |
+
granted to You under this License for that Work shall terminate
|
89 |
+
as of the date such litigation is filed.
|
90 |
+
|
91 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
92 |
+
Work or Derivative Works thereof in any medium, with or without
|
93 |
+
modifications, and in Source or Object form, provided that You
|
94 |
+
meet the following conditions:
|
95 |
+
|
96 |
+
(a) You must give any other recipients of the Work or
|
97 |
+
Derivative Works a copy of this License; and
|
98 |
+
|
99 |
+
(b) You must cause any modified files to carry prominent notices
|
100 |
+
stating that You changed the files; and
|
101 |
+
|
102 |
+
(c) You must retain, in the Source form of any Derivative Works
|
103 |
+
that You distribute, all copyright, patent, trademark, and
|
104 |
+
attribution notices from the Source form of the Work,
|
105 |
+
excluding those notices that do not pertain to any part of
|
106 |
+
the Derivative Works; and
|
107 |
+
|
108 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
109 |
+
distribution, then any Derivative Works that You distribute must
|
110 |
+
include a readable copy of the attribution notices contained
|
111 |
+
within such NOTICE file, excluding those notices that do not
|
112 |
+
pertain to any part of the Derivative Works, in at least one
|
113 |
+
of the following places: within a NOTICE text file distributed
|
114 |
+
as part of the Derivative Works; within the Source form or
|
115 |
+
documentation, if provided along with the Derivative Works; or,
|
116 |
+
within a display generated by the Derivative Works, if and
|
117 |
+
wherever such third-party notices normally appear. The contents
|
118 |
+
of the NOTICE file are for informational purposes only and
|
119 |
+
do not modify the License. You may add Your own attribution
|
120 |
+
notices within Derivative Works that You distribute, alongside
|
121 |
+
or as an addendum to the NOTICE text from the Work, provided
|
122 |
+
that such additional attribution notices cannot be construed
|
123 |
+
as modifying the License.
|
124 |
+
|
125 |
+
You may add Your own copyright statement to Your modifications and
|
126 |
+
may provide additional or different license terms and conditions
|
127 |
+
for use, reproduction, or distribution of Your modifications, or
|
128 |
+
for any such Derivative Works as a whole, provided Your use,
|
129 |
+
reproduction, and distribution of the Work otherwise complies with
|
130 |
+
the conditions stated in this License.
|
131 |
+
|
132 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
133 |
+
any Contribution intentionally submitted for inclusion in the Work
|
134 |
+
by You to the Licensor shall be under the terms and conditions of
|
135 |
+
this License, without any additional terms or conditions.
|
136 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
137 |
+
the terms of any separate license agreement you may have executed
|
138 |
+
with Licensor regarding such Contributions.
|
139 |
+
|
140 |
+
6. Trademarks. This License does not grant permission to use the trade
|
141 |
+
names, trademarks, service marks, or product names of the Licensor,
|
142 |
+
except as required for reasonable and customary use in describing the
|
143 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
144 |
+
|
145 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
146 |
+
agreed to in writing, Licensor provides the Work (and each
|
147 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
148 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
149 |
+
implied, including, without limitation, any warranties or conditions
|
150 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
151 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
152 |
+
appropriateness of using or redistributing the Work and assume any
|
153 |
+
risks associated with Your exercise of permissions under this License.
|
154 |
+
|
155 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
156 |
+
whether in tort (including negligence), contract, or otherwise,
|
157 |
+
unless required by applicable law (such as deliberate and grossly
|
158 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
159 |
+
liable to You for damages, including any direct, indirect, special,
|
160 |
+
incidental, or consequential damages of any character arising as a
|
161 |
+
result of this License or out of the use or inability to use the
|
162 |
+
Work (including but not limited to damages for loss of goodwill,
|
163 |
+
work stoppage, computer failure or malfunction, or any and all
|
164 |
+
other commercial damages or losses), even if such Contributor
|
165 |
+
has been advised of the possibility of such damages.
|
166 |
+
|
167 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
168 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
169 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
170 |
+
or other liability obligations and/or rights consistent with this
|
171 |
+
License. However, in accepting such obligations, You may act only
|
172 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
173 |
+
of any other Contributor, and only if You agree to indemnify,
|
174 |
+
defend, and hold each Contributor harmless for any liability
|
175 |
+
incurred by, or claims asserted against, such Contributor by reason
|
176 |
+
of your accepting any such warranty or additional liability.
|
177 |
+
|
178 |
+
END OF TERMS AND CONDITIONS
|
179 |
+
|
180 |
+
APPENDIX: How to apply the Apache License to your work.
|
181 |
+
|
182 |
+
To apply the Apache License to your work, attach the following
|
183 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
184 |
+
replaced with your own identifying information. (Don't include
|
185 |
+
the brackets!) The text should be enclosed in the appropriate
|
186 |
+
comment syntax for the file format. We also recommend that a
|
187 |
+
file or class name and description of purpose be included on the
|
188 |
+
same "printed page" as the copyright notice for easier
|
189 |
+
identification within third-party archives.
|
190 |
+
|
191 |
+
Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
|
192 |
+
|
193 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
194 |
+
you may not use this file except in compliance with the License.
|
195 |
+
You may obtain a copy of the License at
|
196 |
+
|
197 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
198 |
+
|
199 |
+
Unless required by applicable law or agreed to in writing, software
|
200 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
201 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
202 |
+
See the License for the specific language governing permissions and
|
203 |
+
limitations under the License.
|
models/image_classification_ppresnet/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ResNet
|
2 |
+
|
3 |
+
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:
|
10 |
+
```shell
|
11 |
+
python demo.py --input /path/to/image
|
12 |
+
```
|
13 |
+
|
14 |
+
## License
|
15 |
+
|
16 |
+
All files in this directory are licensed under [Apache 2.0 License](./LICENSE).
|
17 |
+
|
18 |
+
## Reference
|
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
|
models/image_classification_ppresnet/demo.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file is part of OpenCV Zoo project.
|
2 |
+
# It is subject to the license terms in the LICENSE file found in the same directory.
|
3 |
+
#
|
4 |
+
# Copyright (C) 2021, Shenzhen Institute of Artificial Intelligence and Robotics for Society, all rights reserved.
|
5 |
+
# Third party copyrights are property of their respective owners.
|
6 |
+
|
7 |
+
import argparse
|
8 |
+
|
9 |
+
import numpy as np
|
10 |
+
import cv2 as cv
|
11 |
+
|
12 |
+
from ppresnet import PPResNet
|
13 |
+
|
14 |
+
def str2bool(v):
|
15 |
+
if v.lower() in ['on', 'yes', 'true', 'y', 't']:
|
16 |
+
return True
|
17 |
+
elif v.lower() in ['off', 'no', 'false', 'n', 'f']:
|
18 |
+
return False
|
19 |
+
else:
|
20 |
+
raise NotImplementedError
|
21 |
+
|
22 |
+
parser = argparse.ArgumentParser(description='Deep Residual Learning for Image Recognition (https://arxiv.org/abs/1512.03385, https://github.com/PaddlePaddle/PaddleHub)')
|
23 |
+
parser.add_argument('--input', '-i', type=str, help='Path to the input image.')
|
24 |
+
parser.add_argument('--model', '-m', type=str, default='image_classification_ppresnet50.onnx', help='Path to the model.')
|
25 |
+
args = parser.parse_args()
|
26 |
+
|
27 |
+
if __name__ == '__main__':
|
28 |
+
# Instantiate ResNet
|
29 |
+
model = PPResNet(modelPath=args.model)
|
30 |
+
|
31 |
+
# Read image and get a 224x224 crop from a 256x256 resized
|
32 |
+
image = cv.imread(args.input)
|
33 |
+
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
|
34 |
+
image = cv.resize(image, dsize=(256, 256))
|
35 |
+
image = image[16:240, 16:240, :]
|
36 |
+
|
37 |
+
# Inference
|
38 |
+
result = model.infer(image)
|
39 |
+
|
40 |
+
# Print result
|
41 |
+
print('label: {}'.format(result))
|
models/image_classification_ppresnet/imagenet_labels.txt
ADDED
@@ -0,0 +1,1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ingray
|
8 |
+
cock
|
9 |
+
hen
|
10 |
+
ostrich
|
11 |
+
brambling
|
12 |
+
goldfinch
|
13 |
+
house finch
|
14 |
+
junco
|
15 |
+
indigo bunting
|
16 |
+
robin
|
17 |
+
bulbul
|
18 |
+
jay
|
19 |
+
magpie
|
20 |
+
chickadee
|
21 |
+
water ouzel
|
22 |
+
kite
|
23 |
+
bald eagle
|
24 |
+
vulture
|
25 |
+
great grey owl
|
26 |
+
European fire salamander
|
27 |
+
common newt
|
28 |
+
eft
|
29 |
+
spotted salamander
|
30 |
+
axolotl
|
31 |
+
bullfrog
|
32 |
+
tree frog
|
33 |
+
tailed frog
|
34 |
+
loggerhead
|
35 |
+
leatherback turtle
|
36 |
+
mud turtle
|
37 |
+
terrapin
|
38 |
+
box turtle
|
39 |
+
banded gecko
|
40 |
+
common iguana
|
41 |
+
American chameleon
|
42 |
+
whiptail
|
43 |
+
agama
|
44 |
+
frilled lizard
|
45 |
+
alligator lizard
|
46 |
+
Gila monster
|
47 |
+
green lizard
|
48 |
+
African chameleon
|
49 |
+
Komodo dragon
|
50 |
+
African crocodile
|
51 |
+
American alligator
|
52 |
+
triceratops
|
53 |
+
thunder snake
|
54 |
+
ringneck snake
|
55 |
+
hognose snake
|
56 |
+
green snake
|
57 |
+
king snake
|
58 |
+
garter snake
|
59 |
+
water snake
|
60 |
+
vine snake
|
61 |
+
night snake
|
62 |
+
boa constrictor
|
63 |
+
rock python
|
64 |
+
Indian cobra
|
65 |
+
green mamba
|
66 |
+
sea snake
|
67 |
+
horned viper
|
68 |
+
diamondback
|
69 |
+
sidewinder
|
70 |
+
trilobite
|
71 |
+
harvestman
|
72 |
+
scorpion
|
73 |
+
black and gold garden spider
|
74 |
+
barn spider
|
75 |
+
garden spider
|
76 |
+
black widow
|
77 |
+
tarantula
|
78 |
+
wolf spider
|
79 |
+
tick
|
80 |
+
centipede
|
81 |
+
black grouse
|
82 |
+
ptarmigan
|
83 |
+
ruffed grouse
|
84 |
+
prairie chicken
|
85 |
+
peacock
|
86 |
+
quail
|
87 |
+
partridge
|
88 |
+
African grey
|
89 |
+
macaw
|
90 |
+
sulphur-crested cockatoo
|
91 |
+
lorikeet
|
92 |
+
coucal
|
93 |
+
bee eater
|
94 |
+
hornbill
|
95 |
+
hummingbird
|
96 |
+
jacamar
|
97 |
+
toucan
|
98 |
+
drake
|
99 |
+
red-breasted merganser
|
100 |
+
goose
|
101 |
+
black swan
|
102 |
+
tusker
|
103 |
+
echidna
|
104 |
+
platypus
|
105 |
+
wallaby
|
106 |
+
koala
|
107 |
+
wombat
|
108 |
+
jellyfish
|
109 |
+
sea anemone
|
110 |
+
brain coral
|
111 |
+
flatworm
|
112 |
+
nematode
|
113 |
+
conch
|
114 |
+
snail
|
115 |
+
slug
|
116 |
+
sea slug
|
117 |
+
chiton
|
118 |
+
chambered nautilus
|
119 |
+
Dungeness crab
|
120 |
+
rock crab
|
121 |
+
fiddler crab
|
122 |
+
king crab
|
123 |
+
American lobster
|
124 |
+
spiny lobster
|
125 |
+
crayfish
|
126 |
+
hermit crab
|
127 |
+
isopod
|
128 |
+
white stork
|
129 |
+
black stork
|
130 |
+
spoonbill
|
131 |
+
flamingo
|
132 |
+
little blue heron
|
133 |
+
American egret
|
134 |
+
bittern
|
135 |
+
crane
|
136 |
+
limpkin
|
137 |
+
European gallinule
|
138 |
+
American coot
|
139 |
+
bustard
|
140 |
+
ruddy turnstone
|
141 |
+
red-backed sandpiper
|
142 |
+
redshank
|
143 |
+
dowitcher
|
144 |
+
oystercatcher
|
145 |
+
pelican
|
146 |
+
king penguin
|
147 |
+
albatross
|
148 |
+
grey whale
|
149 |
+
killer whale
|
150 |
+
dugong
|
151 |
+
sea lion
|
152 |
+
Chihuahua
|
153 |
+
Japanese spaniel
|
154 |
+
Maltese dog
|
155 |
+
Pekinese
|
156 |
+
Shih-Tzu
|
157 |
+
Blenheim spaniel
|
158 |
+
papillon
|
159 |
+
toy terrier
|
160 |
+
Rhodesian ridgeback
|
161 |
+
Afghan hound
|
162 |
+
basset
|
163 |
+
beagle
|
164 |
+
bloodhound
|
165 |
+
bluetick
|
166 |
+
black-and-tan coonhound
|
167 |
+
Walker hound
|
168 |
+
English foxhound
|
169 |
+
redbone
|
170 |
+
borzoi
|
171 |
+
Irish wolfhound
|
172 |
+
Italian greyhound
|
173 |
+
whippet
|
174 |
+
Ibizan hound
|
175 |
+
Norwegian elkhound
|
176 |
+
otterhound
|
177 |
+
Saluki
|
178 |
+
Scottish deerhound
|
179 |
+
Weimaraner
|
180 |
+
Staffordshire bullterrier
|
181 |
+
American Staffordshire terrier
|
182 |
+
Bedlington terrier
|
183 |
+
Border terrier
|
184 |
+
Kerry blue terrier
|
185 |
+
Irish terrier
|
186 |
+
Norfolk terrier
|
187 |
+
Norwich terrier
|
188 |
+
Yorkshire terrier
|
189 |
+
wire-haired fox terrier
|
190 |
+
Lakeland terrier
|
191 |
+
Sealyham terrier
|
192 |
+
Airedale
|
193 |
+
cairn
|
194 |
+
Australian terrier
|
195 |
+
Dandie Dinmont
|
196 |
+
Boston bull
|
197 |
+
miniature schnauzer
|
198 |
+
giant schnauzer
|
199 |
+
standard schnauzer
|
200 |
+
Scotch terrier
|
201 |
+
Tibetan terrier
|
202 |
+
silky terrier
|
203 |
+
soft-coated wheaten terrier
|
204 |
+
West Highland white terrier
|
205 |
+
Lhasa
|
206 |
+
flat-coated retriever
|
207 |
+
curly-coated retriever
|
208 |
+
golden retriever
|
209 |
+
Labrador retriever
|
210 |
+
Chesapeake Bay retriever
|
211 |
+
German short-haired pointer
|
212 |
+
vizsla
|
213 |
+
English setter
|
214 |
+
Irish setter
|
215 |
+
Gordon setter
|
216 |
+
Brittany spaniel
|
217 |
+
clumber
|
218 |
+
English springer
|
219 |
+
Welsh springer spaniel
|
220 |
+
cocker spaniel
|
221 |
+
Sussex spaniel
|
222 |
+
Irish water spaniel
|
223 |
+
kuvasz
|
224 |
+
schipperke
|
225 |
+
groenendael
|
226 |
+
malinois
|
227 |
+
briard
|
228 |
+
kelpie
|
229 |
+
komondor
|
230 |
+
Old English sheepdog
|
231 |
+
Shetland sheepdog
|
232 |
+
collie
|
233 |
+
Border collie
|
234 |
+
Bouvier des Flandres
|
235 |
+
Rottweiler
|
236 |
+
German shepherd
|
237 |
+
Doberman
|
238 |
+
miniature pinscher
|
239 |
+
Greater Swiss Mountain dog
|
240 |
+
Bernese mountain dog
|
241 |
+
Appenzeller
|
242 |
+
EntleBucher
|
243 |
+
boxer
|
244 |
+
bull mastiff
|
245 |
+
Tibetan mastiff
|
246 |
+
French bulldog
|
247 |
+
Great Dane
|
248 |
+
Saint Bernard
|
249 |
+
Eskimo dog
|
250 |
+
malamute
|
251 |
+
Siberian husky
|
252 |
+
dalmatian
|
253 |
+
affenpinscher
|
254 |
+
basenji
|
255 |
+
pug
|
256 |
+
Leonberg
|
257 |
+
Newfoundland
|
258 |
+
Great Pyrenees
|
259 |
+
Samoyed
|
260 |
+
Pomeranian
|
261 |
+
chow
|
262 |
+
keeshond
|
263 |
+
Brabancon griffon
|
264 |
+
Pembroke
|
265 |
+
Cardigan
|
266 |
+
toy poodle
|
267 |
+
miniature poodle
|
268 |
+
standard poodle
|
269 |
+
Mexican hairless
|
270 |
+
timber wolf
|
271 |
+
white wolf
|
272 |
+
red wolf
|
273 |
+
coyote
|
274 |
+
dingo
|
275 |
+
dhole
|
276 |
+
African hunting dog
|
277 |
+
hyena
|
278 |
+
red fox
|
279 |
+
kit fox
|
280 |
+
Arctic fox
|
281 |
+
grey fox
|
282 |
+
tabby
|
283 |
+
tiger cat
|
284 |
+
Persian cat
|
285 |
+
Siamese cat
|
286 |
+
Egyptian cat
|
287 |
+
cougar
|
288 |
+
lynx
|
289 |
+
leopard
|
290 |
+
snow leopard
|
291 |
+
jaguar
|
292 |
+
lion
|
293 |
+
tiger
|
294 |
+
cheetah
|
295 |
+
brown bear
|
296 |
+
American black bear
|
297 |
+
ice bear
|
298 |
+
sloth bear
|
299 |
+
mongoose
|
300 |
+
meerkat
|
301 |
+
tiger beetle
|
302 |
+
ladybug
|
303 |
+
ground beetle
|
304 |
+
long-horned beetle
|
305 |
+
leaf beetle
|
306 |
+
dung beetle
|
307 |
+
rhinoceros beetle
|
308 |
+
weevil
|
309 |
+
fly
|
310 |
+
bee
|
311 |
+
ant
|
312 |
+
grasshopper
|
313 |
+
cricket
|
314 |
+
walking stick
|
315 |
+
cockroach
|
316 |
+
mantis
|
317 |
+
cicada
|
318 |
+
leafhopper
|
319 |
+
lacewing
|
320 |
+
dragonfly
|
321 |
+
damselfly
|
322 |
+
admiral
|
323 |
+
ringlet
|
324 |
+
monarch
|
325 |
+
cabbage butterfly
|
326 |
+
sulphur butterfly
|
327 |
+
lycaenid
|
328 |
+
starfish
|
329 |
+
sea urchin
|
330 |
+
sea cucumber
|
331 |
+
wood rabbit
|
332 |
+
hare
|
333 |
+
Angora
|
334 |
+
hamster
|
335 |
+
porcupine
|
336 |
+
fox squirrel
|
337 |
+
marmot
|
338 |
+
beaver
|
339 |
+
guinea pig
|
340 |
+
sorrel
|
341 |
+
zebra
|
342 |
+
hog
|
343 |
+
wild boar
|
344 |
+
warthog
|
345 |
+
hippopotamus
|
346 |
+
ox
|
347 |
+
water buffalo
|
348 |
+
bison
|
349 |
+
ram
|
350 |
+
bighorn
|
351 |
+
ibex
|
352 |
+
hartebeest
|
353 |
+
impala
|
354 |
+
gazelle
|
355 |
+
Arabian camel
|
356 |
+
llama
|
357 |
+
weasel
|
358 |
+
mink
|
359 |
+
polecat
|
360 |
+
black-footed ferret
|
361 |
+
otter
|
362 |
+
skunk
|
363 |
+
badger
|
364 |
+
armadillo
|
365 |
+
three-toed sloth
|
366 |
+
orangutan
|
367 |
+
gorilla
|
368 |
+
chimpanzee
|
369 |
+
gibbon
|
370 |
+
siamang
|
371 |
+
guenon
|
372 |
+
patas
|
373 |
+
baboon
|
374 |
+
macaque
|
375 |
+
langur
|
376 |
+
colobus
|
377 |
+
proboscis monkey
|
378 |
+
marmoset
|
379 |
+
capuchin
|
380 |
+
howler monkey
|
381 |
+
titi
|
382 |
+
spider monkey
|
383 |
+
squirrel monkey
|
384 |
+
Madagascar cat
|
385 |
+
indri
|
386 |
+
Indian elephant
|
387 |
+
African elephant
|
388 |
+
lesser panda
|
389 |
+
giant panda
|
390 |
+
barracouta
|
391 |
+
eel
|
392 |
+
coho
|
393 |
+
rock beauty
|
394 |
+
anemone fish
|
395 |
+
sturgeon
|
396 |
+
gar
|
397 |
+
lionfish
|
398 |
+
puffer
|
399 |
+
abacus
|
400 |
+
abaya
|
401 |
+
academic gown
|
402 |
+
accordion
|
403 |
+
acoustic guitar
|
404 |
+
aircraft carrier
|
405 |
+
airliner
|
406 |
+
airship
|
407 |
+
altar
|
408 |
+
ambulance
|
409 |
+
amphibian
|
410 |
+
analog clock
|
411 |
+
apiary
|
412 |
+
apron
|
413 |
+
ashcan
|
414 |
+
assault rifle
|
415 |
+
backpack
|
416 |
+
bakery
|
417 |
+
balance beam
|
418 |
+
balloon
|
419 |
+
ballpoint
|
420 |
+
Band Aid
|
421 |
+
banjo
|
422 |
+
bannister
|
423 |
+
barbell
|
424 |
+
barber chair
|
425 |
+
barbershop
|
426 |
+
barn
|
427 |
+
barometer
|
428 |
+
barrel
|
429 |
+
barrow
|
430 |
+
baseball
|
431 |
+
basketball
|
432 |
+
bassinet
|
433 |
+
bassoon
|
434 |
+
bathing cap
|
435 |
+
bath towel
|
436 |
+
bathtub
|
437 |
+
beach wagon
|
438 |
+
beacon
|
439 |
+
beaker
|
440 |
+
bearskin
|
441 |
+
beer bottle
|
442 |
+
beer glass
|
443 |
+
bell cote
|
444 |
+
bib
|
445 |
+
bicycle-built-for-two
|
446 |
+
bikini
|
447 |
+
binder
|
448 |
+
binoculars
|
449 |
+
birdhouse
|
450 |
+
boathouse
|
451 |
+
bobsled
|
452 |
+
bolo tie
|
453 |
+
bonnet
|
454 |
+
bookcase
|
455 |
+
bookshop
|
456 |
+
bottlecap
|
457 |
+
bow
|
458 |
+
bow tie
|
459 |
+
brass
|
460 |
+
brassiere
|
461 |
+
breakwater
|
462 |
+
breastplate
|
463 |
+
broom
|
464 |
+
bucket
|
465 |
+
buckle
|
466 |
+
bulletproof vest
|
467 |
+
bullet train
|
468 |
+
butcher shop
|
469 |
+
cab
|
470 |
+
caldron
|
471 |
+
candle
|
472 |
+
cannon
|
473 |
+
canoe
|
474 |
+
can opener
|
475 |
+
cardigan
|
476 |
+
car mirror
|
477 |
+
carousel
|
478 |
+
carpenters kit
|
479 |
+
carton
|
480 |
+
car wheel
|
481 |
+
cash machine
|
482 |
+
cassette
|
483 |
+
cassette player
|
484 |
+
castle
|
485 |
+
catamaran
|
486 |
+
CD player
|
487 |
+
cello
|
488 |
+
cellular telephone
|
489 |
+
chain
|
490 |
+
chainlink fence
|
491 |
+
chain mail
|
492 |
+
chain saw
|
493 |
+
chest
|
494 |
+
chiffonier
|
495 |
+
chime
|
496 |
+
china cabinet
|
497 |
+
Christmas stocking
|
498 |
+
church
|
499 |
+
cinema
|
500 |
+
cleaver
|
501 |
+
cliff dwelling
|
502 |
+
cloak
|
503 |
+
clog
|
504 |
+
cocktail shaker
|
505 |
+
coffee mug
|
506 |
+
coffeepot
|
507 |
+
coil
|
508 |
+
combination lock
|
509 |
+
computer keyboard
|
510 |
+
confectionery
|
511 |
+
container ship
|
512 |
+
convertible
|
513 |
+
corkscrew
|
514 |
+
cornet
|
515 |
+
cowboy boot
|
516 |
+
cowboy hat
|
517 |
+
cradle
|
518 |
+
crane
|
519 |
+
crash helmet
|
520 |
+
crate
|
521 |
+
crib
|
522 |
+
Crock Pot
|
523 |
+
croquet ball
|
524 |
+
crutch
|
525 |
+
cuirass
|
526 |
+
dam
|
527 |
+
desk
|
528 |
+
desktop computer
|
529 |
+
dial telephone
|
530 |
+
diaper
|
531 |
+
digital clock
|
532 |
+
digital watch
|
533 |
+
dining table
|
534 |
+
dishrag
|
535 |
+
dishwasher
|
536 |
+
disk brake
|
537 |
+
dock
|
538 |
+
dogsled
|
539 |
+
dome
|
540 |
+
doormat
|
541 |
+
drilling platform
|
542 |
+
drum
|
543 |
+
drumstick
|
544 |
+
dumbbell
|
545 |
+
Dutch oven
|
546 |
+
electric fan
|
547 |
+
electric guitar
|
548 |
+
electric locomotive
|
549 |
+
entertainment center
|
550 |
+
envelope
|
551 |
+
espresso maker
|
552 |
+
face powder
|
553 |
+
feather boa
|
554 |
+
file
|
555 |
+
fireboat
|
556 |
+
fire engine
|
557 |
+
fire screen
|
558 |
+
flagpole
|
559 |
+
flute
|
560 |
+
folding chair
|
561 |
+
football helmet
|
562 |
+
forklift
|
563 |
+
fountain
|
564 |
+
fountain pen
|
565 |
+
four-poster
|
566 |
+
freight car
|
567 |
+
French horn
|
568 |
+
frying pan
|
569 |
+
fur coat
|
570 |
+
garbage truck
|
571 |
+
gasmask
|
572 |
+
gas pump
|
573 |
+
goblet
|
574 |
+
go-kart
|
575 |
+
golf ball
|
576 |
+
golfcart
|
577 |
+
gondola
|
578 |
+
gong
|
579 |
+
gown
|
580 |
+
grand piano
|
581 |
+
greenhouse
|
582 |
+
grille
|
583 |
+
grocery store
|
584 |
+
guillotine
|
585 |
+
hair slide
|
586 |
+
hair spray
|
587 |
+
half track
|
588 |
+
hammer
|
589 |
+
hamper
|
590 |
+
hand blower
|
591 |
+
hand-held computer
|
592 |
+
handkerchief
|
593 |
+
hard disc
|
594 |
+
harmonica
|
595 |
+
harp
|
596 |
+
harvester
|
597 |
+
hatchet
|
598 |
+
holster
|
599 |
+
home theater
|
600 |
+
honeycomb
|
601 |
+
hook
|
602 |
+
hoopskirt
|
603 |
+
horizontal bar
|
604 |
+
horse cart
|
605 |
+
hourglass
|
606 |
+
iPod
|
607 |
+
iron
|
608 |
+
jack-o-lantern
|
609 |
+
jean
|
610 |
+
jeep
|
611 |
+
jersey
|
612 |
+
jigsaw puzzle
|
613 |
+
jinrikisha
|
614 |
+
joystick
|
615 |
+
kimono
|
616 |
+
knee pad
|
617 |
+
knot
|
618 |
+
lab coat
|
619 |
+
ladle
|
620 |
+
lampshade
|
621 |
+
laptop
|
622 |
+
lawn mower
|
623 |
+
lens cap
|
624 |
+
letter opener
|
625 |
+
library
|
626 |
+
lifeboat
|
627 |
+
lighter
|
628 |
+
limousine
|
629 |
+
liner
|
630 |
+
lipstick
|
631 |
+
Loafer
|
632 |
+
lotion
|
633 |
+
loudspeaker
|
634 |
+
loupe
|
635 |
+
lumbermill
|
636 |
+
magnetic compass
|
637 |
+
mailbag
|
638 |
+
mailbox
|
639 |
+
maillot
|
640 |
+
maillot
|
641 |
+
manhole cover
|
642 |
+
maraca
|
643 |
+
marimba
|
644 |
+
mask
|
645 |
+
matchstick
|
646 |
+
maypole
|
647 |
+
maze
|
648 |
+
measuring cup
|
649 |
+
medicine chest
|
650 |
+
megalith
|
651 |
+
microphone
|
652 |
+
microwave
|
653 |
+
military uniform
|
654 |
+
milk can
|
655 |
+
minibus
|
656 |
+
miniskirt
|
657 |
+
minivan
|
658 |
+
missile
|
659 |
+
mitten
|
660 |
+
mixing bowl
|
661 |
+
mobile home
|
662 |
+
Model T
|
663 |
+
modem
|
664 |
+
monastery
|
665 |
+
monitor
|
666 |
+
moped
|
667 |
+
mortar
|
668 |
+
mortarboard
|
669 |
+
mosque
|
670 |
+
mosquito net
|
671 |
+
motor scooter
|
672 |
+
mountain bike
|
673 |
+
mountain tent
|
674 |
+
mouse
|
675 |
+
mousetrap
|
676 |
+
moving van
|
677 |
+
muzzle
|
678 |
+
nail
|
679 |
+
neck brace
|
680 |
+
necklace
|
681 |
+
nipple
|
682 |
+
notebook
|
683 |
+
obelisk
|
684 |
+
oboe
|
685 |
+
ocarina
|
686 |
+
odometer
|
687 |
+
oil filter
|
688 |
+
organ
|
689 |
+
oscilloscope
|
690 |
+
overskirt
|
691 |
+
oxcart
|
692 |
+
oxygen mask
|
693 |
+
packet
|
694 |
+
paddle
|
695 |
+
paddlewheel
|
696 |
+
padlock
|
697 |
+
paintbrush
|
698 |
+
pajama
|
699 |
+
palace
|
700 |
+
panpipe
|
701 |
+
paper towel
|
702 |
+
parachute
|
703 |
+
parallel bars
|
704 |
+
park bench
|
705 |
+
parking meter
|
706 |
+
passenger car
|
707 |
+
patio
|
708 |
+
pay-phone
|
709 |
+
pedestal
|
710 |
+
pencil box
|
711 |
+
pencil sharpener
|
712 |
+
perfume
|
713 |
+
Petri dish
|
714 |
+
photocopier
|
715 |
+
pick
|
716 |
+
pickelhaube
|
717 |
+
picket fence
|
718 |
+
pickup
|
719 |
+
pier
|
720 |
+
piggy bank
|
721 |
+
pill bottle
|
722 |
+
pillow
|
723 |
+
ping-pong ball
|
724 |
+
pinwheel
|
725 |
+
pirate
|
726 |
+
pitcher
|
727 |
+
plane
|
728 |
+
planetarium
|
729 |
+
plastic bag
|
730 |
+
plate rack
|
731 |
+
plow
|
732 |
+
plunger
|
733 |
+
Polaroid camera
|
734 |
+
pole
|
735 |
+
police van
|
736 |
+
poncho
|
737 |
+
pool table
|
738 |
+
pop bottle
|
739 |
+
pot
|
740 |
+
potters wheel
|
741 |
+
power drill
|
742 |
+
prayer rug
|
743 |
+
printer
|
744 |
+
prison
|
745 |
+
projectile
|
746 |
+
projector
|
747 |
+
puck
|
748 |
+
punching bag
|
749 |
+
purse
|
750 |
+
quill
|
751 |
+
quilt
|
752 |
+
racer
|
753 |
+
racket
|
754 |
+
radiator
|
755 |
+
radio
|
756 |
+
radio telescope
|
757 |
+
rain barrel
|
758 |
+
recreational vehicle
|
759 |
+
reel
|
760 |
+
reflex camera
|
761 |
+
refrigerator
|
762 |
+
remote control
|
763 |
+
restaurant
|
764 |
+
revolver
|
765 |
+
rifle
|
766 |
+
rocking chair
|
767 |
+
rotisserie
|
768 |
+
rubber eraser
|
769 |
+
rugby ball
|
770 |
+
rule
|
771 |
+
running shoe
|
772 |
+
safe
|
773 |
+
safety pin
|
774 |
+
saltshaker
|
775 |
+
sandal
|
776 |
+
sarong
|
777 |
+
sax
|
778 |
+
scabbard
|
779 |
+
scale
|
780 |
+
school bus
|
781 |
+
schooner
|
782 |
+
scoreboard
|
783 |
+
screen
|
784 |
+
screw
|
785 |
+
screwdriver
|
786 |
+
seat belt
|
787 |
+
sewing machine
|
788 |
+
shield
|
789 |
+
shoe shop
|
790 |
+
shoji
|
791 |
+
shopping basket
|
792 |
+
shopping cart
|
793 |
+
shovel
|
794 |
+
shower cap
|
795 |
+
shower curtain
|
796 |
+
ski
|
797 |
+
ski mask
|
798 |
+
sleeping bag
|
799 |
+
slide rule
|
800 |
+
sliding door
|
801 |
+
slot
|
802 |
+
snorkel
|
803 |
+
snowmobile
|
804 |
+
snowplow
|
805 |
+
soap dispenser
|
806 |
+
soccer ball
|
807 |
+
sock
|
808 |
+
solar dish
|
809 |
+
sombrero
|
810 |
+
soup bowl
|
811 |
+
space bar
|
812 |
+
space heater
|
813 |
+
space shuttle
|
814 |
+
spatula
|
815 |
+
speedboat
|
816 |
+
spider web
|
817 |
+
spindle
|
818 |
+
sports car
|
819 |
+
spotlight
|
820 |
+
stage
|
821 |
+
steam locomotive
|
822 |
+
steel arch bridge
|
823 |
+
steel drum
|
824 |
+
stethoscope
|
825 |
+
stole
|
826 |
+
stone wall
|
827 |
+
stopwatch
|
828 |
+
stove
|
829 |
+
strainer
|
830 |
+
streetcar
|
831 |
+
stretcher
|
832 |
+
studio couch
|
833 |
+
stupa
|
834 |
+
submarine
|
835 |
+
suit
|
836 |
+
sundial
|
837 |
+
sunglass
|
838 |
+
sunglasses
|
839 |
+
sunscreen
|
840 |
+
suspension bridge
|
841 |
+
swab
|
842 |
+
sweatshirt
|
843 |
+
swimming trunks
|
844 |
+
swing
|
845 |
+
switch
|
846 |
+
syringe
|
847 |
+
table lamp
|
848 |
+
tank
|
849 |
+
tape player
|
850 |
+
teapot
|
851 |
+
teddy
|
852 |
+
television
|
853 |
+
tennis ball
|
854 |
+
thatch
|
855 |
+
theater curtain
|
856 |
+
thimble
|
857 |
+
thresher
|
858 |
+
throne
|
859 |
+
tile roof
|
860 |
+
toaster
|
861 |
+
tobacco shop
|
862 |
+
toilet seat
|
863 |
+
torch
|
864 |
+
totem pole
|
865 |
+
tow truck
|
866 |
+
toyshop
|
867 |
+
tractor
|
868 |
+
trailer truck
|
869 |
+
tray
|
870 |
+
trench coat
|
871 |
+
tricycle
|
872 |
+
trimaran
|
873 |
+
tripod
|
874 |
+
triumphal arch
|
875 |
+
trolleybus
|
876 |
+
trombone
|
877 |
+
tub
|
878 |
+
turnstile
|
879 |
+
typewriter keyboard
|
880 |
+
umbrella
|
881 |
+
unicycle
|
882 |
+
upright
|
883 |
+
vacuum
|
884 |
+
vase
|
885 |
+
vault
|
886 |
+
velvet
|
887 |
+
vending machine
|
888 |
+
vestment
|
889 |
+
viaduct
|
890 |
+
violin
|
891 |
+
volleyball
|
892 |
+
waffle iron
|
893 |
+
wall clock
|
894 |
+
wallet
|
895 |
+
wardrobe
|
896 |
+
warplane
|
897 |
+
washbasin
|
898 |
+
washer
|
899 |
+
water bottle
|
900 |
+
water jug
|
901 |
+
water tower
|
902 |
+
whiskey jug
|
903 |
+
whistle
|
904 |
+
wig
|
905 |
+
window screen
|
906 |
+
window shade
|
907 |
+
Windsor tie
|
908 |
+
wine bottle
|
909 |
+
wing
|
910 |
+
wok
|
911 |
+
wooden spoon
|
912 |
+
wool
|
913 |
+
worm fence
|
914 |
+
wreck
|
915 |
+
yawl
|
916 |
+
yurt
|
917 |
+
web site
|
918 |
+
comic book
|
919 |
+
crossword puzzle
|
920 |
+
street sign
|
921 |
+
traffic light
|
922 |
+
book jacket
|
923 |
+
menu
|
924 |
+
plate
|
925 |
+
guacamole
|
926 |
+
consomme
|
927 |
+
hot pot
|
928 |
+
trifle
|
929 |
+
ice cream
|
930 |
+
ice lolly
|
931 |
+
French loaf
|
932 |
+
bagel
|
933 |
+
pretzel
|
934 |
+
cheeseburger
|
935 |
+
hotdog
|
936 |
+
mashed potato
|
937 |
+
head cabbage
|
938 |
+
broccoli
|
939 |
+
cauliflower
|
940 |
+
zucchini
|
941 |
+
spaghetti squash
|
942 |
+
acorn squash
|
943 |
+
butternut squash
|
944 |
+
cucumber
|
945 |
+
artichoke
|
946 |
+
bell pepper
|
947 |
+
cardoon
|
948 |
+
mushroom
|
949 |
+
Granny Smith
|
950 |
+
strawberry
|
951 |
+
orange
|
952 |
+
lemon
|
953 |
+
fig
|
954 |
+
pineapple
|
955 |
+
banana
|
956 |
+
jackfruit
|
957 |
+
custard apple
|
958 |
+
pomegranate
|
959 |
+
hay
|
960 |
+
carbonara
|
961 |
+
chocolate sauce
|
962 |
+
dough
|
963 |
+
meat loaf
|
964 |
+
pizza
|
965 |
+
potpie
|
966 |
+
burrito
|
967 |
+
red wine
|
968 |
+
espresso
|
969 |
+
cup
|
970 |
+
eggnog
|
971 |
+
alp
|
972 |
+
bubble
|
973 |
+
cliff
|
974 |
+
coral reef
|
975 |
+
geyser
|
976 |
+
lakeside
|
977 |
+
promontory
|
978 |
+
sandbar
|
979 |
+
seashore
|
980 |
+
valley
|
981 |
+
volcano
|
982 |
+
ballplayer
|
983 |
+
groom
|
984 |
+
scuba diver
|
985 |
+
rapeseed
|
986 |
+
daisy
|
987 |
+
yellow ladys slipper
|
988 |
+
corn
|
989 |
+
acorn
|
990 |
+
hip
|
991 |
+
buckeye
|
992 |
+
coral fungus
|
993 |
+
agaric
|
994 |
+
gyromitra
|
995 |
+
stinkhorn
|
996 |
+
earthstar
|
997 |
+
hen-of-the-woods
|
998 |
+
bolete
|
999 |
+
ear
|
1000 |
+
toilet tissue
|
models/image_classification_ppresnet/ppresnet.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file is part of OpenCV Zoo project.
|
2 |
+
# It is subject to the license terms in the LICENSE file found in the same directory.
|
3 |
+
#
|
4 |
+
# Copyright (C) 2021, Shenzhen Institute of Artificial Intelligence and Robotics for Society, all rights reserved.
|
5 |
+
# Third party copyrights are property of their respective owners.
|
6 |
+
|
7 |
+
|
8 |
+
import numpy as np
|
9 |
+
import cv2 as cv
|
10 |
+
|
11 |
+
class PPResNet:
|
12 |
+
def __init__(self, modelPath, labelPath):
|
13 |
+
self._modelPath = modelPath
|
14 |
+
self._model = cv.dnn.readNet(self._modelPath)
|
15 |
+
self._labelPath = labelPath
|
16 |
+
|
17 |
+
self._inputNames = ''
|
18 |
+
self._outputNames = ['save_infer_model/scale_0.tmp_0']
|
19 |
+
self._inputSize = [224, 224]
|
20 |
+
self._mean = np.array([0.485, 0.456, 0.406])[np.newaxis, np.newaxis, :]
|
21 |
+
self._std = np.array([0.229, 0.224, 0.225])[np.newaxis, np.newaxis, :]
|
22 |
+
|
23 |
+
# load labels
|
24 |
+
self._labels = self._load_labels()
|
25 |
+
|
26 |
+
def _load_labels(self):
|
27 |
+
labels = []
|
28 |
+
with open(self._labelPath, 'r') as f:
|
29 |
+
for line in f:
|
30 |
+
labels.append(line.strip())
|
31 |
+
return labels
|
32 |
+
|
33 |
+
@property
|
34 |
+
def name(self):
|
35 |
+
return self.__class__.__name__
|
36 |
+
|
37 |
+
def setBackend(self, backend_id):
|
38 |
+
self._model.setPreferableBackend(backend_id)
|
39 |
+
|
40 |
+
def setTarget(self, target_id):
|
41 |
+
self._model.setPreferableTarget(target_id)
|
42 |
+
|
43 |
+
def _preprocess(self, image):
|
44 |
+
image = image.astype(np.float32, copy=False) / 255.0
|
45 |
+
image -= self._mean
|
46 |
+
image /= self._std
|
47 |
+
return cv.dnn.blobFromImage(image)
|
48 |
+
|
49 |
+
def infer(self, image):
|
50 |
+
assert image.shape[0] == self._inputSize[1], '{} (height of input image) != {} (preset height)'.format(image.shape[0], self._inputSize[1])
|
51 |
+
assert image.shape[1] == self._inputSize[0], '{} (width of input image) != {} (preset width)'.format(image.shape[1], self._inputSize[0])
|
52 |
+
|
53 |
+
# Preprocess
|
54 |
+
inputBlob = self._preprocess(image)
|
55 |
+
|
56 |
+
# Forward
|
57 |
+
self._model.setInput(inputBlob, self._inputNames)
|
58 |
+
outputBlob = self._model.forward(self._outputNames)
|
59 |
+
|
60 |
+
# Postprocess
|
61 |
+
results = self._postprocess(outputBlob)
|
62 |
+
|
63 |
+
return results
|
64 |
+
|
65 |
+
def _postprocess(self, outputBlob):
|
66 |
+
class_id = np.argmax(outputBlob[0])
|
67 |
+
return self._labels[class_id]
|