ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp File Reference
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <arser/arser.h>
#include "CircleModel.h"
#include "TFLModel.h"
#include <vconone/vconone.h>

Go to the source code of this file.

Functions

void print_version (void)
 
int entry (int argc, char **argv)
 Dump IR for given arguments.
 

Function Documentation

◆ entry()

int entry ( int  argc,
char **  argv 
)

Dump IR for given arguments.

Call example: $ ./build/compiler/encodump/encodump \ –frontend build/compiler/enco/frontend/caffe/libenco_caffe_frontend.so \ –frontend-arg build/compiler/enco/test/caffe/Convolution_003.prototxt \ –frontend-arg build/compiler/enco/test/caffe/Convolution_003.caffemodel

HDF5 layout is like below

GROUP "/" ㄴGROUP "name" ㄴATTRIBUTE "0" ㄴDATA (0): "input_01:0" ㄴATTRIBUTE "1" ㄴDATA (0): "input_02:0" ㄴGROUP "value" ㄴDATASET "0" ㄴDATA ... ㄴDATASET "1" ㄴDATA ...

Definition at line 35 of file Driver.cpp.

36{
37 arser::Arser arser{"tflite2circle is a Tensorflow lite to circle model converter"};
38
41
42 arser.add_argument("tflite").help("Source tflite file path to convert");
43 arser.add_argument("circle").help("Target circle file path");
44
45 try
46 {
47 arser.parse(argc, argv);
48 }
49 catch (const std::runtime_error &err)
50 {
51 std::cerr << err.what() << std::endl;
52 std::cout << arser;
53 return 255;
54 }
55
56 std::string tfl_path = arser.get<std::string>("tflite");
57 std::string circle_path = arser.get<std::string>("circle");
58 // read tflite file
59 tflite2circle::TFLModel tfl_model(tfl_path);
60 if (not tfl_model.verify_data())
61 {
62 std::cerr << "ERROR: Failed to verify tflite '" << tfl_path << "'" << std::endl;
63 return 255;
64 }
65
66 // create flatbuffer builder
67 auto flatbuffer_builder = std::make_unique<flatbuffers::FlatBufferBuilder>(1024);
68
69 // convert tflite to circle
70 const std::vector<char> &raw_data = tfl_model.raw_data();
71 tflite2circle::CircleModel circle_model{flatbuffer_builder, raw_data};
72
73 circle_model.load_offsets(tfl_model.get_model());
74 circle_model.model_build();
75 circle_model.finalize();
76
77 std::ofstream outfile{circle_path, std::ios::binary};
78
79 outfile.write(circle_model.base(), circle_model.size());
80 outfile.close();
81 // TODO find a better way of error handling
82 if (outfile.fail())
83 {
84 std::cerr << "ERROR: Failed to write circle '" << circle_path << "'" << std::endl;
85 return 255;
86 }
87
88 return 0;
89}
static void add_version(Arser &arser, const std::function< void(void)> &func)
Definition arser.h:755
static void add_verbose(Arser &arser)
Definition arser.h:765
void print_version(void)
Definition Driver.cpp:36
Definition arser.h:39

References arser::Helper::add_verbose(), arser::Helper::add_version(), and print_version().

◆ print_version()

void print_version ( void  )

Definition at line 29 of file Driver.cpp.

30{
31 std::cout << "tflite2circle version " << vconone::get_string() << std::endl;
32 std::cout << vconone::get_copyright() << std::endl;
33}
std::string get_copyright(void)
get_copyright will return copyright string
Definition version.cpp:54
std::string get_string(void)
get_string will return string of major.minor.patch (without build)
Definition version.cpp:44

References vconone::get_copyright(), and vconone::get_string().