41{
42 auto module = coco::Module::create();
43 auto blk = module->entity()->block()->create();
44 module->block()->append(blk);
45
47
48
50
51
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
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
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
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
125
126 module->output()->insert(output);
127 }
128
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
coco::Module * module(void) const
static std::unique_ptr< Data > create(void)