# Feature extraction for image with a hosted model

**URL:** <https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056>\
**Category:** Beginners\
**Created:** [April 9, 2023, 8:51pm UTC](https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056 "2023-04-09T20:51:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![avivhu](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@avivhu](https://discuss.huggingface.co/u/avivhu)\
**Post date:** [April 9, 2023, 8:51pm UTC](https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056/1 "2023-04-09T20:51:04Z")

</div>

Is there any hosted model on Hugging Face that performs image feature extraction and returns the features vector (aka image2vec, image embedding)?

I came across this one that is documented to do just that:  
[florentgbelidji/blip\_image\_embeddings · Hugging Face](https://huggingface.co/florentgbelidji/blip_image_embeddings)

But when I called it I got an error:  
`{'error': ['value is not a valid list: ` __root__ ` in `parameters`', 'str type expected: ` __root__ ` in `parameters`']}`

The test code:

```auto
import json
from typing import List
import requests as r
import base64

ENDPOINT_URL = "https://api-inference.huggingface.co/models/florentgbelidji/blip_image_embeddings"

def predict(path_to_image: str):
    with open(path_to_image, "rb") as i:
        b64 = base64.b64encode(i.read())
    payload = {"inputs": {"image": b64.decode("utf-8")}}
    response = r.post(
        ENDPOINT_URL, headers={"Authorization": f"Bearer {API_TOKEN}"}, json=payload
    )
    return response.json()

prediction = predict(path_to_image=img)
print(prediction)

```

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [April 10, 2023, 8:46pm UTC](https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056/2 "2023-04-10T20:46:49Z")

</div>

hi @avivhu ,

I don’t think we have a feature-extration from images on our community pipelines, i.e. using our API Inference. The model you’ve linked is an example of a custom pipeline for our [Inference Endpoints](https://huggingface.co/inference-endpoints), cc @florentgbelidji the author.  
If you want it on our community API, for tests and prototypes you can open an issue here [Issues · huggingface/api-inference-community · GitHub](https://github.com/huggingface/api-inference-community/issues)

---

<div class="post-metadata">

**Author:** ![avivhu](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@avivhu](https://discuss.huggingface.co/u/avivhu)\
**Post date:** [April 11, 2023, 9:55am UTC](https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056/3 "2023-04-11T09:55:12Z")

</div>

Thanks @radames .  
I opened a feature request here:  
[Add image feature extraction to the Inference API [img2vec] · Issue #229 · huggingface/api-inference-community (github.com)](https://github.com/huggingface/api-inference-community/issues/229)

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [April 11, 2023, 6:19pm UTC](https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056/4 "2023-04-11T18:19:56Z")

</div>

hi @avivhu , sorry I was able to update the custom pipeline to make it work on our public API,  
You can use from this model repo now, [radames/blip\_image\_embeddings · Hugging Face](https://huggingface.co/radames/blip_image_embeddings)

```python
import json
from typing import List
import requests as r
import base64
ENDPOINT_URL = "https://api-inference.huggingface.co/models/radames/blip_image_embeddings"
HF_TOKEN = ""
def predict(path_to_image: str = None):
    with open(path_to_image, "rb") as i:
        b64 = base64.b64encode(i.read())
    payload = {"inputs": b64.decode("utf-8")}
    response = r.post(
        ENDPOINT_URL, headers={"X-Wait-For-Model": "true", "Authorization": f"Bearer {HF_TOKEN}"}, json=payload
    )
    return response.json()
prediction = predict(
    path_to_image="palace.jpg"
)

```

---

<div class="post-metadata">

**Author:** ![avivhu](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@avivhu](https://discuss.huggingface.co/u/avivhu)\
**Post date:** [April 12, 2023, 3:07pm UTC](https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056/5 "2023-04-12T15:07:24Z")

</div>

That works perfectly. Thank you @radames .

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [December 20, 2023, 7:18pm UTC](https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056/6 "2023-12-20T19:18:12Z")

</div>

A post was split to a new topic: [Deploying CLIP-Vit as an inference endpoint](https://discuss.huggingface.co/t/deploying-clip-vit-as-an-inference-endpoint/66511)

---

<div class="post-metadata">

**Author:** ![timschott](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/timschott/32/31853_2.png) [@timschott](https://discuss.huggingface.co/u/timschott)\
**Post date:** [September 20, 2024, 7:47pm UTC](https://discuss.huggingface.co/t/feature-extraction-for-image-with-a-hosted-model/36056/7 "2024-09-20T19:47:34Z")

</div>

Hello! Trying this out and currently seeing

```auto
radames/blip_image_embeddings does not appear to have a file named config.json. Checkout 'https://huggingface.co/radames/blip_image_embeddings/tree/dace0eb439798ee47c0dc90f45c790ef87514770' for available files.

```

Any ideas on a fix for this?
