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文件。該腳本將使用照片的URL下載實際圖像以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