Feedback loop - Send predictions from models to Datalake or Datasets
Here, we will learn how to send the images and predictions (bounding boxes, masks, classification) from the models you deployed, back to Picsell.ia directly in your Datalake or Datasets
This tutorial assumes that you have already deployed a model using Picsell.ia. If you want to learn how to do so, please check the page below :
To make predictions with the models you deployed using Picsll.ia, you can use the following snippet (it can be found in the deployment tab on the platform)
import requests
token = "your api token"
model_id = "chosen model id"
headers = {
"Authorization": "Token " + token
}
name = "path/to/your/image.jpg"
r = requests.post(
url="https://eyes.picsellia.com/predict/{}".format(model_id),
files={'media': open(name, 'rb')},
headers=headers)
The only things you need to perform prediction is your api token to authenticate you and the API endpoint of your model (which contains the model id). If you don't know it, you can find it in the deployment tab on the platform.
If you just want the images your perform predictions on to be sent on Picsell.ia, either in your Datalake or directly in a Dataset, here are the few things you must add.
Now, we will send a JSON body with our request.
data = {
'loop': True,
}
r = requests.post(
url="https://eyes.picsellia.com/predict/{}".format(model_id),
files={'media': open(name, 'rb')}, data=data,
headers=headers)
You just have to set the
loop
parameter to True and the images will automatically be sent to your Datalake.Please note that in this case, the name of the image once in your Datalake will be something like 'model_name-prediction-yyyy-mm-dd-hh-mm-ss.jpg'
If you want to choose the name of the file to be saved in your Datalake you can add an argument to our JSON
data = {
'loop': True,
'name': 'my_super_image.jpg'
}
r = requests.post(
url="https://eyes.picsellia.com/predict/{}".format(model_id),
files={'media': open(name, 'rb')}, data=data,
headers=headers)
Now the image will be saved with the name 'my_super_image.jpg' in your Datalake !
If you want to add some tags to the images such as the name of the model or whatever you want, you can add a
tags
parameter to the JSON just like this.
data = {
'loop': True,
'name': 'my_super_image.jpg',
'tags': ['model_name', 'camera1']
}
r = requests.post(
url="https://eyes.picsellia.com/predict/{}".format(model_id),
files={'media': open(name, 'rb')}, data=data,
headers=headers)
The
tags
parameter must be a list !If you want to not only add the image to your Datalake but also automatically add it to a Dataset of your choice, it's really simple, just add a
dataset
parameter to the JSON.data = {
'loop': True,
'name': 'my_super_image.jpg',
'dataset': 'my_awesome_dataset/version_name'
}
r = requests.post(
url="https://eyes.picsellia.com/predict/{}".format(model_id),
files={'media': open(name, 'rb')}, data=data,
headers=headers)
See ? The images are now automatically added to your Datalake AND your awesome Dataset 😉
If you want to send the predictions (bounding-boxes, masks, classifications) along with the images to one of your Dataset, it's also possible with just two new parameters.
data = {
'loop': True,
'dataset': 'my_awesome_dataset/version_name',
'send_prediction': True,
'threshold': 0.85
}
r = requests.post(
url="https://eyes.picsellia.com/predict/{}".format(model_id),
files={'media': open(name, 'rb')}, data=data,
headers=headers)
Just set
send_prediction
to True and the predictions will be sent along with images, you can also adjust the threshold
of the predictions to send (the default threshold is 0.7).As predictions (which will be vizualized as annotations) can only be send to a Dataset, the
dataset
parameter can't be null.That's it ! You now know how to build fully operational pipelines using only Picsell.ia !
See you on the next tutorials 👋
Last modified 2yr ago