Commit c5faa9ae authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #9013 from arrybn:ssd_last_layers_optim

parents bbb14d37 ec321e65
...@@ -219,7 +219,7 @@ public: ...@@ -219,7 +219,7 @@ public:
_shareLocation, &allLocationPredictions); _shareLocation, &allLocationPredictions);
// Retrieve all confidences. // Retrieve all confidences.
std::vector<std::map<int, std::vector<float> > > allConfidenceScores; std::vector<std::vector<std::vector<float> > > allConfidenceScores;
GetConfidenceScores(confidenceData, num, numPriors, _numClasses, GetConfidenceScores(confidenceData, num, numPriors, _numClasses,
&allConfidenceScores); &allConfidenceScores);
...@@ -241,7 +241,7 @@ public: ...@@ -241,7 +241,7 @@ public:
for (int i = 0; i < num; ++i) for (int i = 0; i < num; ++i)
{ {
const LabelBBox& decodeBBoxes = allDecodedBBoxes[i]; const LabelBBox& decodeBBoxes = allDecodedBBoxes[i];
const std::map<int, std::vector<float> >& confidenceScores = const std::vector<std::vector<float> >& confidenceScores =
allConfidenceScores[i]; allConfidenceScores[i];
std::map<int, std::vector<int> > indices; std::map<int, std::vector<int> > indices;
int numDetections = 0; int numDetections = 0;
...@@ -252,13 +252,13 @@ public: ...@@ -252,13 +252,13 @@ public:
// Ignore background class. // Ignore background class.
continue; continue;
} }
if (confidenceScores.find(c) == confidenceScores.end()) if (confidenceScores.size() <= c)
{ {
// Something bad happened if there are no predictions for current label. // Something bad happened if there are no predictions for current label.
util::make_error<int>("Could not find confidence predictions for label ", c); util::make_error<int>("Could not find confidence predictions for label ", c);
} }
const std::vector<float>& scores = confidenceScores.find(c)->second; const std::vector<float>& scores = confidenceScores[c];
int label = _shareLocation ? -1 : c; int label = _shareLocation ? -1 : c;
if (decodeBBoxes.find(label) == decodeBBoxes.end()) if (decodeBBoxes.find(label) == decodeBBoxes.end())
{ {
...@@ -280,13 +280,13 @@ public: ...@@ -280,13 +280,13 @@ public:
{ {
int label = it->first; int label = it->first;
const std::vector<int>& labelIndices = it->second; const std::vector<int>& labelIndices = it->second;
if (confidenceScores.find(label) == confidenceScores.end()) if (confidenceScores.size() <= label)
{ {
// Something bad happened for current label. // Something bad happened for current label.
util::make_error<int>("Could not find location predictions for label ", label); util::make_error<int>("Could not find location predictions for label ", label);
continue; continue;
} }
const std::vector<float>& scores = confidenceScores.find(label)->second; const std::vector<float>& scores = confidenceScores[label];
for (size_t j = 0; j < labelIndices.size(); ++j) for (size_t j = 0; j < labelIndices.size(); ++j)
{ {
size_t idx = labelIndices[j]; size_t idx = labelIndices[j];
...@@ -329,20 +329,20 @@ public: ...@@ -329,20 +329,20 @@ public:
int count = 0; int count = 0;
for (int i = 0; i < num; ++i) for (int i = 0; i < num; ++i)
{ {
const std::map<int, std::vector<float> >& confidenceScores = const std::vector<std::vector<float> >& confidenceScores =
allConfidenceScores[i]; allConfidenceScores[i];
const LabelBBox& decodeBBoxes = allDecodedBBoxes[i]; const LabelBBox& decodeBBoxes = allDecodedBBoxes[i];
for (std::map<int, std::vector<int> >::iterator it = allIndices[i].begin(); for (std::map<int, std::vector<int> >::iterator it = allIndices[i].begin();
it != allIndices[i].end(); ++it) it != allIndices[i].end(); ++it)
{ {
int label = it->first; int label = it->first;
if (confidenceScores.find(label) == confidenceScores.end()) if (confidenceScores.size() <= label)
{ {
// Something bad happened if there are no predictions for current label. // Something bad happened if there are no predictions for current label.
util::make_error<int>("Could not find confidence predictions for label ", label); util::make_error<int>("Could not find confidence predictions for label ", label);
continue; continue;
} }
const std::vector<float>& scores = confidenceScores.find(label)->second; const std::vector<float>& scores = confidenceScores[label];
int locLabel = _shareLocation ? -1 : label; int locLabel = _shareLocation ? -1 : label;
if (decodeBBoxes.find(locLabel) == decodeBBoxes.end()) if (decodeBBoxes.find(locLabel) == decodeBBoxes.end())
{ {
...@@ -642,13 +642,14 @@ public: ...@@ -642,13 +642,14 @@ public:
// confidence prediction for an image. // confidence prediction for an image.
void GetConfidenceScores(const float* confData, const int num, void GetConfidenceScores(const float* confData, const int num,
const int numPredsPerClass, const int numClasses, const int numPredsPerClass, const int numClasses,
std::vector<std::map<int, std::vector<float> > >* confPreds) std::vector<std::vector<std::vector<float> > >* confPreds)
{ {
confPreds->clear(); confPreds->clear();
confPreds->resize(num); confPreds->resize(num);
for (int i = 0; i < num; ++i) for (int i = 0; i < num; ++i)
{ {
std::map<int, std::vector<float> >& labelScores = (*confPreds)[i]; std::vector<std::vector<float> >& labelScores = (*confPreds)[i];
labelScores.resize(numClasses);
for (int p = 0; p < numPredsPerClass; ++p) for (int p = 0; p < numPredsPerClass; ++p)
{ {
int startIdx = p * numClasses; int startIdx = p * numClasses;
......
...@@ -124,8 +124,9 @@ public: ...@@ -124,8 +124,9 @@ public:
for (size_t cnDim = 0; cnDim < channels; cnDim++) for (size_t cnDim = 0; cnDim < channels; cnDim++)
{ {
const int offset = srcOffset + cnDim * cnStep;
for (size_t i = 0; i < innerSize; i++) for (size_t i = 0; i < innerSize; i++)
dstPtr[srcOffset + cnDim * cnStep + i] = srcPtr[srcOffset + cnDim * cnStep + i] - bufPtr[bufOffset + i]; dstPtr[offset + i] = srcPtr[offset + i] - bufPtr[bufOffset + i];
} }
} }
...@@ -142,22 +143,25 @@ public: ...@@ -142,22 +143,25 @@ public:
for (size_t cnDim = 0; cnDim < channels; cnDim++) for (size_t cnDim = 0; cnDim < channels; cnDim++)
{ {
const int offset = srcOffset + cnDim * cnStep;
for (size_t i = 0; i < innerSize; i++) for (size_t i = 0; i < innerSize; i++)
bufPtr[bufOffset + i] += dstPtr[srcOffset + cnDim * cnStep + i]; bufPtr[bufOffset + i] += dstPtr[offset + i];
} }
//divide by computed sum //divide by computed sum
for (size_t cnDim = 0; cnDim < channels; cnDim++) for (size_t cnDim = 0; cnDim < channels; cnDim++)
{ {
const int offset = srcOffset + cnDim * cnStep;
for (size_t i = 0; i < innerSize; i++) for (size_t i = 0; i < innerSize; i++)
dstPtr[srcOffset + cnDim * cnStep + i] /= bufPtr[bufOffset + i]; dstPtr[offset + i] /= bufPtr[bufOffset + i];
} }
if (logSoftMax) if (logSoftMax)
{ {
for (size_t cnDim = 0; cnDim < channels; cnDim++) for (size_t cnDim = 0; cnDim < channels; cnDim++)
{ {
const int offset = srcOffset + cnDim * cnStep;
for (size_t i = 0; i < innerSize; i++) for (size_t i = 0; i < innerSize; i++)
dstPtr[srcOffset + cnDim * cnStep + i] = log(dstPtr[srcOffset + cnDim * cnStep + i]); dstPtr[offset + i] = log(dstPtr[offset + i]);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment