Search Results

1 /*
2 * MIT License
3 *
4 * Copyright (c) 2020 International Business Machines
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24 
25 #ifndef PARSER_H_
26 #define PARSER_H_
27 
28 #define BOOST_UBLAS_INLINE
29 #include <boost/numeric/ublas/tensor.hpp>
30 
31 #include <vector>
32 #include "H5Cpp.h"
33 
34 namespace helayers {
35 
36 #define BIAS_RANK 1
37 #define DENSE_RANK 2
38 #define FILTER_RANK 4
39 
41 class H5Parser
42 {
43 protected:
44  std::string file_name;
45  H5::H5File file;
46 
47 public:
50  H5Parser(std::string f);
51 
52  virtual ~H5Parser();
53 
59  void readData(const std::string& path, double& val) const;
60 
68  void readData(const std::string& path,
69  std::vector<double>& vals,
70  std::vector<int>& dims) const;
71 
76  void readData(const std::string& path,
77  boost::numeric::ublas::tensor<double>& vals) const;
78 
80  std::vector<double> parseBias(std::string path) const;
81 
83  std::vector<std::vector<double>> parseFC(std::string path) const;
84 
86  std::vector<std::vector<std::vector<double>>> parseFilters(
87  std::string path) const;
88 
90  bool objectExists(const std::string& name) const;
91 
93  inline H5::H5File& getFile() { return file; }
94 
95  // bool sameHierarchy(const H5Parser& other) const;
96 };
97 }
98 
99 #endif /* PARSER_H_ */
std::vector< std::vector< std::vector< double > > > parseFilters(std::string path) const
Loads convolution layer filters from a given path inside file.
Definition: h5Parser.cpp:257
A simple utility class for loading data from h5 files.
Definition: h5Parser.h:41
void readData(const std::string &path, double &val) const
Reads the scalar from the given path into "val".
Definition: h5Parser.cpp:62
std::vector< std::vector< double > > parseFC(std::string path) const
Loads fully-connected layer weights from a given path inside file.
Definition: h5Parser.cpp:207
H5::H5File & getFile()
Returns underlying H5File object.
Definition: h5Parser.h:93
std::vector< double > parseBias(std::string path) const
Loads fully-connected layer bias from a given path inside file.
Definition: h5Parser.cpp:165
bool objectExists(const std::string &name) const
Checks if given name exists in file.
Definition: h5Parser.cpp:38
H5Parser(std::string f)
Constructor.
Definition: h5Parser.cpp:50