MachineIntelligenceCore:NeuralNets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
mnist_batch_visualization_test.cpp
Go to the documentation of this file.
1 
26 #include <boost/thread/thread.hpp>
27 #include <boost/bind.hpp>
28 
29 #include <importers/MNISTMatrixImporter.hpp>
30 
31 #include <logger/Log.hpp>
32 #include <logger/ConsoleOutput.hpp>
33 using namespace mic::logger;
34 
35 #include <application/ApplicationState.hpp>
36 
37 #include <configuration/ParameterServer.hpp>
38 
39 #include <opengl/visualization/WindowManager.hpp>
40 #include <opengl/visualization/WindowGrayscaleBatch.hpp>
41 using namespace mic::opengl::visualization;
42 
44 WindowGrayscaleBatch<float>* w_batch;
46 mic::importers::MNISTMatrixImporter<float>* importer;
47 
48 
53 void batch_function (void) {
54  // Main application loop.
55  while (!APP_STATE->Quit()) {
56 
57  // If not paused.
58  if (!APP_STATE->isPaused()) {
59 
60  // If single step mode - pause after the step.
61  if (APP_STATE->isSingleStepModeOn())
62  APP_STATE->pressPause();
63 
64  { // Enter critical section - with the use of scoped lock from AppState!
65  APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
66 
67  // Retrieve the next minibatch.
68  mic::types::MNISTBatch<float> bt = importer->getNextBatch();
69 
70  // Set batch to be displayed.
71  w_batch->setBatchUnsynchronized(bt.data());
72 
73  }//: end of critical section
74 
75  }//: if
76 
77  // Sleep.
78  APP_SLEEP();
79  }//: while
80 
81 }//: image_encoder_and_visualization_test
82 
83 
84 
92 int main(int argc, char* argv[]) {
93  // Set console output to logger.
94  LOGGER->addOutput(new ConsoleOutput());
95  LOG(LINFO) << "Logger initialized. Starting application";
96 
97  // Parse parameters.
98  PARAM_SERVER->parseApplicationParameters(argc, argv);
99 
100  // Initilize application state ("touch it") ;)
101  APP_STATE;
102 
103  // Load dataset.
104  importer = new mic::importers::MNISTMatrixImporter<float>();
105  importer->setBatchSize(100);
106 
107  // Set parameters of all property-tree derived objects - USER independent part.
108  PARAM_SERVER->loadPropertiesFromConfiguration();
109 
110  // Initialize property-dependent variables of all registered property-tree objects - USER dependent part.
111  PARAM_SERVER->initializePropertyDependentVariables();
112 
113  // Import data from datasets.
114  if (!importer->importData())
115  return -1;
116 
117  // Initialize GLUT! :]
118  VGL_MANAGER->initializeGLUT(argc, argv);
119 
120  // Create batch visualization window.
121  w_batch = new WindowGrayscaleBatch<float>("MNIST batch", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 0, 0, 256, 256);
122 
123  boost::thread batch_thread(boost::bind(&batch_function));
124 
125  // Start visualization thread.
126  VGL_MANAGER->startVisualizationLoop();
127 
128  LOG(LINFO) << "Waiting for threads to join...";
129  // End test thread.
130  batch_thread.join();
131  LOG(LINFO) << "Threads joined - ending application";
132 }//: main
void batch_function(void)
Function for batch sampling.
int main(int argc, char *argv[])
Main program function. Runs two threads: main (for GLUT) and another one (for data processing)...
mic::importers::MNISTMatrixImporter< float > * importer
MNIST importer.
WindowGrayscaleBatch< float > * w_batch
Window for displaying the MNIST batch.