Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
import json
import subprocess

path = '/path/to/file.mov'
command = ['./classifier', '--top', '3', path]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()

if process.returncode != 0:
    print('Something went wrong: {} - Error: {}'.format(path, error))
else:
    result = json.loads(output)
    for path, predictions in result.items():
        wikidata_ids = [item['value'] for item in  predictions]  # list of IDs from wikidata
        readable_labels = [item['label'] for item in predictions]  # list of human readable labels
        print('For path: "{}" predicted the labels: {}'.format(path, ', '.join(readable_labels)))

# result:
# For path: "/path/to/file.mov" predicted the labels: torch, flame, fire

Result format

Code Block
{u'/path/to/file.mov': [{u'description': u'stick with a flaming end used as a source of light', u'value': u'Q327954', u'label': u'torch'}]}

flag

--info

Shows all information the software.
It will list all categories that this version of the machine learning model can classify.

id - the identifier for the class from wikidata
human-readable - readable label
synonym - a list of different words for this class

--top {number}

Get results of top X predictions

...