Merge remote-tracking branch 'origin/master'
This commit is contained in:
145
src/network.cpp
145
src/network.cpp
@@ -623,151 +623,6 @@ long ConvAndFcInit(struct Weight *weight, int schannel, int lchannel, int kersiz
|
||||
return byteLenght;
|
||||
}
|
||||
|
||||
/**
|
||||
* softmax
|
||||
* @param pbox feature map
|
||||
*/
|
||||
void softmax(const struct pBox *pbox) {
|
||||
if (pbox->pdata == NULL) {
|
||||
cout << "the softmax's pdata is NULL , Please check !" << endl;
|
||||
return;
|
||||
}
|
||||
mydataFmt *p2D = pbox->pdata;
|
||||
mydataFmt *p3D = NULL;
|
||||
long mapSize = pbox->width * pbox->height;
|
||||
mydataFmt eleSum = 0;
|
||||
for (int row = 0; row < pbox->height; row++) {
|
||||
for (int col = 0; col < pbox->width; col++) {
|
||||
eleSum = 0;
|
||||
for (int channel = 0; channel < pbox->channel; channel++) {
|
||||
p3D = p2D + channel * mapSize;
|
||||
*p3D = exp(*p3D);
|
||||
eleSum += *p3D;
|
||||
}
|
||||
for (int channel = 0; channel < pbox->channel; channel++) {
|
||||
p3D = p2D + channel * mapSize;
|
||||
*p3D = (*p3D) / eleSum;
|
||||
}
|
||||
p2D++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool cmpScore(struct orderScore lsh, struct orderScore rsh) {
|
||||
if (lsh.score < rsh.score)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 非极大值抑制
|
||||
* @param boundingBox_
|
||||
* @param bboxScore_
|
||||
* @param overlap_threshold
|
||||
* @param modelname
|
||||
*/
|
||||
void nms(vector<struct Bbox> &boundingBox_, vector<struct orderScore> &bboxScore_, const mydataFmt overlap_threshold,
|
||||
string modelname) {
|
||||
if (boundingBox_.empty()) {
|
||||
return;
|
||||
}
|
||||
std::vector<int> heros;
|
||||
//sort the score
|
||||
sort(bboxScore_.begin(), bboxScore_.end(), cmpScore);
|
||||
|
||||
int order = 0;
|
||||
float IOU = 0;
|
||||
float maxX = 0;
|
||||
float maxY = 0;
|
||||
float minX = 0;
|
||||
float minY = 0;
|
||||
while (bboxScore_.size() > 0) {
|
||||
order = bboxScore_.back().oriOrder;
|
||||
bboxScore_.pop_back();
|
||||
if (order < 0)continue;
|
||||
heros.push_back(order);
|
||||
boundingBox_.at(order).exist = false;//delete it
|
||||
|
||||
for (int num = 0; num < boundingBox_.size(); num++) {
|
||||
if (boundingBox_.at(num).exist) {
|
||||
//the iou
|
||||
maxX = (boundingBox_.at(num).x1 > boundingBox_.at(order).x1) ? boundingBox_.at(num).x1
|
||||
: boundingBox_.at(order).x1;
|
||||
maxY = (boundingBox_.at(num).y1 > boundingBox_.at(order).y1) ? boundingBox_.at(num).y1
|
||||
: boundingBox_.at(order).y1;
|
||||
minX = (boundingBox_.at(num).x2 < boundingBox_.at(order).x2) ? boundingBox_.at(num).x2
|
||||
: boundingBox_.at(order).x2;
|
||||
minY = (boundingBox_.at(num).y2 < boundingBox_.at(order).y2) ? boundingBox_.at(num).y2
|
||||
: boundingBox_.at(order).y2;
|
||||
//maxX1 and maxY1 reuse
|
||||
maxX = ((minX - maxX + 1) > 0) ? (minX - maxX + 1) : 0;
|
||||
maxY = ((minY - maxY + 1) > 0) ? (minY - maxY + 1) : 0;
|
||||
//IOU reuse for the area of two bbox
|
||||
IOU = maxX * maxY;
|
||||
if (!modelname.compare("Union"))
|
||||
IOU = IOU / (boundingBox_.at(num).area + boundingBox_.at(order).area - IOU);
|
||||
else if (!modelname.compare("Min")) {
|
||||
IOU = IOU /
|
||||
((boundingBox_.at(num).area < boundingBox_.at(order).area) ? boundingBox_.at(num).area
|
||||
: boundingBox_.at(
|
||||
order).area);
|
||||
}
|
||||
if (IOU > overlap_threshold) {
|
||||
boundingBox_.at(num).exist = false;
|
||||
for (vector<orderScore>::iterator it = bboxScore_.begin(); it != bboxScore_.end(); it++) {
|
||||
if ((*it).oriOrder == num) {
|
||||
(*it).oriOrder = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < heros.size(); i++)
|
||||
boundingBox_.at(heros.at(i)).exist = true;
|
||||
}
|
||||
|
||||
void refineAndSquareBbox(vector<struct Bbox> &vecBbox, const int &height, const int &width) {
|
||||
if (vecBbox.empty()) {
|
||||
cout << "Bbox is empty!!" << endl;
|
||||
return;
|
||||
}
|
||||
float bbw = 0, bbh = 0, maxSide = 0;
|
||||
float h = 0, w = 0;
|
||||
float x1 = 0, y1 = 0, x2 = 0, y2 = 0;
|
||||
for (vector<struct Bbox>::iterator it = vecBbox.begin(); it != vecBbox.end(); it++) {
|
||||
if ((*it).exist) {
|
||||
bbh = (*it).x2 - (*it).x1 + 1;
|
||||
bbw = (*it).y2 - (*it).y1 + 1;
|
||||
x1 = (*it).x1 + (*it).regreCoord[1] * bbh;
|
||||
y1 = (*it).y1 + (*it).regreCoord[0] * bbw;
|
||||
x2 = (*it).x2 + (*it).regreCoord[3] * bbh;
|
||||
y2 = (*it).y2 + (*it).regreCoord[2] * bbw;
|
||||
|
||||
h = x2 - x1 + 1;
|
||||
w = y2 - y1 + 1;
|
||||
|
||||
maxSide = (h > w) ? h : w;
|
||||
x1 = x1 + h * 0.5 - maxSide * 0.5;
|
||||
y1 = y1 + w * 0.5 - maxSide * 0.5;
|
||||
(*it).x2 = round(x1 + maxSide - 1);
|
||||
(*it).y2 = round(y1 + maxSide - 1);
|
||||
(*it).x1 = round(x1);
|
||||
(*it).y1 = round(y1);
|
||||
|
||||
//boundary check
|
||||
if ((*it).x1 < 0)(*it).x1 = 0;
|
||||
if ((*it).y1 < 0)(*it).y1 = 0;
|
||||
if ((*it).x2 > height)(*it).x2 = height - 1;
|
||||
if ((*it).y2 > width)(*it).y2 = width - 1;
|
||||
|
||||
it->area = (it->x2 - it->x1) * (it->y2 - it->y1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 残差融合初始化
|
||||
* @param output 输出feature map
|
||||
|
||||
@@ -10,7 +10,7 @@ int main() {
|
||||
facenet ggg;
|
||||
vector<mydataFmt> o;
|
||||
ggg.run(Image, o, 0);
|
||||
// imshow("result", Image);
|
||||
imshow("result", Image);
|
||||
imwrite("../result.jpg", Image);
|
||||
|
||||
for (int i = 0; i < Num; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user