Ryan Lee
commited on
Commit
·
30e431e
1
Parent(s):
be1656e
C++ Demo - Image Classification (PPResNet) (#241)
Browse files* Functional version of C++ demo.
* Improve printout.
* Remove printouts and add README examples
* Add goldfish example
* Add empty space at EOF
* Add empty line at EOF for Python
* Use the shared labels.txt file instead of having the entire list as a variable in the demo.py
* Address PR comments. Revert example and labels
* Use namespaces for brevity
* Follow OpenCV formatting
* Remove LoadLabel() and use a vector of strings instead of having redundant work.
models/image_classification_ppresnet/CMakeLists.txt
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cmake_minimum_required(VERSION 3.24)
|
| 2 |
+
set(project_name "opencv_zoo_image_classification_ppresnet")
|
| 3 |
+
|
| 4 |
+
PROJECT (${project_name})
|
| 5 |
+
|
| 6 |
+
set(OPENCV_VERSION "4.9.0")
|
| 7 |
+
set(OPENCV_INSTALLATION_PATH "" CACHE PATH "Where to look for OpenCV installation")
|
| 8 |
+
find_package(OpenCV ${OPENCV_VERSION} REQUIRED HINTS ${OPENCV_INSTALLATION_PATH})
|
| 9 |
+
# Find OpenCV, you may need to set OpenCV_DIR variable
|
| 10 |
+
# to the absolute path to the directory containing OpenCVConfig.cmake file
|
| 11 |
+
# via the command line or GUI
|
| 12 |
+
|
| 13 |
+
file(GLOB SourceFile
|
| 14 |
+
"demo.cpp")
|
| 15 |
+
# If the package has been found, several variables will
|
| 16 |
+
# be set, you can find the full list with descriptions
|
| 17 |
+
# in the OpenCVConfig.cmake file.
|
| 18 |
+
# Print some message showing some of them
|
| 19 |
+
message(STATUS "OpenCV library status:")
|
| 20 |
+
message(STATUS " config: ${OpenCV_DIR}")
|
| 21 |
+
message(STATUS " version: ${OpenCV_VERSION}")
|
| 22 |
+
message(STATUS " libraries: ${OpenCV_LIBS}")
|
| 23 |
+
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
|
| 24 |
+
|
| 25 |
+
# Declare the executable target built from your sources
|
| 26 |
+
add_executable(${project_name} ${SourceFile})
|
| 27 |
+
|
| 28 |
+
# Set C++ compilation standard to C++11
|
| 29 |
+
set(CMAKE_CXX_STANDARD 11)
|
| 30 |
+
|
| 31 |
+
# Link your application with OpenCV libraries
|
| 32 |
+
target_link_libraries(${project_name} PRIVATE ${OpenCV_LIBS})
|
models/image_classification_ppresnet/README.md
CHANGED
|
@@ -15,7 +15,9 @@ Results of accuracy evaluation with [tools/eval](../../tools/eval).
|
|
| 15 |
|
| 16 |
## Demo
|
| 17 |
|
| 18 |
-
Run the following
|
|
|
|
|
|
|
| 19 |
|
| 20 |
```shell
|
| 21 |
python demo.py --input /path/to/image
|
|
@@ -23,6 +25,24 @@ python demo.py --input /path/to/image
|
|
| 23 |
# get help regarding various parameters
|
| 24 |
python demo.py --help
|
| 25 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
## License
|
| 28 |
|
|
|
|
| 15 |
|
| 16 |
## Demo
|
| 17 |
|
| 18 |
+
Run the following commands to try the demo:
|
| 19 |
+
|
| 20 |
+
### Python
|
| 21 |
|
| 22 |
```shell
|
| 23 |
python demo.py --input /path/to/image
|
|
|
|
| 25 |
# get help regarding various parameters
|
| 26 |
python demo.py --help
|
| 27 |
```
|
| 28 |
+
### C++
|
| 29 |
+
|
| 30 |
+
Install latest OpenCV and CMake >= 3.24.0 to get started with:
|
| 31 |
+
|
| 32 |
+
```shell
|
| 33 |
+
# A typical and default installation path of OpenCV is /usr/local
|
| 34 |
+
cmake -B build -D OPENCV_INSTALLATION_PATH=/path/to/opencv/installation .
|
| 35 |
+
cmake --build build
|
| 36 |
+
|
| 37 |
+
# detect on an image
|
| 38 |
+
./build/opencv_zoo_image_classification_ppresnet -i=/path/to/image
|
| 39 |
+
|
| 40 |
+
# detect on an image and display top N classes
|
| 41 |
+
./build/opencv_zoo_image_classification_ppresnet -i=/path/to/image -k=N
|
| 42 |
+
|
| 43 |
+
# get help messages
|
| 44 |
+
./build/opencv_zoo_image_classification_ppresnet -h
|
| 45 |
+
```
|
| 46 |
|
| 47 |
## License
|
| 48 |
|
models/image_classification_ppresnet/demo.cpp
ADDED
|
@@ -0,0 +1,1123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
#include <algorithm>
|
| 5 |
+
|
| 6 |
+
using namespace std;
|
| 7 |
+
using namespace cv;
|
| 8 |
+
using namespace dnn;
|
| 9 |
+
|
| 10 |
+
extern vector<string> LABELS_IMAGENET_1K;
|
| 11 |
+
|
| 12 |
+
class PPResNet {
|
| 13 |
+
public:
|
| 14 |
+
PPResNet(const string& modelPath, int topK, int backendId, int targetId)
|
| 15 |
+
: _topK(topK) {
|
| 16 |
+
_model = readNet(modelPath);
|
| 17 |
+
_model.setPreferableBackend(backendId);
|
| 18 |
+
_model.setPreferableTarget(targetId);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
Mat preprocess(const Mat& image)
|
| 22 |
+
{
|
| 23 |
+
Mat floatImage;
|
| 24 |
+
image.convertTo(floatImage, CV_32F, 1.0 / 255.0);
|
| 25 |
+
subtract(floatImage, _mean, floatImage);
|
| 26 |
+
divide(floatImage, _std, floatImage);
|
| 27 |
+
return blobFromImage(floatImage);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
vector<string> infer(const Mat& image)
|
| 31 |
+
{
|
| 32 |
+
assert(image.rows == _inputSize.height && image.cols == _inputSize.width);
|
| 33 |
+
Mat inputBlob = preprocess(image);
|
| 34 |
+
_model.setInput(inputBlob, _inputName);
|
| 35 |
+
Mat outputBlob = _model.forward(_outputName);
|
| 36 |
+
vector<string> results = postprocess(outputBlob);
|
| 37 |
+
return results;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
vector<string> postprocess(const Mat& outputBlob)
|
| 41 |
+
{
|
| 42 |
+
vector<int> class_id_list;
|
| 43 |
+
sortIdx(outputBlob, class_id_list, SORT_EVERY_ROW | SORT_DESCENDING);
|
| 44 |
+
class_id_list.resize(min(_topK, static_cast<int>(outputBlob.cols)));
|
| 45 |
+
vector<string> predicted_labels;
|
| 46 |
+
for (int class_id : class_id_list)
|
| 47 |
+
{
|
| 48 |
+
predicted_labels.push_back(LABELS_IMAGENET_1K[class_id]);
|
| 49 |
+
}
|
| 50 |
+
return predicted_labels;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
private:
|
| 54 |
+
Net _model;
|
| 55 |
+
int _topK;
|
| 56 |
+
const Size _inputSize = Size(224, 224);
|
| 57 |
+
const Scalar _mean = Scalar(0.485, 0.456, 0.406);
|
| 58 |
+
const Scalar _std = Scalar(0.229, 0.224, 0.225);
|
| 59 |
+
string _inputName = "";
|
| 60 |
+
string _outputName = "save_infer_model/scale_0.tmp_0";
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
const vector<vector<int>> backend_target_pairs =
|
| 64 |
+
{
|
| 65 |
+
{DNN_BACKEND_OPENCV, DNN_TARGET_CPU},
|
| 66 |
+
{DNN_BACKEND_CUDA, DNN_TARGET_CUDA},
|
| 67 |
+
{DNN_BACKEND_CUDA, DNN_TARGET_CUDA_FP16},
|
| 68 |
+
{DNN_BACKEND_TIMVX, DNN_TARGET_NPU},
|
| 69 |
+
{DNN_BACKEND_CANN, DNN_TARGET_NPU}
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
int main(int argc, char** argv)
|
| 73 |
+
{
|
| 74 |
+
CommandLineParser parser(argc, argv,
|
| 75 |
+
"{ input i | | Set input path to a certain image, omit if using camera.}"
|
| 76 |
+
"{ model m | image_classification_ppresnet50_2022jan.onnx | Set model path.}"
|
| 77 |
+
"{ top_k k | 1 | Get top k predictions.}"
|
| 78 |
+
"{ backend_target bt | 0 | Choose one of computation backends: "
|
| 79 |
+
"0: (default) OpenCV implementation + CPU, "
|
| 80 |
+
"1: CUDA + GPU (CUDA), "
|
| 81 |
+
"2: CUDA + GPU (CUDA FP16), "
|
| 82 |
+
"3: TIM-VX + NPU, "
|
| 83 |
+
"4: CANN + NPU}");
|
| 84 |
+
|
| 85 |
+
string inputPath = parser.get<string>("input");
|
| 86 |
+
string modelPath = parser.get<string>("model");
|
| 87 |
+
int backendTarget = parser.get<int>("backend_target");
|
| 88 |
+
int topK = parser.get<int>("top_k");
|
| 89 |
+
|
| 90 |
+
int backendId = backend_target_pairs[backendTarget][0];
|
| 91 |
+
int targetId = backend_target_pairs[backendTarget][1];
|
| 92 |
+
|
| 93 |
+
PPResNet model(modelPath, topK, backendId, targetId);
|
| 94 |
+
|
| 95 |
+
// Read image and get a 224x224 crop from a 256x256 resized
|
| 96 |
+
Mat image = imread(inputPath);
|
| 97 |
+
cvtColor(image, image, COLOR_BGR2RGB);
|
| 98 |
+
resize(image, image, Size(256, 256));
|
| 99 |
+
image = image(Rect(16, 16, 224, 224));
|
| 100 |
+
|
| 101 |
+
// Inference
|
| 102 |
+
auto predictions = model.infer(image);
|
| 103 |
+
|
| 104 |
+
// Print result
|
| 105 |
+
if (topK == 1)
|
| 106 |
+
{
|
| 107 |
+
cout << "Predicted Label: " << predictions[0] << endl;
|
| 108 |
+
}
|
| 109 |
+
else
|
| 110 |
+
{
|
| 111 |
+
cout << "Predicted Top-K Labels (in decreasing confidence): " << endl;
|
| 112 |
+
for (size_t i = 0; i < predictions.size(); ++i)
|
| 113 |
+
{
|
| 114 |
+
cout << "(" << i+1 << ") " << predictions[i] << endl;
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
return 0;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
vector<string> LABELS_IMAGENET_1K =
|
| 122 |
+
{
|
| 123 |
+
"tench",
|
| 124 |
+
"goldfish",
|
| 125 |
+
"great white shark",
|
| 126 |
+
"tiger shark",
|
| 127 |
+
"hammerhead",
|
| 128 |
+
"electric ray",
|
| 129 |
+
"stingray",
|
| 130 |
+
"cock",
|
| 131 |
+
"hen",
|
| 132 |
+
"ostrich",
|
| 133 |
+
"brambling",
|
| 134 |
+
"goldfinch",
|
| 135 |
+
"house finch",
|
| 136 |
+
"junco",
|
| 137 |
+
"indigo bunting",
|
| 138 |
+
"robin",
|
| 139 |
+
"bulbul",
|
| 140 |
+
"jay",
|
| 141 |
+
"magpie",
|
| 142 |
+
"chickadee",
|
| 143 |
+
"water ouzel",
|
| 144 |
+
"kite",
|
| 145 |
+
"bald eagle",
|
| 146 |
+
"vulture",
|
| 147 |
+
"great grey owl",
|
| 148 |
+
"European fire salamander",
|
| 149 |
+
"common newt",
|
| 150 |
+
"eft",
|
| 151 |
+
"spotted salamander",
|
| 152 |
+
"axolotl",
|
| 153 |
+
"bullfrog",
|
| 154 |
+
"tree frog",
|
| 155 |
+
"tailed frog",
|
| 156 |
+
"loggerhead",
|
| 157 |
+
"leatherback turtle",
|
| 158 |
+
"mud turtle",
|
| 159 |
+
"terrapin",
|
| 160 |
+
"box turtle",
|
| 161 |
+
"banded gecko",
|
| 162 |
+
"common iguana",
|
| 163 |
+
"American chameleon",
|
| 164 |
+
"whiptail",
|
| 165 |
+
"agama",
|
| 166 |
+
"frilled lizard",
|
| 167 |
+
"alligator lizard",
|
| 168 |
+
"Gila monster",
|
| 169 |
+
"green lizard",
|
| 170 |
+
"African chameleon",
|
| 171 |
+
"Komodo dragon",
|
| 172 |
+
"African crocodile",
|
| 173 |
+
"American alligator",
|
| 174 |
+
"triceratops",
|
| 175 |
+
"thunder snake",
|
| 176 |
+
"ringneck snake",
|
| 177 |
+
"hognose snake",
|
| 178 |
+
"green snake",
|
| 179 |
+
"king snake",
|
| 180 |
+
"garter snake",
|
| 181 |
+
"water snake",
|
| 182 |
+
"vine snake",
|
| 183 |
+
"night snake",
|
| 184 |
+
"boa constrictor",
|
| 185 |
+
"rock python",
|
| 186 |
+
"Indian cobra",
|
| 187 |
+
"green mamba",
|
| 188 |
+
"sea snake",
|
| 189 |
+
"horned viper",
|
| 190 |
+
"diamondback",
|
| 191 |
+
"sidewinder",
|
| 192 |
+
"trilobite",
|
| 193 |
+
"harvestman",
|
| 194 |
+
"scorpion",
|
| 195 |
+
"black and gold garden spider",
|
| 196 |
+
"barn spider",
|
| 197 |
+
"garden spider",
|
| 198 |
+
"black widow",
|
| 199 |
+
"tarantula",
|
| 200 |
+
"wolf spider",
|
| 201 |
+
"tick",
|
| 202 |
+
"centipede",
|
| 203 |
+
"black grouse",
|
| 204 |
+
"ptarmigan",
|
| 205 |
+
"ruffed grouse",
|
| 206 |
+
"prairie chicken",
|
| 207 |
+
"peacock",
|
| 208 |
+
"quail",
|
| 209 |
+
"partridge",
|
| 210 |
+
"African grey",
|
| 211 |
+
"macaw",
|
| 212 |
+
"sulphur-crested cockatoo",
|
| 213 |
+
"lorikeet",
|
| 214 |
+
"coucal",
|
| 215 |
+
"bee eater",
|
| 216 |
+
"hornbill",
|
| 217 |
+
"hummingbird",
|
| 218 |
+
"jacamar",
|
| 219 |
+
"toucan",
|
| 220 |
+
"drake",
|
| 221 |
+
"red-breasted merganser",
|
| 222 |
+
"goose",
|
| 223 |
+
"black swan",
|
| 224 |
+
"tusker",
|
| 225 |
+
"echidna",
|
| 226 |
+
"platypus",
|
| 227 |
+
"wallaby",
|
| 228 |
+
"koala",
|
| 229 |
+
"wombat",
|
| 230 |
+
"jellyfish",
|
| 231 |
+
"sea anemone",
|
| 232 |
+
"brain coral",
|
| 233 |
+
"flatworm",
|
| 234 |
+
"nematode",
|
| 235 |
+
"conch",
|
| 236 |
+
"snail",
|
| 237 |
+
"slug",
|
| 238 |
+
"sea slug",
|
| 239 |
+
"chiton",
|
| 240 |
+
"chambered nautilus",
|
| 241 |
+
"Dungeness crab",
|
| 242 |
+
"rock crab",
|
| 243 |
+
"fiddler crab",
|
| 244 |
+
"king crab",
|
| 245 |
+
"American lobster",
|
| 246 |
+
"spiny lobster",
|
| 247 |
+
"crayfish",
|
| 248 |
+
"hermit crab",
|
| 249 |
+
"isopod",
|
| 250 |
+
"white stork",
|
| 251 |
+
"black stork",
|
| 252 |
+
"spoonbill",
|
| 253 |
+
"flamingo",
|
| 254 |
+
"little blue heron",
|
| 255 |
+
"American egret",
|
| 256 |
+
"bittern",
|
| 257 |
+
"crane",
|
| 258 |
+
"limpkin",
|
| 259 |
+
"European gallinule",
|
| 260 |
+
"American coot",
|
| 261 |
+
"bustard",
|
| 262 |
+
"ruddy turnstone",
|
| 263 |
+
"red-backed sandpiper",
|
| 264 |
+
"redshank",
|
| 265 |
+
"dowitcher",
|
| 266 |
+
"oystercatcher",
|
| 267 |
+
"pelican",
|
| 268 |
+
"king penguin",
|
| 269 |
+
"albatross",
|
| 270 |
+
"grey whale",
|
| 271 |
+
"killer whale",
|
| 272 |
+
"dugong",
|
| 273 |
+
"sea lion",
|
| 274 |
+
"Chihuahua",
|
| 275 |
+
"Japanese spaniel",
|
| 276 |
+
"Maltese dog",
|
| 277 |
+
"Pekinese",
|
| 278 |
+
"Shih-Tzu",
|
| 279 |
+
"Blenheim spaniel",
|
| 280 |
+
"papillon",
|
| 281 |
+
"toy terrier",
|
| 282 |
+
"Rhodesian ridgeback",
|
| 283 |
+
"Afghan hound",
|
| 284 |
+
"basset",
|
| 285 |
+
"beagle",
|
| 286 |
+
"bloodhound",
|
| 287 |
+
"bluetick",
|
| 288 |
+
"black-and-tan coonhound",
|
| 289 |
+
"Walker hound",
|
| 290 |
+
"English foxhound",
|
| 291 |
+
"redbone",
|
| 292 |
+
"borzoi",
|
| 293 |
+
"Irish wolfhound",
|
| 294 |
+
"Italian greyhound",
|
| 295 |
+
"whippet",
|
| 296 |
+
"Ibizan hound",
|
| 297 |
+
"Norwegian elkhound",
|
| 298 |
+
"otterhound",
|
| 299 |
+
"Saluki",
|
| 300 |
+
"Scottish deerhound",
|
| 301 |
+
"Weimaraner",
|
| 302 |
+
"Staffordshire bullterrier",
|
| 303 |
+
"American Staffordshire terrier",
|
| 304 |
+
"Bedlington terrier",
|
| 305 |
+
"Border terrier",
|
| 306 |
+
"Kerry blue terrier",
|
| 307 |
+
"Irish terrier",
|
| 308 |
+
"Norfolk terrier",
|
| 309 |
+
"Norwich terrier",
|
| 310 |
+
"Yorkshire terrier",
|
| 311 |
+
"wire-haired fox terrier",
|
| 312 |
+
"Lakeland terrier",
|
| 313 |
+
"Sealyham terrier",
|
| 314 |
+
"Airedale",
|
| 315 |
+
"cairn",
|
| 316 |
+
"Australian terrier",
|
| 317 |
+
"Dandie Dinmont",
|
| 318 |
+
"Boston bull",
|
| 319 |
+
"miniature schnauzer",
|
| 320 |
+
"giant schnauzer",
|
| 321 |
+
"standard schnauzer",
|
| 322 |
+
"Scotch terrier",
|
| 323 |
+
"Tibetan terrier",
|
| 324 |
+
"silky terrier",
|
| 325 |
+
"soft-coated wheaten terrier",
|
| 326 |
+
"West Highland white terrier",
|
| 327 |
+
"Lhasa",
|
| 328 |
+
"flat-coated retriever",
|
| 329 |
+
"curly-coated retriever",
|
| 330 |
+
"golden retriever",
|
| 331 |
+
"Labrador retriever",
|
| 332 |
+
"Chesapeake Bay retriever",
|
| 333 |
+
"German short-haired pointer",
|
| 334 |
+
"vizsla",
|
| 335 |
+
"English setter",
|
| 336 |
+
"Irish setter",
|
| 337 |
+
"Gordon setter",
|
| 338 |
+
"Brittany spaniel",
|
| 339 |
+
"clumber",
|
| 340 |
+
"English springer",
|
| 341 |
+
"Welsh springer spaniel",
|
| 342 |
+
"cocker spaniel",
|
| 343 |
+
"Sussex spaniel",
|
| 344 |
+
"Irish water spaniel",
|
| 345 |
+
"kuvasz",
|
| 346 |
+
"schipperke",
|
| 347 |
+
"groenendael",
|
| 348 |
+
"malinois",
|
| 349 |
+
"briard",
|
| 350 |
+
"kelpie",
|
| 351 |
+
"komondor",
|
| 352 |
+
"Old English sheepdog",
|
| 353 |
+
"Shetland sheepdog",
|
| 354 |
+
"collie",
|
| 355 |
+
"Border collie",
|
| 356 |
+
"Bouvier des Flandres",
|
| 357 |
+
"Rottweiler",
|
| 358 |
+
"German shepherd",
|
| 359 |
+
"Doberman",
|
| 360 |
+
"miniature pinscher",
|
| 361 |
+
"Greater Swiss Mountain dog",
|
| 362 |
+
"Bernese mountain dog",
|
| 363 |
+
"Appenzeller",
|
| 364 |
+
"EntleBucher",
|
| 365 |
+
"boxer",
|
| 366 |
+
"bull mastiff",
|
| 367 |
+
"Tibetan mastiff",
|
| 368 |
+
"French bulldog",
|
| 369 |
+
"Great Dane",
|
| 370 |
+
"Saint Bernard",
|
| 371 |
+
"Eskimo dog",
|
| 372 |
+
"malamute",
|
| 373 |
+
"Siberian husky",
|
| 374 |
+
"dalmatian",
|
| 375 |
+
"affenpinscher",
|
| 376 |
+
"basenji",
|
| 377 |
+
"pug",
|
| 378 |
+
"Leonberg",
|
| 379 |
+
"Newfoundland",
|
| 380 |
+
"Great Pyrenees",
|
| 381 |
+
"Samoyed",
|
| 382 |
+
"Pomeranian",
|
| 383 |
+
"chow",
|
| 384 |
+
"keeshond",
|
| 385 |
+
"Brabancon griffon",
|
| 386 |
+
"Pembroke",
|
| 387 |
+
"Cardigan",
|
| 388 |
+
"toy poodle",
|
| 389 |
+
"miniature poodle",
|
| 390 |
+
"standard poodle",
|
| 391 |
+
"Mexican hairless",
|
| 392 |
+
"timber wolf",
|
| 393 |
+
"white wolf",
|
| 394 |
+
"red wolf",
|
| 395 |
+
"coyote",
|
| 396 |
+
"dingo",
|
| 397 |
+
"dhole",
|
| 398 |
+
"African hunting dog",
|
| 399 |
+
"hyena",
|
| 400 |
+
"red fox",
|
| 401 |
+
"kit fox",
|
| 402 |
+
"Arctic fox",
|
| 403 |
+
"grey fox",
|
| 404 |
+
"tabby",
|
| 405 |
+
"tiger cat",
|
| 406 |
+
"Persian cat",
|
| 407 |
+
"Siamese cat",
|
| 408 |
+
"Egyptian cat",
|
| 409 |
+
"cougar",
|
| 410 |
+
"lynx",
|
| 411 |
+
"leopard",
|
| 412 |
+
"snow leopard",
|
| 413 |
+
"jaguar",
|
| 414 |
+
"lion",
|
| 415 |
+
"tiger",
|
| 416 |
+
"cheetah",
|
| 417 |
+
"brown bear",
|
| 418 |
+
"American black bear",
|
| 419 |
+
"ice bear",
|
| 420 |
+
"sloth bear",
|
| 421 |
+
"mongoose",
|
| 422 |
+
"meerkat",
|
| 423 |
+
"tiger beetle",
|
| 424 |
+
"ladybug",
|
| 425 |
+
"ground beetle",
|
| 426 |
+
"long-horned beetle",
|
| 427 |
+
"leaf beetle",
|
| 428 |
+
"dung beetle",
|
| 429 |
+
"rhinoceros beetle",
|
| 430 |
+
"weevil",
|
| 431 |
+
"fly",
|
| 432 |
+
"bee",
|
| 433 |
+
"ant",
|
| 434 |
+
"grasshopper",
|
| 435 |
+
"cricket",
|
| 436 |
+
"walking stick",
|
| 437 |
+
"cockroach",
|
| 438 |
+
"mantis",
|
| 439 |
+
"cicada",
|
| 440 |
+
"leafhopper",
|
| 441 |
+
"lacewing",
|
| 442 |
+
"dragonfly",
|
| 443 |
+
"damselfly",
|
| 444 |
+
"admiral",
|
| 445 |
+
"ringlet",
|
| 446 |
+
"monarch",
|
| 447 |
+
"cabbage butterfly",
|
| 448 |
+
"sulphur butterfly",
|
| 449 |
+
"lycaenid",
|
| 450 |
+
"starfish",
|
| 451 |
+
"sea urchin",
|
| 452 |
+
"sea cucumber",
|
| 453 |
+
"wood rabbit",
|
| 454 |
+
"hare",
|
| 455 |
+
"Angora",
|
| 456 |
+
"hamster",
|
| 457 |
+
"porcupine",
|
| 458 |
+
"fox squirrel",
|
| 459 |
+
"marmot",
|
| 460 |
+
"beaver",
|
| 461 |
+
"guinea pig",
|
| 462 |
+
"sorrel",
|
| 463 |
+
"zebra",
|
| 464 |
+
"hog",
|
| 465 |
+
"wild boar",
|
| 466 |
+
"warthog",
|
| 467 |
+
"hippopotamus",
|
| 468 |
+
"ox",
|
| 469 |
+
"water buffalo",
|
| 470 |
+
"bison",
|
| 471 |
+
"ram",
|
| 472 |
+
"bighorn",
|
| 473 |
+
"ibex",
|
| 474 |
+
"hartebeest",
|
| 475 |
+
"impala",
|
| 476 |
+
"gazelle",
|
| 477 |
+
"Arabian camel",
|
| 478 |
+
"llama",
|
| 479 |
+
"weasel",
|
| 480 |
+
"mink",
|
| 481 |
+
"polecat",
|
| 482 |
+
"black-footed ferret",
|
| 483 |
+
"otter",
|
| 484 |
+
"skunk",
|
| 485 |
+
"badger",
|
| 486 |
+
"armadillo",
|
| 487 |
+
"three-toed sloth",
|
| 488 |
+
"orangutan",
|
| 489 |
+
"gorilla",
|
| 490 |
+
"chimpanzee",
|
| 491 |
+
"gibbon",
|
| 492 |
+
"siamang",
|
| 493 |
+
"guenon",
|
| 494 |
+
"patas",
|
| 495 |
+
"baboon",
|
| 496 |
+
"macaque",
|
| 497 |
+
"langur",
|
| 498 |
+
"colobus",
|
| 499 |
+
"proboscis monkey",
|
| 500 |
+
"marmoset",
|
| 501 |
+
"capuchin",
|
| 502 |
+
"howler monkey",
|
| 503 |
+
"titi",
|
| 504 |
+
"spider monkey",
|
| 505 |
+
"squirrel monkey",
|
| 506 |
+
"Madagascar cat",
|
| 507 |
+
"indri",
|
| 508 |
+
"Indian elephant",
|
| 509 |
+
"African elephant",
|
| 510 |
+
"lesser panda",
|
| 511 |
+
"giant panda",
|
| 512 |
+
"barracouta",
|
| 513 |
+
"eel",
|
| 514 |
+
"coho",
|
| 515 |
+
"rock beauty",
|
| 516 |
+
"anemone fish",
|
| 517 |
+
"sturgeon",
|
| 518 |
+
"gar",
|
| 519 |
+
"lionfish",
|
| 520 |
+
"puffer",
|
| 521 |
+
"abacus",
|
| 522 |
+
"abaya",
|
| 523 |
+
"academic gown",
|
| 524 |
+
"accordion",
|
| 525 |
+
"acoustic guitar",
|
| 526 |
+
"aircraft carrier",
|
| 527 |
+
"airliner",
|
| 528 |
+
"airship",
|
| 529 |
+
"altar",
|
| 530 |
+
"ambulance",
|
| 531 |
+
"amphibian",
|
| 532 |
+
"analog clock",
|
| 533 |
+
"apiary",
|
| 534 |
+
"apron",
|
| 535 |
+
"ashcan",
|
| 536 |
+
"assault rifle",
|
| 537 |
+
"backpack",
|
| 538 |
+
"bakery",
|
| 539 |
+
"balance beam",
|
| 540 |
+
"balloon",
|
| 541 |
+
"ballpoint",
|
| 542 |
+
"Band Aid",
|
| 543 |
+
"banjo",
|
| 544 |
+
"bannister",
|
| 545 |
+
"barbell",
|
| 546 |
+
"barber chair",
|
| 547 |
+
"barbershop",
|
| 548 |
+
"barn",
|
| 549 |
+
"barometer",
|
| 550 |
+
"barrel",
|
| 551 |
+
"barrow",
|
| 552 |
+
"baseball",
|
| 553 |
+
"basketball",
|
| 554 |
+
"bassinet",
|
| 555 |
+
"bassoon",
|
| 556 |
+
"bathing cap",
|
| 557 |
+
"bath towel",
|
| 558 |
+
"bathtub",
|
| 559 |
+
"beach wagon",
|
| 560 |
+
"beacon",
|
| 561 |
+
"beaker",
|
| 562 |
+
"bearskin",
|
| 563 |
+
"beer bottle",
|
| 564 |
+
"beer glass",
|
| 565 |
+
"bell cote",
|
| 566 |
+
"bib",
|
| 567 |
+
"bicycle-built-for-two",
|
| 568 |
+
"bikini",
|
| 569 |
+
"binder",
|
| 570 |
+
"binoculars",
|
| 571 |
+
"birdhouse",
|
| 572 |
+
"boathouse",
|
| 573 |
+
"bobsled",
|
| 574 |
+
"bolo tie",
|
| 575 |
+
"bonnet",
|
| 576 |
+
"bookcase",
|
| 577 |
+
"bookshop",
|
| 578 |
+
"bottlecap",
|
| 579 |
+
"bow",
|
| 580 |
+
"bow tie",
|
| 581 |
+
"brass",
|
| 582 |
+
"brassiere",
|
| 583 |
+
"breakwater",
|
| 584 |
+
"breastplate",
|
| 585 |
+
"broom",
|
| 586 |
+
"bucket",
|
| 587 |
+
"buckle",
|
| 588 |
+
"bulletproof vest",
|
| 589 |
+
"bullet train",
|
| 590 |
+
"butcher shop",
|
| 591 |
+
"cab",
|
| 592 |
+
"caldron",
|
| 593 |
+
"candle",
|
| 594 |
+
"cannon",
|
| 595 |
+
"canoe",
|
| 596 |
+
"can opener",
|
| 597 |
+
"cardigan",
|
| 598 |
+
"car mirror",
|
| 599 |
+
"carousel",
|
| 600 |
+
"carpenter's kit",
|
| 601 |
+
"carton",
|
| 602 |
+
"car wheel",
|
| 603 |
+
"cash machine",
|
| 604 |
+
"cassette",
|
| 605 |
+
"cassette player",
|
| 606 |
+
"castle",
|
| 607 |
+
"catamaran",
|
| 608 |
+
"CD player",
|
| 609 |
+
"cello",
|
| 610 |
+
"cellular telephone",
|
| 611 |
+
"chain",
|
| 612 |
+
"chainlink fence",
|
| 613 |
+
"chain mail",
|
| 614 |
+
"chain saw",
|
| 615 |
+
"chest",
|
| 616 |
+
"chiffonier",
|
| 617 |
+
"chime",
|
| 618 |
+
"china cabinet",
|
| 619 |
+
"Christmas stocking",
|
| 620 |
+
"church",
|
| 621 |
+
"cinema",
|
| 622 |
+
"cleaver",
|
| 623 |
+
"cliff dwelling",
|
| 624 |
+
"cloak",
|
| 625 |
+
"clog",
|
| 626 |
+
"cocktail shaker",
|
| 627 |
+
"coffee mug",
|
| 628 |
+
"coffeepot",
|
| 629 |
+
"coil",
|
| 630 |
+
"combination lock",
|
| 631 |
+
"computer keyboard",
|
| 632 |
+
"confectionery",
|
| 633 |
+
"container ship",
|
| 634 |
+
"convertible",
|
| 635 |
+
"corkscrew",
|
| 636 |
+
"cornet",
|
| 637 |
+
"cowboy boot",
|
| 638 |
+
"cowboy hat",
|
| 639 |
+
"cradle",
|
| 640 |
+
"crane",
|
| 641 |
+
"crash helmet",
|
| 642 |
+
"crate",
|
| 643 |
+
"crib",
|
| 644 |
+
"Crock Pot",
|
| 645 |
+
"croquet ball",
|
| 646 |
+
"crutch",
|
| 647 |
+
"cuirass",
|
| 648 |
+
"dam",
|
| 649 |
+
"desk",
|
| 650 |
+
"desktop computer",
|
| 651 |
+
"dial telephone",
|
| 652 |
+
"diaper",
|
| 653 |
+
"digital clock",
|
| 654 |
+
"digital watch",
|
| 655 |
+
"dining table",
|
| 656 |
+
"dishrag",
|
| 657 |
+
"dishwasher",
|
| 658 |
+
"disk brake",
|
| 659 |
+
"dock",
|
| 660 |
+
"dogsled",
|
| 661 |
+
"dome",
|
| 662 |
+
"doormat",
|
| 663 |
+
"drilling platform",
|
| 664 |
+
"drum",
|
| 665 |
+
"drumstick",
|
| 666 |
+
"dumbbell",
|
| 667 |
+
"Dutch oven",
|
| 668 |
+
"electric fan",
|
| 669 |
+
"electric guitar",
|
| 670 |
+
"electric locomotive",
|
| 671 |
+
"entertainment center",
|
| 672 |
+
"envelope",
|
| 673 |
+
"espresso maker",
|
| 674 |
+
"face powder",
|
| 675 |
+
"feather boa",
|
| 676 |
+
"filing cabinet",
|
| 677 |
+
"fireboat",
|
| 678 |
+
"fire engine",
|
| 679 |
+
"fire screen",
|
| 680 |
+
"flagpole",
|
| 681 |
+
"flute",
|
| 682 |
+
"folding chair",
|
| 683 |
+
"football helmet",
|
| 684 |
+
"forklift",
|
| 685 |
+
"fountain",
|
| 686 |
+
"fountain pen",
|
| 687 |
+
"four-poster",
|
| 688 |
+
"freight car",
|
| 689 |
+
"French horn",
|
| 690 |
+
"frying pan",
|
| 691 |
+
"fur coat",
|
| 692 |
+
"garbage truck",
|
| 693 |
+
"gasmask",
|
| 694 |
+
"gas pump",
|
| 695 |
+
"goblet",
|
| 696 |
+
"go-kart",
|
| 697 |
+
"golf ball",
|
| 698 |
+
"golfcart",
|
| 699 |
+
"gondola",
|
| 700 |
+
"gong",
|
| 701 |
+
"gown",
|
| 702 |
+
"grand piano",
|
| 703 |
+
"greenhouse",
|
| 704 |
+
"grille",
|
| 705 |
+
"grocery store",
|
| 706 |
+
"guillotine",
|
| 707 |
+
"hair slide",
|
| 708 |
+
"hair spray",
|
| 709 |
+
"half track",
|
| 710 |
+
"hammer",
|
| 711 |
+
"hamper",
|
| 712 |
+
"hand blower",
|
| 713 |
+
"hand-held computer",
|
| 714 |
+
"handkerchief",
|
| 715 |
+
"hard disc",
|
| 716 |
+
"harmonica",
|
| 717 |
+
"harp",
|
| 718 |
+
"harvester",
|
| 719 |
+
"hatchet",
|
| 720 |
+
"holster",
|
| 721 |
+
"home theater",
|
| 722 |
+
"honeycomb",
|
| 723 |
+
"hook",
|
| 724 |
+
"hoopskirt",
|
| 725 |
+
"horizontal bar",
|
| 726 |
+
"horse cart",
|
| 727 |
+
"hourglass",
|
| 728 |
+
"iPod",
|
| 729 |
+
"iron",
|
| 730 |
+
"jack-o'-lantern",
|
| 731 |
+
"jean",
|
| 732 |
+
"jeep",
|
| 733 |
+
"jersey",
|
| 734 |
+
"jigsaw puzzle",
|
| 735 |
+
"jinrikisha",
|
| 736 |
+
"joystick",
|
| 737 |
+
"kimono",
|
| 738 |
+
"knee pad",
|
| 739 |
+
"knot",
|
| 740 |
+
"lab coat",
|
| 741 |
+
"ladle",
|
| 742 |
+
"lampshade",
|
| 743 |
+
"laptop",
|
| 744 |
+
"lawn mower",
|
| 745 |
+
"lens cap",
|
| 746 |
+
"letter opener",
|
| 747 |
+
"library",
|
| 748 |
+
"lifeboat",
|
| 749 |
+
"lighter",
|
| 750 |
+
"limousine",
|
| 751 |
+
"liner",
|
| 752 |
+
"lipstick",
|
| 753 |
+
"Loafer",
|
| 754 |
+
"lotion",
|
| 755 |
+
"loudspeaker",
|
| 756 |
+
"loupe",
|
| 757 |
+
"lumbermill",
|
| 758 |
+
"magnetic compass",
|
| 759 |
+
"mailbag",
|
| 760 |
+
"mailbox",
|
| 761 |
+
"maillot",
|
| 762 |
+
"maillot",
|
| 763 |
+
"manhole cover",
|
| 764 |
+
"maraca",
|
| 765 |
+
"marimba",
|
| 766 |
+
"mask",
|
| 767 |
+
"matchstick",
|
| 768 |
+
"maypole",
|
| 769 |
+
"maze",
|
| 770 |
+
"measuring cup",
|
| 771 |
+
"medicine chest",
|
| 772 |
+
"megalith",
|
| 773 |
+
"microphone",
|
| 774 |
+
"microwave",
|
| 775 |
+
"military uniform",
|
| 776 |
+
"milk can",
|
| 777 |
+
"minibus",
|
| 778 |
+
"miniskirt",
|
| 779 |
+
"minivan",
|
| 780 |
+
"missile",
|
| 781 |
+
"mitten",
|
| 782 |
+
"mixing bowl",
|
| 783 |
+
"mobile home",
|
| 784 |
+
"Model T",
|
| 785 |
+
"modem",
|
| 786 |
+
"monastery",
|
| 787 |
+
"monitor",
|
| 788 |
+
"moped",
|
| 789 |
+
"mortar",
|
| 790 |
+
"mortarboard",
|
| 791 |
+
"mosque",
|
| 792 |
+
"mosquito net",
|
| 793 |
+
"motor scooter",
|
| 794 |
+
"mountain bike",
|
| 795 |
+
"mountain tent",
|
| 796 |
+
"mouse",
|
| 797 |
+
"mousetrap",
|
| 798 |
+
"moving van",
|
| 799 |
+
"muzzle",
|
| 800 |
+
"nail",
|
| 801 |
+
"neck brace",
|
| 802 |
+
"necklace",
|
| 803 |
+
"nipple",
|
| 804 |
+
"notebook",
|
| 805 |
+
"obelisk",
|
| 806 |
+
"oboe",
|
| 807 |
+
"ocarina",
|
| 808 |
+
"odometer",
|
| 809 |
+
"oil filter",
|
| 810 |
+
"organ",
|
| 811 |
+
"oscilloscope",
|
| 812 |
+
"overskirt",
|
| 813 |
+
"oxcart",
|
| 814 |
+
"oxygen mask",
|
| 815 |
+
"packet",
|
| 816 |
+
"paddle",
|
| 817 |
+
"paddlewheel",
|
| 818 |
+
"padlock",
|
| 819 |
+
"paintbrush",
|
| 820 |
+
"pajama",
|
| 821 |
+
"palace",
|
| 822 |
+
"panpipe",
|
| 823 |
+
"paper towel",
|
| 824 |
+
"parachute",
|
| 825 |
+
"parallel bars",
|
| 826 |
+
"park bench",
|
| 827 |
+
"parking meter",
|
| 828 |
+
"passenger car",
|
| 829 |
+
"patio",
|
| 830 |
+
"pay-phone",
|
| 831 |
+
"pedestal",
|
| 832 |
+
"pencil box",
|
| 833 |
+
"pencil sharpener",
|
| 834 |
+
"perfume",
|
| 835 |
+
"Petri dish",
|
| 836 |
+
"photocopier",
|
| 837 |
+
"pick",
|
| 838 |
+
"pickelhaube",
|
| 839 |
+
"picket fence",
|
| 840 |
+
"pickup",
|
| 841 |
+
"pier",
|
| 842 |
+
"piggy bank",
|
| 843 |
+
"pill bottle",
|
| 844 |
+
"pillow",
|
| 845 |
+
"ping-pong ball",
|
| 846 |
+
"pinwheel",
|
| 847 |
+
"pirate",
|
| 848 |
+
"pitcher",
|
| 849 |
+
"plane",
|
| 850 |
+
"planetarium",
|
| 851 |
+
"plastic bag",
|
| 852 |
+
"plate rack",
|
| 853 |
+
"plow",
|
| 854 |
+
"plunger",
|
| 855 |
+
"Polaroid camera",
|
| 856 |
+
"pole",
|
| 857 |
+
"police van",
|
| 858 |
+
"poncho",
|
| 859 |
+
"pool table",
|
| 860 |
+
"pop bottle",
|
| 861 |
+
"pot",
|
| 862 |
+
"potter's wheel",
|
| 863 |
+
"power drill",
|
| 864 |
+
"prayer rug",
|
| 865 |
+
"printer",
|
| 866 |
+
"prison",
|
| 867 |
+
"projectile",
|
| 868 |
+
"projector",
|
| 869 |
+
"puck",
|
| 870 |
+
"punching bag",
|
| 871 |
+
"purse",
|
| 872 |
+
"quill",
|
| 873 |
+
"quilt",
|
| 874 |
+
"racer",
|
| 875 |
+
"racket",
|
| 876 |
+
"radiator",
|
| 877 |
+
"radio",
|
| 878 |
+
"radio telescope",
|
| 879 |
+
"rain barrel",
|
| 880 |
+
"recreational vehicle",
|
| 881 |
+
"reel",
|
| 882 |
+
"reflex camera",
|
| 883 |
+
"refrigerator",
|
| 884 |
+
"remote control",
|
| 885 |
+
"restaurant",
|
| 886 |
+
"revolver",
|
| 887 |
+
"rifle",
|
| 888 |
+
"rocking chair",
|
| 889 |
+
"rotisserie",
|
| 890 |
+
"rubber eraser",
|
| 891 |
+
"rugby ball",
|
| 892 |
+
"rule",
|
| 893 |
+
"running shoe",
|
| 894 |
+
"safe",
|
| 895 |
+
"safety pin",
|
| 896 |
+
"saltshaker",
|
| 897 |
+
"sandal",
|
| 898 |
+
"sarong",
|
| 899 |
+
"sax",
|
| 900 |
+
"scabbard",
|
| 901 |
+
"scale",
|
| 902 |
+
"school bus",
|
| 903 |
+
"schooner",
|
| 904 |
+
"scoreboard",
|
| 905 |
+
"screen",
|
| 906 |
+
"screw",
|
| 907 |
+
"screwdriver",
|
| 908 |
+
"seat belt",
|
| 909 |
+
"sewing machine",
|
| 910 |
+
"shield",
|
| 911 |
+
"shoe shop",
|
| 912 |
+
"shoji",
|
| 913 |
+
"shopping basket",
|
| 914 |
+
"shopping cart",
|
| 915 |
+
"shovel",
|
| 916 |
+
"shower cap",
|
| 917 |
+
"shower curtain",
|
| 918 |
+
"ski",
|
| 919 |
+
"ski mask",
|
| 920 |
+
"sleeping bag",
|
| 921 |
+
"slide rule",
|
| 922 |
+
"sliding door",
|
| 923 |
+
"slot",
|
| 924 |
+
"snorkel",
|
| 925 |
+
"snowmobile",
|
| 926 |
+
"snowplow",
|
| 927 |
+
"soap dispenser",
|
| 928 |
+
"soccer ball",
|
| 929 |
+
"sock",
|
| 930 |
+
"solar dish",
|
| 931 |
+
"sombrero",
|
| 932 |
+
"soup bowl",
|
| 933 |
+
"space bar",
|
| 934 |
+
"space heater",
|
| 935 |
+
"space shuttle",
|
| 936 |
+
"spatula",
|
| 937 |
+
"speedboat",
|
| 938 |
+
"spider web",
|
| 939 |
+
"spindle",
|
| 940 |
+
"sports car",
|
| 941 |
+
"spotlight",
|
| 942 |
+
"stage",
|
| 943 |
+
"steam locomotive",
|
| 944 |
+
"steel arch bridge",
|
| 945 |
+
"steel drum",
|
| 946 |
+
"stethoscope",
|
| 947 |
+
"stole",
|
| 948 |
+
"stone wall",
|
| 949 |
+
"stopwatch",
|
| 950 |
+
"stove",
|
| 951 |
+
"strainer",
|
| 952 |
+
"streetcar",
|
| 953 |
+
"stretcher",
|
| 954 |
+
"studio couch",
|
| 955 |
+
"stupa",
|
| 956 |
+
"submarine",
|
| 957 |
+
"suit",
|
| 958 |
+
"sundial",
|
| 959 |
+
"sunglass",
|
| 960 |
+
"sunglasses",
|
| 961 |
+
"sunscreen",
|
| 962 |
+
"suspension bridge",
|
| 963 |
+
"swab",
|
| 964 |
+
"sweatshirt",
|
| 965 |
+
"swimming trunks",
|
| 966 |
+
"swing",
|
| 967 |
+
"switch",
|
| 968 |
+
"syringe",
|
| 969 |
+
"table lamp",
|
| 970 |
+
"tank",
|
| 971 |
+
"tape player",
|
| 972 |
+
"teapot",
|
| 973 |
+
"teddy",
|
| 974 |
+
"television",
|
| 975 |
+
"tennis ball",
|
| 976 |
+
"thatch",
|
| 977 |
+
"theater curtain",
|
| 978 |
+
"thimble",
|
| 979 |
+
"thresher",
|
| 980 |
+
"throne",
|
| 981 |
+
"tile roof",
|
| 982 |
+
"toaster",
|
| 983 |
+
"tobacco shop",
|
| 984 |
+
"toilet seat",
|
| 985 |
+
"torch",
|
| 986 |
+
"totem pole",
|
| 987 |
+
"tow truck",
|
| 988 |
+
"toyshop",
|
| 989 |
+
"tractor",
|
| 990 |
+
"trailer truck",
|
| 991 |
+
"tray",
|
| 992 |
+
"trench coat",
|
| 993 |
+
"tricycle",
|
| 994 |
+
"trimaran",
|
| 995 |
+
"tripod",
|
| 996 |
+
"triumphal arch",
|
| 997 |
+
"trolleybus",
|
| 998 |
+
"trombone",
|
| 999 |
+
"tub",
|
| 1000 |
+
"turnstile",
|
| 1001 |
+
"typewriter keyboard",
|
| 1002 |
+
"umbrella",
|
| 1003 |
+
"unicycle",
|
| 1004 |
+
"upright",
|
| 1005 |
+
"vacuum",
|
| 1006 |
+
"vase",
|
| 1007 |
+
"vault",
|
| 1008 |
+
"velvet",
|
| 1009 |
+
"vending machine",
|
| 1010 |
+
"vestment",
|
| 1011 |
+
"viaduct",
|
| 1012 |
+
"violin",
|
| 1013 |
+
"volleyball",
|
| 1014 |
+
"waffle iron",
|
| 1015 |
+
"wall clock",
|
| 1016 |
+
"wallet",
|
| 1017 |
+
"wardrobe",
|
| 1018 |
+
"warplane",
|
| 1019 |
+
"washbasin",
|
| 1020 |
+
"washer",
|
| 1021 |
+
"water bottle",
|
| 1022 |
+
"water jug",
|
| 1023 |
+
"water tower",
|
| 1024 |
+
"whiskey jug",
|
| 1025 |
+
"whistle",
|
| 1026 |
+
"wig",
|
| 1027 |
+
"window screen",
|
| 1028 |
+
"window shade",
|
| 1029 |
+
"Windsor tie",
|
| 1030 |
+
"wine bottle",
|
| 1031 |
+
"wing",
|
| 1032 |
+
"wok",
|
| 1033 |
+
"wooden spoon",
|
| 1034 |
+
"wool",
|
| 1035 |
+
"worm fence",
|
| 1036 |
+
"wreck",
|
| 1037 |
+
"yawl",
|
| 1038 |
+
"yurt",
|
| 1039 |
+
"web site",
|
| 1040 |
+
"comic book",
|
| 1041 |
+
"crossword puzzle",
|
| 1042 |
+
"street sign",
|
| 1043 |
+
"traffic light",
|
| 1044 |
+
"book jacket",
|
| 1045 |
+
"menu",
|
| 1046 |
+
"plate",
|
| 1047 |
+
"guacamole",
|
| 1048 |
+
"consomme",
|
| 1049 |
+
"hot pot",
|
| 1050 |
+
"trifle",
|
| 1051 |
+
"ice cream",
|
| 1052 |
+
"ice lolly",
|
| 1053 |
+
"French loaf",
|
| 1054 |
+
"bagel",
|
| 1055 |
+
"pretzel",
|
| 1056 |
+
"cheeseburger",
|
| 1057 |
+
"hotdog",
|
| 1058 |
+
"mashed potato",
|
| 1059 |
+
"head cabbage",
|
| 1060 |
+
"broccoli",
|
| 1061 |
+
"cauliflower",
|
| 1062 |
+
"zucchini",
|
| 1063 |
+
"spaghetti squash",
|
| 1064 |
+
"acorn squash",
|
| 1065 |
+
"butternut squash",
|
| 1066 |
+
"cucumber",
|
| 1067 |
+
"artichoke",
|
| 1068 |
+
"bell pepper",
|
| 1069 |
+
"cardoon",
|
| 1070 |
+
"mushroom",
|
| 1071 |
+
"Granny Smith",
|
| 1072 |
+
"strawberry",
|
| 1073 |
+
"orange",
|
| 1074 |
+
"lemon",
|
| 1075 |
+
"fig",
|
| 1076 |
+
"pineapple",
|
| 1077 |
+
"banana",
|
| 1078 |
+
"jackfruit",
|
| 1079 |
+
"custard apple",
|
| 1080 |
+
"pomegranate",
|
| 1081 |
+
"hay",
|
| 1082 |
+
"carbonara",
|
| 1083 |
+
"chocolate sauce",
|
| 1084 |
+
"dough",
|
| 1085 |
+
"meatloaf",
|
| 1086 |
+
"pizza",
|
| 1087 |
+
"potpie",
|
| 1088 |
+
"burrito",
|
| 1089 |
+
"red wine",
|
| 1090 |
+
"espresso",
|
| 1091 |
+
"cup",
|
| 1092 |
+
"eggnog",
|
| 1093 |
+
"alp",
|
| 1094 |
+
"bubble",
|
| 1095 |
+
"cliff",
|
| 1096 |
+
"coral reef",
|
| 1097 |
+
"geyser",
|
| 1098 |
+
"lakeside",
|
| 1099 |
+
"promontory",
|
| 1100 |
+
"sandbar",
|
| 1101 |
+
"seashore",
|
| 1102 |
+
"valley",
|
| 1103 |
+
"volcano",
|
| 1104 |
+
"ballplayer",
|
| 1105 |
+
"groom",
|
| 1106 |
+
"scuba diver",
|
| 1107 |
+
"rapeseed",
|
| 1108 |
+
"daisy",
|
| 1109 |
+
"yellow lady's slipper",
|
| 1110 |
+
"corn",
|
| 1111 |
+
"acorn",
|
| 1112 |
+
"hip",
|
| 1113 |
+
"buckeye",
|
| 1114 |
+
"coral fungus",
|
| 1115 |
+
"agaric",
|
| 1116 |
+
"gyromitra",
|
| 1117 |
+
"stinkhorn",
|
| 1118 |
+
"earthstar",
|
| 1119 |
+
"hen-of-the-woods",
|
| 1120 |
+
"bolete",
|
| 1121 |
+
"ear",
|
| 1122 |
+
"toilet tissue"
|
| 1123 |
+
};
|
models/image_classification_ppresnet/demo.py
CHANGED
|
@@ -55,7 +55,12 @@ if __name__ == '__main__':
|
|
| 55 |
image = image[16:240, 16:240, :]
|
| 56 |
|
| 57 |
# Inference
|
| 58 |
-
result = model.infer(image)
|
| 59 |
|
| 60 |
# Print result
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
image = image[16:240, 16:240, :]
|
| 56 |
|
| 57 |
# Inference
|
| 58 |
+
result = model.infer(image)[0]
|
| 59 |
|
| 60 |
# Print result
|
| 61 |
+
if top_k == 1:
|
| 62 |
+
print(f"Predicted Label: {result[0]}")
|
| 63 |
+
else:
|
| 64 |
+
print("Predicted Top-K Labels (in decreasing confidence):")
|
| 65 |
+
for i, prediction in enumerate(result):
|
| 66 |
+
print(f"({i+1}) {prediction}")
|