rom1504 / clip-retrieval

Easily compute clip embeddings and build a clip retrieval system with them
https://rom1504.github.io/clip-retrieval/
MIT License
2.42k stars 213 forks source link

Running demo notebook error: JSONDecodeError: Expecting value: line 1 column 1 (char 0) #251

Closed mrdbourke closed 1 year ago

mrdbourke commented 1 year ago

Hi there,

Thank you for the incredible package!

I'm trying to run the demo notebook: https://colab.research.google.com/github/rom1504/clip-retrieval/blob/master/notebook/clip-client-query-api.ipynb

And after running the cell:

cat_results = client.query(text="an image of a cat")
log_result(cat_results[0])

I'm getting the error:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
[/usr/local/lib/python3.8/dist-packages/requests/models.py](https://localhost:8080/#) in json(self, **kwargs)
    970         try:
--> 971             return complexjson.loads(self.text, **kwargs)
    972         except JSONDecodeError as e:

6 frames
[/usr/lib/python3.8/json/__init__.py](https://localhost:8080/#) in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    356             parse_constant is None and object_pairs_hook is None and not kw):
--> 357         return _default_decoder.decode(s)
    358     if cls is None:

[/usr/lib/python3.8/json/decoder.py](https://localhost:8080/#) in decode(self, s, _w)
    336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()

[/usr/lib/python3.8/json/decoder.py](https://localhost:8080/#) in raw_decode(self, s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
[<ipython-input-5-414b01a3aacd>](https://localhost:8080/#) in <module>
----> 1 cat_results = client.query(text="an image of a cat")
      2 log_result(cat_results[0])

[/usr/local/lib/python3.8/dist-packages/clip_retrieval/clip_client.py](https://localhost:8080/#) in query(self, text, image, embedding_input)
     82             raise ValueError("Only one of text or image can be provided.")
     83         if text:
---> 84             return self.__search_knn_api__(text=text)
     85         elif image:
     86             if image.startswith("http"):

[/usr/local/lib/python3.8/dist-packages/clip_retrieval/clip_client.py](https://localhost:8080/#) in __search_knn_api__(self, text, image, image_url, embedding_input)
    129                 encoded_string = base64.b64encode(image_file.read())
    130                 image = str(encoded_string.decode("utf-8"))
--> 131         return requests.post(
    132             self.url,
    133             data=json.dumps(

[/usr/local/lib/python3.8/dist-packages/requests/models.py](https://localhost:8080/#) in json(self, **kwargs)
    973             # Catch JSON-related errors and raise as requests.JSONDecodeError
    974             # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975             raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
    976 
    977     @property

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Potentially something is offline?

mrdbourke commented 1 year ago

Might be a CORS issue?

Seems to be happening on the front-end at https://rom1504.github.io/clip-retrieval/ as well:

Screenshot 2023-03-01 at 1 40 43 pm

vishaal27 commented 1 year ago

Is it working for you? It doesn't seem to be fixed yet for me.

orchardbirds commented 1 year ago

No, me neither

Itay89 commented 1 year ago

I have the same problem. Until yesterday it worked fine

rom1504 commented 1 year ago

fixed

mrdbourke commented 1 year ago

Thank you!

dydxdt commented 1 year ago

I still meet this error when I set num_images=1000. How can I solve this ? Thx!!!

Tianhao-Qi commented 1 year ago

@dydxdt I also meet the same issue, can @rom1504 tell us how to solve the problem?

rom1504 commented 1 year ago

Sure, how many times do you need to call the service?

rom1504 commented 1 year ago

If you all can provide some information on how you're calling the service, it'll become possible to handle more load that look like what you need

On Mon, Jul 10, 2023, 20:03 Tianhao-Qi @.***> wrote:

@dydxdt https://github.com/dydxdt I also meet the same issue, can @rom1504 https://github.com/rom1504 tell us how to solve the problem?

— Reply to this email directly, view it on GitHub https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1629452855, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437VL6LXFT2P2P6NMDALXPQ7YLANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.***>

Tianhao-Qi commented 1 year ago
from clip_retrieval.clip_client import ClipClient, Modality

client = ClipClient(
    url="https://knn.laion.ai/knn-service",
    indice_name="laion5B-H-14",
    aesthetic_score=9,
    aesthetic_weight=0.5,
    modality=Modality.IMAGE,
    num_images=20000,
)
url = "http://p6.storage.canalblog.com/68/98/584238/68087013_q.jpg"
results = client.query(image=url)
print(len(results))

@rom1504 In this way ,I'll get the JSONDecodeError: Expecting value: line 1 column 1 (char 0).

rom1504 commented 1 year ago

The cause is people are calling the service too much and it's bringing it down. Hence why I'm asking what's your use case

On Wed, Jul 12, 2023, 07:33 Tianhao-Qi @.***> wrote:

from clip_retrieval.clip_client import ClipClient, Modality

client = ClipClient( url="https://knn.laion.ai/knn-service", indice_name="laion5B-H-14", aesthetic_score=9, aesthetic_weight=0.5, modality=Modality.IMAGE, num_images=20000, ) url = "http://p6.storage.canalblog.com/68/98/584238/68087013_q.jpg" results = client.query(image=url) print(len(results))

@rom1504 https://github.com/rom1504 In this way ,I'll get the JSONDecodeError: Expecting value: line 1 column 1 (char 0).

— Reply to this email directly, view it on GitHub https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1631876095, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437T53XTSBST3X56JLM3XPYZKHANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.***>

Tianhao-Qi commented 1 year ago

Thanks for your reply. So the solution may be to build a search engine on a local machine? If true, could you please tell me the existing instructions that I can follow.

The cause is people are calling the service too much and it's bringing it down. Hence why I'm asking what's your use case On Wed, Jul 12, 2023, 07:33 Tianhao-Qi @.> wrote: from clip_retrieval.clip_client import ClipClient, Modality client = ClipClient( url="https://knn.laion.ai/knn-service", indice_name="laion5B-H-14", aesthetic_score=9, aesthetic_weight=0.5, modality=Modality.IMAGE, num_images=20000, ) url = "http://p6.storage.canalblog.com/68/98/584238/68087013_q.jpg" results = client.query(image=url) print(len(results)) @rom1504 https://github.com/rom1504 In this way ,I'll get the JSONDecodeError: Expecting value: line 1 column 1 (char 0). — Reply to this email directly, view it on GitHub <#251 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437T53XTSBST3X56JLM3XPYZKHANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.>

rom1504 commented 1 year ago

There's at least 2 solutions

  1. You run it locally, see the guide for that which is linked in the readme
  2. You tell me what is your use case so I can figure out how to optimize the service

On Wed, Jul 12, 2023, 08:47 Tianhao-Qi @.***> wrote:

Thanks for your reply. So the solution may be to build a search engine on a local machine? If true, could you please tell me the existing instructions that I can follow.

The cause is people are calling the service too much and it's bringing it down. Hence why I'm asking what's your use case … <#m-2281301921330147586> On Wed, Jul 12, 2023, 07:33 Tianhao-Qi @.> wrote: from clip_retrieval.clip_client import ClipClient, Modality client = ClipClient( url="https://knn.laion.ai/knn-service https://knn.laion.ai/knn-service", indice_name="laion5B-H-14", aesthetic_score=9, aesthetic_weight=0.5, modality=Modality.IMAGE, num_images=20000, ) url = "http://p6.storage.canalblog.com/68/98/584238/68087013_q.jpg http://p6.storage.canalblog.com/68/98/584238/68087013_q.jpg" results = client.query(image=url) print(len(results)) @rom1504 https://github.com/rom1504 https://github.com/rom1504 https://github.com/rom1504 In this way ,I'll get the JSONDecodeError: Expecting value: line 1 column 1 (char 0). — Reply to this email directly, view it on GitHub <#251 (comment) https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1631876095>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437T53XTSBST3X56JLM3XPYZKHANCNFSM6AAAAAAVLQMFD4 https://github.com/notifications/unsubscribe-auth/AAR437T53XTSBST3X56JLM3XPYZKHANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.>

— Reply to this email directly, view it on GitHub https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1631943940, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437S5DEBGPYDBTMTU3P3XPZCBHANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.***>

Tianhao-Qi commented 1 year ago

Actually, I want to search images given one image URL at billion scales to support my research.

https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1631948889

rom1504 commented 1 year ago

So that's only a single query or thousands of similar ones ? Any pattern ?

On Wed, Jul 12, 2023, 09:12 Tianhao-Qi @.***> wrote:

Actually, I want to search images given one image URL at billion scales to support my research.

251 (comment)

https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1631948889

— Reply to this email directly, view it on GitHub https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1631972211, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437SAZ7IK74X644N576LXPZE65ANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.***>

Tianhao-Qi commented 1 year ago

I wanna get 10k~100k images through a single query.

So that's only a single query or thousands of similar ones ? Any pattern ? On Wed, Jul 12, 2023, 09:12 Tianhao-Qi @.> wrote: Actually, I want to search images given one image URL at billion scales to support my research. #251 (comment) <#251 (comment)> — Reply to this email directly, view it on GitHub <#251 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437SAZ7IK74X644N576LXPZE65ANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.>

ghost commented 1 year ago

I wanna get 10k~100k images through a single query.

So that's only a single query or thousands of similar ones ? Any pattern ? On Wed, Jul 12, 2023, 09:12 Tianhao-Qi @.**> wrote: Actually, I want to search images given one image URL at billion scales to support my research. #251 (comment) <#251 (comment)> — Reply to this email directly, view it on GitHub <#251 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437SAZ7IK74X644N576LXPZE65ANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.**>

+1

rom1504 commented 1 year ago

How many queries

The fewer information you provide the less likely we can find a solution

On Thu, Jul 20, 2023, 15:13 Iheb Belgacem @.***> wrote:

I wanna get 10k~100k images through a single query.

So that's only a single query or thousands of similar ones ? Any pattern ? … <#m6587339981003085040> On Wed, Jul 12, 2023, 09:12 Tianhao-Qi @.*> wrote: Actually, I want to search images given one image URL at billion scales to support my research.

251 https://github.com/rom1504/clip-retrieval/issues/251 (comment) <#251

(comment) https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1631948889> — Reply to this email directly, view it on GitHub <#251 (comment) https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1631972211>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437SAZ7IK74X644N576LXPZE65ANCNFSM6AAAAAAVLQMFD4 https://github.com/notifications/unsubscribe-auth/AAR437SAZ7IK74X644N576LXPZE65ANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @*.>

+1

— Reply to this email directly, view it on GitHub https://github.com/rom1504/clip-retrieval/issues/251#issuecomment-1643904509, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437SCEDIOFWNDWXXIITLXREVHLANCNFSM6AAAAAAVLQMFD4 . You are receiving this because you were mentioned.Message ID: @.***>