Details
Input Type: Image
Model Type: Visual Classifier
Output Type: Concepts
Data Sources: Kaggle
Language: English
Demo Link: View Demo
Preview:
Description
1. To run the demo, please request an API key using this form:
API Request Form
2. Run the demo by entering the API key here:
Demo Link
3. Download sample images to test the demo or use your own images:
Google Drive
Objective: Identify objects contained within image inputs.
Output: Concepts using the general classifier model with associated confidence level from 0 to 1.
- Gathering data
- Data pre-processing
- Model Used:
- Training and testing the model
- Evaluation
Notes: I used the Streamlit platform to run the demo for public testing.
import streamlit as st
import pandas as pd
from PIL import Image
st.title(“General Classifier Demo”)
st.header(“Enter an App Key, then press Enter”)
key = st.text_input(“App Key”)
if key == ”:
st.warning(“An app key has not been entered”)
st.stop()
else:
st.write(“Thank you for entering an App Key.”)
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import service_pb2_grpc
stub = service_pb2_grpc.V2Stub(ClarifaiChannel.get_grpc_channel())
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
# This is how you authenticate.
metadata = ((‘authorization’, ‘Key {}’.format(key)),)
file_data = st.file_uploader(“Upload Image”,type=[‘jpg’])
if file_data == None:
st.warning(“File needs to be uploaded”)
st.stop()
else:
image = Image.open(file_data)
st.image(image)
request = service_pb2.PostModelOutputsRequest(
# This is the model ID of a publicly available General model. You may use any other public or custom model ID.
model_id=’aaa03c23b3724a16a56b629203edc62c’,
inputs=[
resources_pb2.Input(data=resources_pb2.Data(image=resources_pb2.Image(base64=file_data.getvalue())))
])
response = stub.PostModelOutputs(request, metadata=metadata)
if response.status.code != status_code_pb2.SUCCESS:
raise Exception(“Request failed, status code: ” + str(response.status.code))
names = []
confidences = []
for concept in response.outputs[0].data.concepts:
names.append(concept.name)
confidences.append(concept.value)
df = pd.DataFrame({
“Concept Name”:names,
“Model Confidence”:confidences
})
st.dataframe(df)