# image_embeddings
[![pypi](https://img.shields.io/pypi/v/image_embeddings.svg)](https://pypi.python.org/pypi/image_embeddings)
[![ci](https://github.com/rom1504/image_embeddings/workflows/Continuous%20integration/badge.svg)](https://github.com/rom1504/image_embeddings/actions?query=workflow%3A%22Continuous+integration%22)
Using efficientnet to provide embeddings for retrieval.
Why this repo ? Embeddings are a widely used technique that is well known in scientific circles. But it seems to be underused and not very well known for most engineers. I want to show how easy it is to represent things as embeddings, and how many application this unlocks.
![knn example](knn_example.png)
## Workflow
1. download some pictures
2. run inference on them to get embeddings
3. simple knn example, to understand what's the point : click on some pictures and see KNN
## Simple Install
Run `pip install image_embeddings`
## Example workflow
1. run `image_embeddings save_examples_to_folder --images_count=1000 --output_folder=tf_flower_images`, this will retrieve 1000 image files from https://www.tensorflow.org/datasets/catalog/tf_flowers (but you can also pick any other dataset)
2. produce tf records with `image_embeddings write_tfrecord --image_folder=tf_flower_images --output_folder=tf_flower_tf_records --shards=10`
3. run the inference with `image_embeddings run_inference --tfrecords_folder=tf_flower_tf_records --output_folder=tf_flower_embeddings`
4. run a random knn search on them `image_embeddings random_search --path=tf_flower_embeddings`
```
$ image_embeddings random_search --path=tf_flower_embeddings
image_roses_261
160.83 image_roses_261
114.36 image_roses_118
102.77 image_roses_537
92.95 image_roses_659
88.49 image_roses_197
```
Explore the [Simple notebook](notebooks/using_the_lib.ipynb) for more details.
You can try it locally or [try it in colab](https://colab.research.google.com/github/rom1504/image_embeddings/blob/master/notebooks/using_the_lib.ipynb)
The [From scratch](notebooks/from_scratch.ipynb) notebook provides an explanation on how to build this from scratch.
## API
### image_embeddings.downloader
Downloader from tensorflow datasets. Any other set of images could be used instead
#### image_embeddings.downloader.save_examples_to_folder(output_folder, images_count=1000, dataset="tf_flowers")
Save https://www.tensorflow.org/datasets/catalog/tf_flowers to folder
Also works with other tf datasets
### image_embeddings.inference
Create tf recors from images files, and apply inference with an efficientnet model. Other models could be used.
#### image_embeddings.inference.write_tfrecord(image_folder, output_folder, num_shards=100)
Write tf records from an image folders
#### image_embeddings.inference.run_inference(tfrecords_folder, output_folder, batch_size=1000)
Run inference on provided tf records and save to folder the embeddings
### image_embeddings.knn
Convenience methods to read, build indices and apply search on them. These methods are provided as example.
Use [faiss](https://github.com/facebookresearch/faiss) directly for bigger datasets.
#### image_embeddings.knn.read_embeddings(path)
Run embeddings from path and return a tuple with
* embeddings as a numpy matrix
* an id to name dictionary
* a name to id dictionary
#### image_embeddings.knn.build_index(emb)
Build a simple faiss inner product index using the provided matrix of embeddings
#### image_embeddings.knn.search(index, id_to_name, emb, k=5)
Search the query embeddings and return an array of (distance, name) images
#### image_embeddings.knn.display_picture(image_path, image_name)
Display one picture from the given path and image name in jupyter
#### image_embeddings.knn.display_results(image_path, results)
Display the results from search method
#### image_embeddings.knn.random_search(path)
Load the embeddings, apply a random search on them and display the result
## Advanced Installation
### Prerequisites
Make sure you use `python>=3.6` and an up-to-date version of `pip` and
`setuptools`
python --version
pip install -U pip setuptools
It is recommended to install `image_embeddings` in a new virtual environment. For
example
python3 -m venv image_embeddings_env
source image_embeddings_env/bin/activate
pip install -U pip setuptools
pip install image_embeddings
### Using Pip
pip install image_embeddings
### From Source
First, clone the `image_embeddings` repo on your local machine with
git clone https://github.com/rom1504/image_embeddings.git
cd image_embeddings
make install
To install development tools and test requirements, run
make install-dev
## Test
To run unit tests in your current environment, run
make test
To run lint + unit tests in a fresh virtual environment,
run
make venv-lint-test
## Lint
To run `black --check`:
make lint
To auto-format the code using `black`
make black
## Tasks
* [x] simple downloader in python
* [x] simple inference in python using https://github.com/qubvel/efficientnet
* [x] build python basic knn example using https://github.com/facebookresearch/faiss
* [ ] build basic ui using lit element and some brute force knn to show what it does, put in github pages
* [ ] use to illustrate embeddings blogpost
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共21个文件
py:11个
txt:6个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:image_embeddings-1.3.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
image_embeddings-1.3.1.tar.gz (21个子文件)
image_embeddings-1.3.1
PKG-INFO 7KB
image_embeddings.egg-info
PKG-INFO 7KB
requires.txt 142B
SOURCES.txt 625B
entry_points.txt 69B
top_level.txt 17B
dependency_links.txt 1B
image_embeddings
knn
knn.py 2KB
__init__.py 152B
downloader
__init__.py 97B
tf_datasets_saver.py 4KB
__init__.py 125B
inference
inference.py 6KB
__init__.py 79B
version.py 76B
cli
main.py 619B
__init__.py 0B
setup.cfg 38B
requirements.txt 154B
setup.py 2KB
README.md 5KB
共 21 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于opencv+yolov8实现目标追踪及驻留时长统计源码.zip
- 水稻病害基于Yolov8算法优化目标检测识别与AI辅助决策python源码+模型+使用说明.zip
- 海尔618算价表_七海5.20_16.00xlsx(1)(2).xlsx
- WebCrawler.scr
- 【计算机专业毕业设计】大学生就业信息管理系统设计源码.zip
- YOLO 数据集:8种路面缺陷病害检测【包含划分好的数据集、类别class文件、数据可视化脚本】
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于YOLOv8的FPS TPS AI自动锁定源码+使用步骤说明.zip
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于yolov8+streamlit的火灾检测部署源码+模型.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功