Last active
April 30, 2017 17:14
-
-
Save devStepsize/b76fa99db3c1962be7372f08e71a158c to your computer and use it in GitHub Desktop.
Local image tagging with Clarifai's Python client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Tagging a few local images using the Clarifai API and the clarifai-python | |
client. | |
""" | |
from os.path import expanduser | |
from clarifai.client import ClarifaiApi | |
directory = expanduser('~/pictures/clarifai/') | |
pictures = ['burning_basmatty.jpg', 'concert.jpg'] | |
clarifai_api = ClarifaiApi() | |
results = clarifai_api.tag_images( | |
[open('%s%s' % (directory, p), 'rb') for p in pictures] | |
) | |
# Uncomment the below to print the whole JSON returned | |
# from pprint import pprint | |
# pprint(result) | |
for i, result in enumerate(results['results']): | |
tags = result['result']['tag'] | |
print '\nTags for %s (Tag - Probability)' % pictures[i] | |
for j in range(len(tags['classes'])): | |
print '%s - %0.4f' % (tags['classes'][j], tags['probs'][j]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment