std::map<std::string, tensor::Shape> shape_ctx;
std::map<std::string, coco::Bag *> bag_ctx;
- std::set<std::string> top;
+ std::set<std::string> bags;
+ std::map<std::string, uint32_t> def_count;
+ std::map<std::string, uint32_t> use_count;
+
+ auto def = [&bags, &def_count, &use_count](const std::string &name) {
+ if (bags.find(name) == bags.end())
+ {
+ bags.insert(name);
+ def_count[name] = 0;
+ use_count[name] = 0;
+ }
+
+ def_count.at(name) += 1;
+ };
+
+ auto use = [&use_count](const std::string &name) { use_count.at(name) += 1; };
+
+ auto outputs = [&bags, &def_count, &use_count](void) {
+ std::set<std::string> res;
+
+ for (const auto &bag : bags)
+ {
+ if (def_count.at(bag) > use_count.at(bag))
+ {
+ res.insert(bag);
+ }
+ }
+
+ return res;
+ };
for (const auto &layer : _prototxt->layer())
{
assert(layer.has_name());
assert(layer.has_type());
- top.clear();
- top.insert(layer.top().begin(), layer.top().end());
+ for (uint32_t n = 0; n < layer.top().size(); ++n)
+ {
+ def(layer.top(n));
+ }
+
+ for (uint32_t n = 0; n < layer.bottom().size(); ++n)
+ {
+ use(layer.bottom(n));
+ }
if (layer.type() == "Input")
{
}
// Finalize: Create output for each top blob
- for (const auto &name : top)
+ for (const auto &name : outputs())
{
const auto &shape = shape_ctx.at(name);
auto bag = bag_ctx.at(name);