42 auto module = coco::Module::create();
43 auto blk =
module->entity()->block()->create();
44 module->block()->append(blk);
52 std::map<std::string, tensor::Shape> shape_ctx;
53 std::map<std::string, coco::Bag *> bag_ctx;
55 std::set<std::string> bags;
56 std::map<std::string, uint32_t> def_count;
57 std::map<std::string, uint32_t> use_count;
59 auto def = [&bags, &def_count, &use_count](
const std::string &name) {
60 if (bags.find(name) == bags.end())
67 def_count.at(name) += 1;
70 auto use = [&use_count](
const std::string &name) { use_count.at(name) += 1; };
72 auto outputs = [&bags, &def_count, &use_count](void) {
73 std::set<std::string> res;
75 for (
const auto &bag : bags)
77 if (def_count.at(bag) > use_count.at(bag))
89 for (
const auto &layer : _prototxt->layer())
91 assert(layer.has_name());
92 assert(layer.has_type());
94 for (uint32_t n = 0; n < layer.top().
size(); ++n)
99 for (uint32_t n = 0; n < layer.bottom().
size(); ++n)
101 use(layer.bottom(n));
106 graph_builder->build(layer, &opbuilder_context);
110 throw std::runtime_error{
"Not supported: " + layer.type()};
115 for (
const auto &name : outputs())
117 const auto &shape = shape_ctx.at(name);
118 auto bag = bag_ctx.at(name);
120 auto output =
module->entity()->output()->create(shape);
126 module->output()->insert(output);
131 bundle.
module(std::move(module));
132 bundle.
data(std::move(data));
134 return std::move(bundle);