Kagami/go-face

I found a bug with classify.cc .Classifier always gives me some result .

Closed this issue · 1 comments

I changed some code。it can work normally。

`
int classify(
const std::vector& samples,
const std::unordered_map<int, int>& cats,
const descriptor& test_sample,
float tolerance
) {
if (samples.size() == 0)
return -1;

std::vector<std::pair<int, float>> distances;
distances.reserve(samples.size());
auto dist_func = dlib::squared_euclidean_distance();
int idx = 0;
for (const auto& sample : samples) {
	float dist = dist_func(sample, test_sample);

	if (dist < tolerance)
	    distances.push_back({idx, dist});
	idx++;
}

if (distances.size() == 0)
	return -1;
std::sort(
	distances.begin(), distances.end(),
	[](const auto a, const auto b) { return a.second < b.second; }
);
int nIndext = distances[0].first;
auto cat = cats.find(nIndext);
if (cat == cats.end())return -1;
return cat->second;

}

`

Thank you, fixed.