ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Frontend Class Referencefinal

#include <Frontend.h>

Collaboration diagram for Frontend:

Public Member Functions

 Frontend ()
 
::caffe::NetParameter * prototxt (void)
 
::caffe::NetParameter * caffemodel (void)
 
enco::Bundle load (void) const override
 
 Frontend (std::unique_ptr< RawModel > &&raw)
 
enco::Bundle load (void) const override
 
- Public Member Functions inherited from enco::Frontend
virtual ~Frontend ()=default
 

Detailed Description

Definition at line 26 of file Frontend.h.

Constructor & Destructor Documentation

◆ Frontend() [1/2]

Frontend::Frontend ( )

Definition at line 35 of file Frontend.cpp.

35 : _prototxt{new ::caffe::NetParameter}, _caffemodel{new ::caffe::NetParameter}
36{
37 // DO NOTHING
38}

◆ Frontend() [2/2]

Frontend::Frontend ( std::unique_ptr< RawModel > &&  raw)

Definition at line 125 of file Frontend.cpp.

125 : _raw{std::move(raw)}
126{
127 // DO NOTHING
128}

Member Function Documentation

◆ caffemodel()

::caffe::NetParameter * Frontend::caffemodel ( void  )
inline

Definition at line 33 of file Frontend.h.

33{ return _caffemodel.get(); }

◆ load() [1/2]

enco::Bundle Frontend::load ( void  ) const
overridevirtual

Implements enco::Frontend.

Definition at line 40 of file Frontend.cpp.

41{
42 auto module = coco::Module::create();
43 auto blk = module->entity()->block()->create();
44 module->block()->append(blk);
45
46 auto data = coco::Data::create();
47
48 // For weight access
49 caffeimport::WeightContext weight_ctx(_caffemodel.get());
50
51 // For inter-layer communication
52 std::map<std::string, tensor::Shape> shape_ctx;
53 std::map<std::string, coco::Bag *> bag_ctx;
54
55 std::set<std::string> bags;
56 std::map<std::string, uint32_t> def_count;
57 std::map<std::string, uint32_t> use_count;
58
59 auto def = [&bags, &def_count, &use_count](const std::string &name) {
60 if (bags.find(name) == bags.end())
61 {
62 bags.insert(name);
63 def_count[name] = 0;
64 use_count[name] = 0;
65 }
66
67 def_count.at(name) += 1;
68 };
69
70 auto use = [&use_count](const std::string &name) { use_count.at(name) += 1; };
71
72 auto outputs = [&bags, &def_count, &use_count](void) {
73 std::set<std::string> res;
74
75 for (const auto &bag : bags)
76 {
77 if (def_count.at(bag) > use_count.at(bag))
78 {
79 res.insert(bag);
80 }
81 }
82
83 return res;
84 };
85
86 caffeimport::GraphBuilderContext opbuilder_context(module.get(), data.get(), blk, shape_ctx,
87 bag_ctx, weight_ctx);
88
89 for (const auto &layer : _prototxt->layer())
90 {
91 assert(layer.has_name());
92 assert(layer.has_type());
93
94 for (uint32_t n = 0; n < layer.top().size(); ++n)
95 {
96 def(layer.top(n));
97 }
98
99 for (uint32_t n = 0; n < layer.bottom().size(); ++n)
100 {
101 use(layer.bottom(n));
102 }
103
104 if (const auto *graph_builder = caffeimport::GraphBuilderRegistry::get().lookup(layer.type()))
105 {
106 graph_builder->build(layer, &opbuilder_context);
107 }
108 else
109 {
110 throw std::runtime_error{"Not supported: " + layer.type()};
111 }
112 }
113
114 // Finalize: Create output for each top blob
115 for (const auto &name : outputs())
116 {
117 const auto &shape = shape_ctx.at(name);
118 auto bag = bag_ctx.at(name);
119
120 auto output = module->entity()->output()->create(shape);
121
122 output->bag(bag);
123 output->name(name);
124 output->reorder<LexicalLayout>();
125
126 module->output()->insert(output);
127 }
128
129 enco::Bundle bundle;
130
131 bundle.module(std::move(module));
132 bundle.data(std::move(data));
133
134 return std::move(bundle);
135}
static GraphBuilderRegistry & get()
coco::Data * data(void) const
Definition Bundle.h:38
coco::Module * module(void) const
Definition Bundle.h:34
int32_t size[5]
Definition Slice.cpp:35
static std::unique_ptr< Data > create(void)
Definition Data.cpp:202

References coco::Data::create(), enco::Bundle::data(), caffeimport::GraphBuilderRegistry::get(), enco::Bundle::module(), and size.

◆ load() [2/2]

enco::Bundle Frontend::load ( void  ) const
overridevirtual

Implements enco::Frontend.

◆ prototxt()

::caffe::NetParameter * Frontend::prototxt ( void  )
inline

Definition at line 32 of file Frontend.h.

32{ return _prototxt.get(); }

The documentation for this class was generated from the following files: