clip image search
1.0.0
使用打开AI预验证的剪辑模型根据查询(文本或图像)检索图像。
文字作为查询。
图像作为查询。
剪辑(对比性语言图像预训练)是一个在各种(图像,文本)对中训练的神经网络。它可以将图像和文本映射到相同的潜在空间中,以便可以使用相似度度量进行比较。
在此存储库中扩展工作,我创建了一个简单的图像搜索引擎,可以将文本和图像作为查询。搜索引擎工作如下:
image_id: {"url": https://abc.com/xyz, "feature_vector": [0.1, 0.3, ..., 0.2]}
我使用了包含25,000张图像的Unsplash数据集的Lite版本。 K-Neart的邻居搜索由Amazon Elasticsearch服务提供动力。我将查询服务部署为AWS lambda功能,并在其前面放置API网关。前端是使用精简的。
pip install -e . --no-cache-dir
python scripts/download_unsplash.py --image_width=480 --threads_count=32
这将下载并提取包含有关数据集中照片的元数据的zip文件。 The script will use the URLs of the photos to download the actual images to unsplash-dataset/photos .下载可能会因几张图像而失败(请参阅此问题)。由于剪辑无论如何都会将图像置于224 x 224,因此您可能需要调整下载图像的宽度以减少存储空间。 You may also want to increase the threads_count parameter to achieve a faster performance.
python scripts/ingest_data.py
该脚本将下载审计的剪辑模型,并批次处理图像。如果有一个,它将使用GPU。
为AWS lambda构建Docker图像。
docker build --build-arg AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID
--build-arg AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY
--tag clip-image-search
--file server/Dockerfile .
将Docker图像作为容器运行。
docker run -p 9000:8080 -it --rm clip-image-search
用邮政请求测试容器。
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"query": "two dogs", "input_type": "text"}'
streamlit run streamlit_app.py