Image Recognition:
This is a v1 general model for image recognition.
more information on this can be found at
Product: Image Recognition
Initialize and Get model:
from cognious import CogniousApp
# Use <client_id> and <client_secret> of your application
# Refer to Step 2 of https://cognious.com/documentation/quickstart
app = CogniousApp('DKP3ADiCHVWO0NvuDg9XIpYgZAgKIXc73ZiPfBe2', 'i55x7kQWGc83u2fpKgMmyGCXaWDHYlk7kS986a6e')
# Get the model you want to use
# models.get function returns an instance of the model
model = app.models.get('ImageRecognition')
Methods:
Method: predict_by_url
Syntax: model.predict_by_url(
<image_url>)
Input
<image__url> should be a publicly accessible image url
# model.predict_by_url(<image_url>)
model.predict_by_url('https://upload.wikimedia.org/wikipedia/commons/6/6e/Golde33443.jpg')
Method: predict_by_imagefile
Syntax: model.predict_by_imagefile(
<image_file>)
Input
<image_file> should be a fully qualified path to a local image file
# model.predict_by_imagefile(<full_path_to_image_file>)
model.predict_by_imagefile('/home/user/dog.jpg')
Response
model.response:
# model.response contains the response
print(model.response)
Sample response (prettified):
{
"success": true,
"result": {
"prediction": [
{
"confidence": "0.826396",
"answer": "Labrador_retriever"
},
{
"confidence": "0.128493",
"answer": "golden_retriever"
},
{
"confidence": "0.0122971",
"answer": "Chesapeake_Bay_retriever"
}
]
}
}
model.result:
# model.result contains the only the result part of the response
print(model.result)
Full example code:
from cognious import CogniousApp
# Initialize application client
app = CogniousApp('DKP3ADiCHVWO0NvuDg9XIpYgZAgKIXc73ZiPfBe2', 'i55x7kQWGc83u2fpKgMmyGCXaWDHYlk7kS986a6e')
# Get the model you want to use
# models.get function returns an instance of the model
model = app.models.get('ImageRecognition')
# Use the available methods to make a prediction
# predict_by_url(<image_url>)
model.predict_by_url('https://upload.wikimedia.org/wikipedia/commons/2/21/Golden_Retriever_Adolescent.jpg')
# model.response contains the response
print(model.response)
# {
# 'success': True,
# 'result': {
# 'prediction': [
# {'confidence': '0.679696', 'answer': 'golden_retriever'},
# {'confidence': '0.317834', 'answer': 'Labrador_retriever'},
# {'confidence': '0.00169803', 'answer': 'kuvasz'}
# ]
# }
# }
#
# model.result contains the result portion of the response