| 233 | } |
| 234 | |
| 235 | int main(int argc, char** argv) |
| 236 | { |
| 237 | if(argc != 6) |
| 238 | { |
| 239 | std::cerr << "Usage: " << argv[0] << " deploy.prototxt network.caffemodel" |
| 240 | << " mean.binaryproto labels.txt img.jpg" << std::endl; |
| 241 | return 1; |
| 242 | } |
| 243 | |
| 244 | ::google::InitGoogleLogging(argv[0]); |
| 245 | |
| 246 | string model_file = argv[1]; |
| 247 | string trained_file = argv[2]; |
| 248 | string mean_file = argv[3]; |
| 249 | string label_file = argv[4]; |
| 250 | Classifier classifier(model_file, trained_file, mean_file, label_file); |
| 251 | |
| 252 | string file = argv[5]; |
| 253 | |
| 254 | std::cout << "---------- Prediction for " << file << " ----------" << std::endl; |
| 255 | |
| 256 | cv::Mat img = cv::imread(file, -1); |
| 257 | CHECK(!img.empty()) << "Unable to decode image " << file; |
| 258 | std::vector<Prediction> predictions = classifier.Classify(img); |
| 259 | |
| 260 | /* Print the top N predictions. */ |
| 261 | for(size_t i = 0; i < predictions.size(); ++i) |
| 262 | { |
| 263 | Prediction p = predictions[i]; |
| 264 | std::cout << std::fixed << std::setprecision(4) << p.second << " - \"" << p.first << "\"" << std::endl; |
| 265 | } |
| 266 | } |
| 267 | #else |
| 268 | int main(int argc, char** argv) |
| 269 | { |