Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
suddenly-ou opened this issue Aug 1, 2019 · 1 comment

Comments

@suddenly-ou
Copy link

suddenly-ou commented Aug 1, 2019

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;

}

`

@suddenly-ou suddenly-ou changed the title I found a bug with classify. Classifier always gives me some result . I found a bug with classify.cc .Classifier always gives me some result . Aug 1, 2019
@Kagami Kagami closed this as completed in 0956e40 Aug 18, 2019
@Kagami
Copy link
Owner

Kagami commented Aug 18, 2019

Thank you, fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants