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

How to use local data #181

Closed lonleyodd closed 10 months ago

lonleyodd commented 2 years ago

thanks for building this work and sharing it. I want to know how to use my own dataset, when I use inference download of img2dataset package to create my local data, such as /data/wang/data/emotion/val/val_00000000.jpg, the folder can not be created properly,and the key status_dict of status.json shows "unknown url type",how to fix it? thanks

rom1504 commented 2 years ago

If you already have local data you do not need to use img2dataset at all

On Thu, Sep 15, 2022, 05:08 lonelyRyze @.***> wrote:

thanks for building this work and sharing it. I want to know how to use my own dataset, when I use inference download of img2dataset package to create my local data, such as /data/wang/data/emotion/val/val_00000000.jpg, the folder can not be created properly,and the key status_dict of status.json shows "unknown url type",how to fix it? thanks

— Reply to this email directly, view it on GitHub https://github.com/rom1504/clip-retrieval/issues/181, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437UVU2HB7AT3EE6D4QTV6KHLJANCNFSM6AAAAAAQM65YNU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

nielsrolf commented 2 years ago

How exactly does it work then? I tried:

clip-retrieval inference --input_dataset sample_images --output_folder embeddings_folder --batch_size 4 --num_prepro_workers 1
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.8.15/bin/clip-retrieval", line 33, in <module>
    sys.exit(load_entry_point('clip-retrieval', 'console_scripts', 'clip-retrieval')())
  File "/src/clip-retrieval/clip_retrieval/cli.py", line 18, in main
    fire.Fire(
  File "/root/.pyenv/versions/3.8.15/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/root/.pyenv/versions/3.8.15/lib/python3.8/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/root/.pyenv/versions/3.8.15/lib/python3.8/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/src/clip-retrieval/clip_retrieval/clip_inference/main.py", line 106, in main
    output_partition_count = calculate_partition_count(
  File "/src/clip-retrieval/clip_retrieval/clip_inference/main.py", line 41, in calculate_partition_count
    keys, text_files, image_files, metadata_files = folder_to_keys(
  File "/src/clip-retrieval/clip_retrieval/clip_inference/reader.py", line 40, in folder_to_keys
    keys = list(sorted(keys))
TypeError: 'NoneType' object is not iterable
ghost commented 1 year ago

@nielsrolf

How exactly does it work then? I tried:

Personnally, I added --enable-text False to the command because I have no text to process.

I found it when reading the following code which put keys to None if you have no text https://github.com/rom1504/clip-retrieval/blob/e6884fc973d7be7cb44eb1223989ea585606d2e0/clip_retrieval/clip_inference/reader.py#L33-L38

My full command is like this clip-retrieval inference --input_dataset path/to/img_dir --output_folder path/to/output_embeddings_folder --enable-text False

I hope it will help other people who search how to use the amazing clip-retrieval tool with local images.