This repository aims at giving sample code for vector search with Azure Computer Vision Image retrieval API and faiss
.
Other reference:
- Revolutionizing Image Search with Vectors
- What is Azure AI Vision?
- Computer Vision の Image Retrieval を使って画像のベクトル検索を行う in Japanese
- Quickstart: Image Analysis 4.0
-
Environmental setting
python
libraries:
pip install -r ./requirements.txt
-
API assumption
- Prepare Flickr account, where we can get several image under creative commons license.
- Prepare Azure Computer vision API
-
Configuration You need to prepare the
config.yml
file for configuration. Once you put values, please allocate it in the top directory of the repository:## Flickr account flickr: API_KEY: <YOUR API KEY> API_SECRET: <YOUR API SECRET> NUMBER_OF_IMAGES: 100 ## How many images do you use? NUMBER_PROCESS_IMAGES: 10 ## Prepare for test image: folder: './downloaded_images' Azure: KEY: <YOUR API KEY FOR AZURE COMPUTER VISION> ENDPOINT: 'https://<YOUR CV RESOURCE NAME>.cognitiveservices.azure.com' faiss: dimension: 1024 filename: 'imageIndex.pkl' top_N: 5 ## How many you use meta_data: vectors_name: 'vectors.pkl' display: num_cols: 1 ## How many columns in displaying the result?
-
Run the codes!
- If you succeed in running the notebook, you get the following result in the end.
- Here are quick summary of the procedures:
- Get several images in Flickr.
- For the downloaded images, we append vector with
vectorizeImage
API. - Store the vectors in
faiss
, where we can query images after converting text or image into vector. - We put
many people
as argument ofquery_text
of the methoddisplayWithText
. Then, the text is converted into vector withvectorizeText
API, and it's used for searching pre-stored images.
- If you succeed in running the notebook, you get the following result in the end.
- API refrence for azure-ai-vision
- If python doesn't see the package, try:
!pip show
- Then, add the path as follows:
sys.path.append('/anaconda/envs/azureml_py38/lib/python3.8/site-packages')
- Then, add the path as follows:
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.