MCPcopy Create free account
hub / github.com/NVIDIA/DALI / CreateCocoAnchors

Method CreateCocoAnchors

dali/operators/ssd/box_encoder_test.cc:974–1024  ·  view source on GitHub ↗

Creates SSD default boxes (anchors) for COCO dataset. Exact description can be found in https://arxiv.org/abs/1512.02325

Source from the content-addressed store, hash-verified

972 // Creates SSD default boxes (anchors) for COCO dataset.
973 // Exact description can be found in https://arxiv.org/abs/1512.02325
974 void CreateCocoAnchors() {
975 anchors_ = vector<float>(coco_anchors_count_ * 4);
976
977 int fig_size = 300;
978 vector<int> feat_sizes {38, 19, 10, 5, 3, 1};
979 int feat_count = feat_sizes.size();
980 vector<float> steps {8.f, 16.f, 32.f, 64.f, 100.f, 300.f};
981 vector<float> scales {21.f, 45.f, 99.f, 153.f, 207.f, 261.f, 315.f};
982 vector<vector<int>> aspect_ratios {{2}, {2, 3}, {2, 3}, {2, 3}, {2}, {2}};
983
984 vector<float> fks;
985 for (auto &step : steps) fks.push_back(fig_size / step);
986
987 int anchor_idx = 0;
988 for (int idx = 0; idx < feat_count; ++idx) {
989 auto sk1 = scales[idx] / fig_size;
990 auto sk2 = scales[idx + 1] / fig_size;
991 auto sk3 = std::sqrt(sk1 * sk2);
992 vector<std::pair<float, float>> all_sizes{{sk1, sk1}, {sk3, sk3}};
993
994 for (auto &alpha : aspect_ratios[idx]) {
995 auto w = sk1 * sqrt(alpha);
996 auto h = sk1 / sqrt(alpha);
997 all_sizes.push_back({w, h});
998 all_sizes.push_back({h, w});
999 }
1000
1001 for (auto &sizes : all_sizes) {
1002 auto w = sizes.first;
1003 auto h = sizes.second;
1004
1005 for (int i = 0; i < feat_sizes[idx]; ++i)
1006 for (int j = 0; j < feat_sizes[idx]; ++j) {
1007 auto cx = (j + 0.5f) / fks[idx];
1008 auto cy = (i + 0.5f) / fks[idx];
1009
1010 cx = this->Clamp(cx);
1011 cy = this->Clamp(cy);
1012 w = this->Clamp(w);
1013 h = this->Clamp(h);
1014
1015 anchors_[anchor_idx * 4] = cx - 0.5f * w;
1016 anchors_[anchor_idx * 4 + 1] = cy - 0.5f * h;
1017 anchors_[anchor_idx * 4 + 2] = cx + 0.5f * w;
1018 anchors_[anchor_idx * 4 + 3] = cy + 0.5f * h;
1019
1020 ++anchor_idx;
1021 }
1022 }
1023 }
1024 }
1025
1026 void CheckAnswersForCoco(TensorList<CPUBackend> *boxes,
1027 TensorList<CPUBackend> *labels,

Callers

nothing calls this directly

Calls 4

ClampMethod · 0.95
sqrtFunction · 0.50
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected