ONE - On-device Neural Engine
Loading...
Searching...
No Matches
tensor_gen.cpp File Reference
#include <vector>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <functional>
#include <algorithm>
#include <H5Cpp.h>

Go to the source code of this file.

Data Structures

class  Tensor
 

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 167 of file tensor_gen.cpp.

168{
169 if (argc < 4)
170 {
171 cout << "Usage: " << argv[0] << " <tensor name> <output file name> dim0, dim1, dim2, ..."
172 << endl;
173 cout << "Where: dim0, dim1, dim2, ... are the generated tensor shape dimensions" << endl;
174 return 1;
175 }
176
177 vector<hsize_t> dimensions;
178
179 for (int i = 3; i < argc; ++i)
180 {
181 try
182 {
183 int d = stoi(argv[i]);
184
185 if (d <= 0)
186 {
187 cout << "The dimensions must be positive values. This is not a correct dimension value: "
188 << d << endl;
189 return 1;
190 }
191
192 dimensions.push_back(d);
193 }
194 catch (const invalid_argument &)
195 {
196 cout << "The parameter does not look as an integer value: " << argv[i] << endl;
197 return 1;
198 }
199 catch (const out_of_range &)
200 {
201 cout << "The value is out of the C++ \"int\" type range: " << argv[i] << endl;
202 return 1;
203 }
204 }
205
206 Tensor caffe_tensor(dimensions);
207 fillTensor(caffe_tensor);
208 writeTensorToHDF5File(dimensions, argv[1], "in_" + string(argv[2]) + "_caffe", caffe_tensor);
209
210 vector<hsize_t> tf_reshape{0, 2, 3, 1};
211 Tensor tf_tensor = caffe_tensor.transpose(tf_reshape);
212 writeTensorToDatFile(string(argv[2]) + "_tf", tf_tensor);
213
214 return 0;
215}
Tensor transpose(const vector< hsize_t > &reshape)

References Tensor::transpose().