Editing classify.py

Hi, I want to edit classify.py in the python SDK. I deployed a model that classifies waste into either paper, glass, and compost on a Raspberry pi. Where is the result of the classification stored? What variable?
I want to use the variable in an if statement.

Any help would be appreciated.

Hello @okosa20d,

The results of the classification are stored in res['results']['classification']
If you want to grab the classification results with the highest probability you can do something like:

predicted_label = ''
acceptable_threshold = 0.8
if "classification" in res["result"].keys():
                print('Result (%d ms.) ' % (res['timing']['dsp'] + res['timing']['classification']), end='')
                for label in labels:
                    score = res['result']['classification'][label]
                    if res['result']['classification'][value] > acceptable_threshold:
                       predicted_value = res['result']['classification'][label]
                    print('%s: %.2f\t' % (label, score), end='')
                print('', flush=True)

Regards,

Louis

1 Like

It says that ‘value’ is not defined.

This worked though

Hello @okosa20d,

Yes sorry I could not remember the results object structure and it seems to be a key:value.
Your modification seems right :slight_smile: thanks for the update.

I am updating it here just in case someone else want to copy-paste the code snippet:

predicted_label = ''
acceptable_threshold = 0.8
if "classification" in res["result"].keys():
                print('Result (%d ms.) ' % (res['timing']['dsp'] + res['timing']['classification']), end='')
                for label in labels:
                    score = res['result']['classification'][label]
                    if score > acceptable_threshold:
                       predicted_label = label
                    print('%s: %.2f\t' % (label, score), end='')
                print('', flush=True)

Regards,

Louis