ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp File Reference
#include "tflchef/ModelChef.h"
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
#include <arser/arser.h>
#include <fstream>
#include <iostream>

Go to the source code of this file.

Functions

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 28 of file Driver.cpp.

29{
31 arser.add_argument("recipe").help("Source recipe file path to convert");
32 arser.add_argument("tflite").help("Target tflite file path");
33
34 try
35 {
36 arser.parse(argc, argv);
37 }
38 catch (const std::runtime_error &err)
39 {
40 std::cout << err.what() << std::endl;
41 std::cout << arser;
42 return 255;
43 }
44
45 int32_t model_version = 1;
46
47 ::tflchef::ModelRecipe model_recipe;
48
49 std::string recipe_path = arser.get<std::string>("recipe");
50 // Load model recipe from a file
51 {
52 std::ifstream is{recipe_path};
53 google::protobuf::io::IstreamInputStream iis{&is};
54 if (!google::protobuf::TextFormat::Parse(&iis, &model_recipe))
55 {
56 std::cerr << "ERROR: Failed to parse recipe '" << recipe_path << "'" << std::endl;
57 return 255;
58 }
59
60 if (model_recipe.has_version())
61 {
62 model_version = model_recipe.version();
63 }
64 }
65
66 if (model_version > 1)
67 {
68 std::cerr << "ERROR: Unsupported recipe version: " << model_version << ", '" << recipe_path
69 << "'" << std::endl;
70 return 255;
71 }
72
73 auto generated_model = tflchef::cook(model_recipe);
74
75 std::string tflite_path = arser.get<std::string>("tflite");
76 // Dump generated model into a file
77 {
78 std::ofstream os{tflite_path, std::ios::binary};
79 os.write(generated_model.base(), generated_model.size());
80 }
81
82 return 0;
83}
Definition arser.h:39
GeneratedModel cook(const ModelRecipe &model_recipe)

References tflchef::cook().