Comments (3)
It looks like all the priorboxes are created, even the ones who are associated with an anchor without a match, then all the locations and all the priorboxes are send to decode and it's only later that the uninteresting predictions are discarded (line 114 through 124).
I think it's possible to do the opposite, first discard uninteresting predictions, then generate only the priorboxes corresponding to the interesting propositions and then decode them. This might provide the speedup you seek.
from pytorch_retinaface.
Personally, I run the code in C++ and have my own code that generates prior boxes once and caches the result.
I also only decode boxes that meet my threshold requirements. This means it is under a millisecond to decode rather than 150ms.
Same code I used for Faceboxes but there has been variations.
// This generates the 'd' input array used in decodeBox
std::vector<std::array<float, 3>> generateDefaultBoxRetina(int width, int height)
{
std::vector<std::array<float, 3>> boxes;
const static std::vector<int> feature_map_sizes = {8, 16, 32};
const static std::vector<std::vector<int>> min_sizes = {{16, 32}, {64, 128}, {256, 512}};
for (int e = 0; e < feature_map_sizes.size(); ++e)
{
float fmap = (float)feature_map_sizes.at(e);
const int maxH = (int)std::ceil((float)height / fmap);
const int maxW = (int)std::ceil((float)width / fmap);
for (int h = 0; h < maxH; ++h)
{
for (int w = 0; w < maxW; ++w)
{
for (const auto &min_size : min_sizes.at(e))
{
const float cx = (w + 0.5f) * fmap;
const float cy = (h + 0.5f) * fmap;
boxes.push_back({cx, cy, (float)min_size});
}
}
}
}
return boxes;
}
std::tuple<cv::Rect2f, float, std::vector<cv::Point2f>>
decodeBox(const std::vector<float> &p, const std::vector<float> &l, const std::array<float, 3> &d, int width, int height, const float &c)
{
// Hardcoded variance values
const static float vxy = 0.1f;
const static float vwh = 0.2f;
// cX, cY
const auto cx = p[0] * vxy * d[2] + d[0];
auto cy = p[1] * vxy * d[2] + d[1];
// Size
const auto sx = std::exp(p[2] * vwh) * d[2];
const auto sy = std::exp(p[3] * vwh) * d[2];
std::vector<cv::Point2f> landmarks;
if (!l.empty())
{
landmarks.reserve(10);
for (int i = 0; i < 10; i += 2)
{
auto cx = d[0] + l.at(i) * vxy * d[2];
auto cy = d[1] + l.at(i + 1) * vxy * d[2];
landmarks.push_back({cx / (float)width, cy / (float)height});
}
}
return {{(cx - (sx / 2.0f)) / (float)width, (cy - (sy / 2.0f)) / (float)height, sx / (float)width, sy / (float)height}, c, landmarks};
}
from pytorch_retinaface.
@xsacha @mooss Thank you for your answer. It's very helpful to me.
from pytorch_retinaface.
Related Issues (20)
- Is it ok if we upload your models to Zenodo and distribute them?
- Fine-tuning Resnet 50 model
- Unable to find a compatible Visual Studio installation
- How to fit non-squared input?
- The form of bboxes is wrong!!!
- Mesh decoder HOT 1
- About the ratioHard Example Mining HOT 3
- Why can't we evaluate during the training? HOT 1
- Pretrained Model HOT 1
- [Refactor] Acclerate training based on MMEngine :rocket:
- How to train with custom dataset by using the pretrained model?
- Dataset
- Evaluation 评估失败,在widerface的三个子集上map值都为0 HOT 1
- What maximum FPS have you achieved?
- Why does the forward pass time become shorter with iterations?
- Why loop 100 times while testing begin in detect.py?
- 用celeba数据集训练的模型,摄像头测试时小脸的框会变大框不准 HOT 1
- How can I train using pth pretrained file? (For transfer learning)
- 用预训练的权重直接训练,为什么loss会这么高
- C++ and TensorRT implementation of yolov5face yolov7face yolov8face
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch_retinaface.