ConvNet  1.0
A GPU-based C++ implementation of Convolutional Neural Nets
 All Classes Namespaces Functions Variables
util.h
1 #ifndef UTIL_H_
2 #define UTIL_H_
3 
4 #ifndef _GNU_SOURCE
5 #define _GNU_SOURCE
6 #endif
7 #ifndef __USE_GNU
8 #define __USE_GNU
9 #endif
10 
11 #include <string>
12 #define cimg_use_jpeg
13 #define cimg_use_lapack
14 #include "CImg.h"
15 #include "cudamat.cuh"
16 #include <stdio.h>
17 #include <google/protobuf/text_format.h>
18 #include "convnet_config.pb.h"
19 #include "hdf5.h"
20 #include <signal.h>
21 #include <execinfo.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <ucontext.h>
27 #include <unistd.h>
28 
29 using namespace cimg_library;
30 using namespace std;
31 
32 // Outputs a string that describes the err_code.
33 string GetStringError(int err_code);
34 // Reads model_file from the disk and instantiates a Model.
35 void ReadModel(const string& model_file, config::Model& model);
36 void ReadModelText(const string& model_file, config::Model& model);
37 void ReadDataConfig(const string& data_config_file, config::DatasetConfig& data_config);
38 void ReadLayerConfig(const string& layer_config_file, config::Layer& layer_config);
39 void WriteModelBinary(const string& output_file, const config::Model& model);
40 void ReadModelBinary(const string& input_file, config::Model& model);
41 void WriteHDF5CPU(hid_t file, float* mat, int rows, int cols, const string& name);
42 void ReadHDF5IntAttr(hid_t file, const string& name, int* val);
43 void WriteHDF5IntAttr(hid_t file, const string& name, const int* val);
44 
45 // mat must already be allocated. Use ReadHDF5Shape to figure out the shape, if needed.
46 void ReadHDF5CPU(hid_t file, float* mat, int size, const string& name);
47 void ReadHDF5Shape(hid_t file, const string& name, int* rows, int* cols);
48 void ReadHDF5ShapeFromFile(const string& file_name, const string& dataset_name, int* rows, int* cols);
49 
50 void SetupBackTraceHandler();
51 void WaitForEnter();
52 int Bound(int val, int lb, int ub);
53 string GetTimeStamp();
54 void TimestampModelFile(const string& src_file, const string& dest_file, const string& timestamp);
55 
56 bool ReadLines(const string& filename, vector<string>& lines);
57 
58 
60  public:
62  ImageDisplayer(int width, int height, int num_colors, bool show_separate, const string& name);
63  ~ImageDisplayer() { delete main_disp; delete disp; }
64  void SetTitle(const string& title) {title_ = title;}
65  void DisplayImage(float* data, int spacing, int image_id);
66  void DisplayWeights(float* data, int size, int num_filters, int display_size, bool yuv = false);
67  //void DisplayWeightStats(float* data, int size);
68  //void DisplayMathGL(mglGraph& gr);
69  CImgDisplay* main_disp, *disp;
70 
71  static void YUVToRGB(const float* yuv, float* rgb, int spacing);
72  static void RGBToYUV(const float* rgb, float* yuv, int spacing);
73 
74  private:
75  int width, height, num_colors;
76  bool show_separate;
77  string title_;
78 };
79 
80 
81 #endif
Definition: util.h:59
STL namespace.