Move Caffe simulation to a separate thread.
Teapot now shows pretty much instantly after starting the program, and then only reappears when switching inputs.
This commit is contained in:
@@ -17,39 +17,6 @@
|
||||
using namespace std;
|
||||
using namespace fmri;
|
||||
|
||||
static void loadSimulationData(const Options &options)
|
||||
{
|
||||
vector<vector<LayerData>> results;
|
||||
|
||||
auto dumper = options.imageDumper();
|
||||
Simulator simulator(options.model(), options.weights(), options.means());
|
||||
|
||||
for (const auto &image : options.inputs()) {
|
||||
results.emplace_back(simulator.simulate(image));
|
||||
}
|
||||
|
||||
CHECK_GT(results.size(), 0) << "Should have some results" << endl;
|
||||
|
||||
if (dumper) {
|
||||
for (auto &layer : *results.begin()) {
|
||||
dumper->dump(layer);
|
||||
}
|
||||
}
|
||||
|
||||
const auto optLabels = options.labels();
|
||||
|
||||
if (optLabels) {
|
||||
auto& labels = *optLabels;
|
||||
for (const auto& result : results) {
|
||||
auto &last = *result.rbegin();
|
||||
auto bestIndex = std::distance(last.data(), max_element(last.data(), last.data() + last.numEntries()));
|
||||
LOG(INFO) << "Got answer: " << labels[bestIndex] << endl;
|
||||
}
|
||||
}
|
||||
|
||||
RenderingState::instance().loadSimulationData(simulator.layerInfo(), std::move(results));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
@@ -64,7 +31,6 @@ int main(int argc, char *argv[])
|
||||
// Prepare data for simulations
|
||||
Options options(argc, argv);
|
||||
RenderingState::instance().loadOptions(options);
|
||||
loadSimulationData(options);
|
||||
|
||||
// Register callbacks
|
||||
glutReshapeFunc(changeWindowSize);
|
||||
|
||||
Reference in New Issue
Block a user