Reformat code.
This commit is contained in:
126
src/Options.cpp
126
src/Options.cpp
@@ -1,18 +1,16 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "Options.hpp"
|
#include "Options.hpp"
|
||||||
|
|
||||||
using namespace fmri;
|
using namespace fmri;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static void show_help(const char* progname, int exitcode)
|
static void show_help(const char *progname, int exitcode) {
|
||||||
{
|
cerr << "Usage: " << progname << " -m MODEL -w WEIGHTS INPUTS..." << endl
|
||||||
cerr << "Usage: " << progname << " -m MODEL -w WEIGHTS INPUTS..." << endl
|
<< endl
|
||||||
<< endl
|
<< R"END(
|
||||||
<< R"END(
|
|
||||||
Simulate the specified network on the specified inputs.
|
Simulate the specified network on the specified inputs.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
@@ -21,88 +19,82 @@ Options:
|
|||||||
-w (required) the trained weights
|
-w (required) the trained weights
|
||||||
)END" << endl;
|
)END" << endl;
|
||||||
|
|
||||||
exit(exitcode);
|
exit(exitcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_file(const char * filename)
|
static void check_file(const char *filename) {
|
||||||
{
|
if (access(filename, R_OK) != 0) {
|
||||||
if (access(filename, R_OK) != 0) {
|
perror(filename);
|
||||||
perror(filename);
|
exit(1);
|
||||||
exit(1);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Options Options::parse(const int argc, char * const argv[])
|
Options Options::parse(const int argc, char *const argv[]) {
|
||||||
{
|
string model;
|
||||||
string model;
|
string weights;
|
||||||
string weights;
|
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "hm:w:")) != -1) {
|
while ((c = getopt(argc, argv, "hm:w:")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
show_help(argv[0], 0);
|
show_help(argv[0], 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
check_file(optarg);
|
check_file(optarg);
|
||||||
weights = optarg;
|
weights = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
check_file(optarg);
|
check_file(optarg);
|
||||||
model = optarg;
|
model = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
show_help(argv[0], 1);
|
show_help(argv[0], 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weights.empty()) {
|
if (weights.empty()) {
|
||||||
cerr << "Weights file is required!" << endl;
|
cerr << "Weights file is required!" << endl;
|
||||||
show_help(argv[0], 1);
|
show_help(argv[0], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.empty()) {
|
if (model.empty()) {
|
||||||
cerr << "Model file is required!" << endl;
|
cerr << "Model file is required!" << endl;
|
||||||
show_help(argv[0], 1);
|
show_help(argv[0], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for_each(argv + optind, argv + argc, check_file);
|
for_each(argv + optind, argv + argc, check_file);
|
||||||
|
|
||||||
vector<string> inputs(argv + optind, argv + argc);
|
vector<string> inputs(argv + optind, argv + argc);
|
||||||
if (inputs.empty()) {
|
if (inputs.empty()) {
|
||||||
cerr << "No inputs specified" << endl;
|
cerr << "No inputs specified" << endl;
|
||||||
show_help(argv[0], 1);
|
show_help(argv[0], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Options(move(model), move(weights), move(inputs));
|
return Options(move(model), move(weights), move(inputs));
|
||||||
}
|
}
|
||||||
|
|
||||||
Options::Options(string&& model, string&& weights, vector<string>&& inputs) noexcept:
|
Options::Options(string &&model, string &&weights, vector<string> &&inputs) noexcept:
|
||||||
modelPath(move(model)),
|
modelPath(move(model)),
|
||||||
weightsPath(move(weights)),
|
weightsPath(move(weights)),
|
||||||
inputPaths(move(inputs))
|
inputPaths(move(inputs)) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& Options::model() const
|
const string &Options::model() const {
|
||||||
{
|
return modelPath;
|
||||||
return modelPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& Options::weights() const
|
const string &Options::weights() const {
|
||||||
{
|
return weightsPath;
|
||||||
return weightsPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const vector<string>& Options::inputs() const
|
const vector<string> &Options::inputs() const {
|
||||||
{
|
return inputPaths;
|
||||||
return inputPaths;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,23 +5,24 @@
|
|||||||
|
|
||||||
namespace fmri {
|
namespace fmri {
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
class Options
|
class Options {
|
||||||
{
|
public:
|
||||||
public:
|
static Options parse(const int argc, char *const argv[]);
|
||||||
static Options parse(const int argc, char * const argv[]);
|
|
||||||
|
|
||||||
const string& model() const;
|
const string &model() const;
|
||||||
const string& weights() const;
|
|
||||||
const vector<string>& inputs() const;
|
|
||||||
|
|
||||||
private:
|
const string &weights() const;
|
||||||
const string modelPath;
|
|
||||||
const string weightsPath;
|
|
||||||
const vector<string> inputPaths;
|
|
||||||
|
|
||||||
Options(string&&, string&&, vector<string>&&) noexcept;
|
const vector<string> &inputs() const;
|
||||||
};
|
|
||||||
|
private:
|
||||||
|
const string modelPath;
|
||||||
|
const string weightsPath;
|
||||||
|
const vector<string> inputPaths;
|
||||||
|
|
||||||
|
Options(string &&, string &&, vector<string> &&) noexcept;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
|
||||||
#include "Simulator.hpp"
|
#include "Simulator.hpp"
|
||||||
|
|
||||||
using namespace caffe;
|
using namespace caffe;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace fmri;
|
using namespace fmri;
|
||||||
|
|
||||||
Simulator::Simulator(const string& model_file, const string& weights_file) :
|
Simulator::Simulator(const string &model_file, const string &weights_file) :
|
||||||
net(model_file, TEST)
|
net(model_file, TEST) {
|
||||||
{
|
net.CopyTrainedLayersFrom(weights_file);
|
||||||
net.CopyTrainedLayersFrom(weights_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulator::simulate(const string& image_file)
|
void Simulator::simulate(const string &image_file) {
|
||||||
{
|
cerr << "This is not implemented yet." << endl;
|
||||||
cerr << "This is not implemented yet." << endl;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,17 +6,17 @@
|
|||||||
#include <caffe/caffe.hpp>
|
#include <caffe/caffe.hpp>
|
||||||
|
|
||||||
namespace fmri {
|
namespace fmri {
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
class Simulator {
|
class Simulator {
|
||||||
public:
|
public:
|
||||||
typedef float DType;
|
typedef float DType;
|
||||||
|
|
||||||
Simulator(const string& model_file, const string& weights_file);
|
Simulator(const string &model_file, const string &weights_file);
|
||||||
|
|
||||||
void simulate(const string& input_file);
|
void simulate(const string &input_file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caffe::Net<DType> net;
|
caffe::Net<DType> net;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/main.cpp
17
src/main.cpp
@@ -5,17 +5,16 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace fmri;
|
using namespace fmri;
|
||||||
|
|
||||||
int main(int argc, char * const argv[])
|
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);
|
||||||
|
|
||||||
Simulator simulator(options.model(), options.weights());
|
Simulator simulator(options.model(), options.weights());
|
||||||
|
|
||||||
for (const auto& image : options.inputs()) {
|
for (const auto &image : options.inputs()) {
|
||||||
simulator.simulate(image);
|
simulator.simulate(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user