Print labels with score upon finish, if available.

This commit is contained in:
2017-10-09 13:54:48 +02:00
parent 7571fab20d
commit f43ffd717d
2 changed files with 60 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
#include <algorithm>
#include <iostream> #include <iostream>
#include "Options.hpp" #include "Options.hpp"
#include "Simulator.hpp" #include "Simulator.hpp"
#include "utils.hpp"
using namespace std; using namespace std;
using namespace fmri; using namespace fmri;
@@ -9,11 +11,25 @@ int main(int argc, char *const argv[]) {
::google::InitGoogleLogging(argv[0]); ::google::InitGoogleLogging(argv[0]);
Options options = Options::parse(argc, argv); Options options = Options::parse(argc, argv);
vector<string> labels;
if (options.labels() != "") {
labels = read_vector<string>(options.labels());
}
Simulator simulator(options.model(), options.weights(), options.means()); Simulator simulator(options.model(), options.weights(), options.means());
for (const auto &image : options.inputs()) { for (const auto &image : options.inputs()) {
simulator.simulate(image); cout << "Result for " << image << ":" << endl;
auto res = simulator.simulate(image);
if (!labels.empty()) {
for (unsigned int i = 0; i < res.size(); ++i) {
cout << res[i] << " " << labels[i] << endl;
}
} else {
cout << "Best result: " << *(max_element(res.begin(), res.end())) << endl;
}
cout << endl;
} }
::google::ShutdownGoogleLogging(); ::google::ShutdownGoogleLogging();

43
src/utils.hpp Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
#include <cassert>
#include <fstream>
#include <vector>
#include <string>
namespace fmri
{
template<class T>
inline std::vector <T> read_vector(const std::string& filename)
{
std::ifstream input(filename);
assert(input.good());
T t;
std::vector<T> res;
while (input >> t) {
res.push_back(t);
}
return res;
}
template<>
inline std::vector<std::string> read_vector<std::string>(const std::string& filename)
{
std::ifstream input(filename);
assert(input.good());
std::string v;
std::vector<std::string> res;
while (getline(input, v)) {
res.push_back(v);
}
return res;
}
}