...
Tip |
---|
You can deploy it on your render farm to use it in a post-render process for labeling of elements. |
How To
Simple usage:
classifier {file}
The file path can be to a single file (single image or movie file) or a sequence of files.
Code Block | ||
---|---|---|
| ||
classifier /path/to/file.#.movexr # result: {"/path/to/file.mov#.exr": [{"label": "fire", "description": "rapid oxidation of a material", "value": "Q3196"}]} |
...
You can pass multiple file paths to the software.
classifier {file1} {file2} {file3}
Code Block | ||
---|---|---|
| ||
classifier /path/to/filefiles.#.movexr /path/to/another/file.exrmov # result: {"/path/to/filefiles.#.movexr": [{"label": "fire", "description": "rapid oxidation of a material", "value": "Q3196"}], "/path/to/another/file.exrmov": [{"label": "torch", "description": "stick with a flaming end used as a source of light", "value": "Q327954"}]} |
...
Here is an example code snippet that you could use in your python code.
Code Block | ||
---|---|---|
| ||
# print the top 3 label predictions for a given file path
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 |
...