# Feedback loop - Send predictions from models to 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 :

{% content-ref url="deploy-model-in-production-tensorflow-only" %}
[deploy-model-in-production-tensorflow-only](https://picsellia.gitbook.io/picsellia/getting-started-2/deploy-model-in-production-tensorflow-only)
{% endcontent-ref %}

## Make predictions

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)

```python
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.

## Send images back to Picsell.ia

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.

### Send to Datalake

Now, we will send a JSON body with our request.

```python
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.

{% hint style="info" %}
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'
{% endhint %}

If you want to choose the name of the file to be saved in your Datalake you can add an argument to our JSON

```python
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 !

### Add tags to images

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.

```python
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)
```

{% hint style="warning" %}
The `tags` parameter must be a list !
{% endhint %}

### Send to Datalake + add to a Dataset

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.

```python
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 😉

## Send images + predictions

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.

```python
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).

{% hint style="warning" %}
As predictions (which will be vizualized as annotations) can only be send to a Dataset, the `dataset` parameter can't be null.
{% endhint %}

That's it ! You now know how to build fully operational pipelines using only Picsell.ia !

See you on the next tutorials 👋
