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

enumerate() in load_labels returns a wrong indexed list #1

Open
helmuter opened this issue Jan 10, 2024 · 1 comment
Open

enumerate() in load_labels returns a wrong indexed list #1

helmuter opened this issue Jan 10, 2024 · 1 comment

Comments

@helmuter
Copy link

Dear rdlauer,

thank you for the nice project!!

I first got wrong results always, and found a bug: load_labels() returns a list of indexed lines from the file birds-label.txt, but the line index is not the same as the birdname index in the first column of the csv file. I changed load_labels() as follows:

def load_labels2():
    """ load labels for the ML model from the file specified """
    labels = list()
    with open(path_to_labels, 'r', encoding="utf8") as f:
        for line in f.readlines():
            index, name_en = line.strip().split(",")
            #print(index, name_en)
            try:
                label = {"id":int(index), "name_en": name_en}
                labels.append(label)
            except Exception as e:
                print(e)
                continue
    return labels

And in the caller function, I did this change:

labels = load_labels2()
label_id, prob = results[0]
(...)

        try:
            label = next(l for l in labels if l["id"] == label_id)
            bird_id = label["id"]  #integer
            bird_name_en = label["name_en"] #string
            prob_pct = str(round(prob * 100, 1)) + "%"`

Probably this could be solved more pythonesque, I still write more in C style. But the recognition rate is amazingly good with this change.

Best regards
Helmut

@rdlauer
Copy link
Owner

rdlauer commented Jan 11, 2024

Awesome, thank you!

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