Skip to content

Commit

Permalink
Merge pull request #1046 from shiyu22/towhee0.6
Browse files Browse the repository at this point in the history
Update to Milvus2.0.2 and Towhee0.6
  • Loading branch information
shiyu22 committed Apr 12, 2022
2 parents 8ce84cb + 1fb4f75 commit 88ef7b2
Show file tree
Hide file tree
Showing 40 changed files with 124 additions and 1,335 deletions.
8 changes: 4 additions & 4 deletions solutions/reverse_image_search/object_detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

This demo uses the [towhee](https://github.com/towhee-io/towhee) pipelines to detect objects in images and extract feature vectors of images, and then uses Milvus to build an image similarity search system.
This demo uses the [towhee](https://github.com/towhee-io/towhee) operators to detect objects in images and extract feature vectors of images, and then uses Milvus to build an image similarity search system.

The following is the system diagram.

Expand Down Expand Up @@ -61,7 +61,7 @@ And show all containers with `docker ps`, and you can use `docker logs img-searc

```bash
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4cc6e60eb295 milvusbootcamp/imgsearch-with-objdet:towhee "/bin/sh -c 'python3…" 56 seconds ago Up 55 seconds 0.0.0.0:5010->5010/tcp img-obj-det-webserver
4cc6e60eb295 milvusbootcamp/imgsearch-with-objdet:towhee "/bin/sh -c 'python3…" 56 seconds ago Up 55 seconds 0.0.0.0:5000->5000/tcp img-obj-det-webserver
40f4ea99fd22 milvusdb/milvus:v2.0.0-rc8-20211104-d1f4106 "/tini -- milvus run…" 57 seconds ago Up 55 seconds 0.0.0.0:19530->19530/tcp milvus-standalone
60ed080afac1 minio/minio:RELEASE.2020-12-03T00-03-10Z "/usr/bin/docker-ent…" 57 seconds ago Up 56 seconds (healthy) 9000/tcp milvus-minio
5d9cdfba872b mysql:5.7 "docker-entrypoint.s…" 57 seconds ago Up 56 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp img-obj-det-mysql
Expand Down Expand Up @@ -122,7 +122,7 @@ $ python main.py

- **API docs**

Visit 127.0.0.1:5010/docs in your browser to use all the APIs.
Visit `127.0.0.1:5000/docs` in your browser to use all the APIs.

![fastapi](pic/fastapi.png)

Expand All @@ -144,7 +144,7 @@ Visit 127.0.0.1:5010/docs in your browser to use all the APIs.

```bash
# Modify API_URL to the IP address and port of the server.
$ export API_URL='http://127.0.0.1:5010'
$ export API_URL='http://127.0.0.1:5000'
$ docker run -d -p 8001:80 \
-e API_URL=${API_URL} \
milvusbootcamp/img-search-client:1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:

standalone:
container_name: milvus-standalone
image: milvusdb/milvus:v2.0.0-rc8-20211104-d1f4106
image: milvusdb/milvus:v2.0.2
networks:
app_net:
ipv4_address: 172.16.238.10
Expand Down Expand Up @@ -62,7 +62,7 @@ services:

webserver:
container_name: img-obj-det-webserver
image: milvusbootcamp/imgsearch-with-objdet:towhee
image: milvusbootcamp/img-search-with-object:towhee0.6
networks:
app_net:
ipv4_address: 172.16.238.12
Expand All @@ -76,7 +76,7 @@ services:
- standalone
- mysql
ports:
- "5010:5010"
- "5000:5000"

webclient:
container_name: img-obj-det-webclient
Expand All @@ -85,7 +85,7 @@ services:
app_net:
ipv4_address: 172.16.238.13
environment:
API_URL: 'http://127.0.0.1:5010'
API_URL: 'http://127.0.0.1:5000'
ports:
- "8001:80"
healthcheck:
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pymilvus==2.0.1
pymilvus==2.0.2
diskcache==5.2.1
uvicorn==0.13.4
PyMySQL==1.0.2
Expand All @@ -14,4 +14,7 @@ torch==1.9.0
pillow==9.0.1
matplotlib
seaborn
towhee==0.2.0
towhee==0.6.0
scipy
opencv-python
pyyaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
############### Milvus Configuration ###############
MILVUS_HOST = os.getenv("MILVUS_HOST", "127.0.0.1")
MILVUS_PORT = int(os.getenv("MILVUS_PORT", "19530"))
VECTOR_DIMENSION = int(os.getenv("VECTOR_DIMENSION", "1000"))
VECTOR_DIMENSION = int(os.getenv("VECTOR_DIMENSION", "2048"))
INDEX_FILE_SIZE = int(os.getenv("INDEX_FILE_SIZE", "1024"))
METRIC_TYPE = os.getenv("METRIC_TYPE", "L2")
DEFAULT_TABLE = os.getenv("DEFAULT_TABLE", "milvus_obj_det")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
from towhee import pipeline
import towhee
import cv2
from numpy import linalg as LA

# os.environ['KERAS_HOME'] = os.path.abspath(os.path.join('.', 'data'))


class CustomOperator:
"""
Say something about the ExampleCalass...
Args:
args_0 (`type`):
...
"""
def __init__(self):
#self.img_embedding = pipeline('image-embedding')
self.yolo_embedding = pipeline('shiyu/img_object_embedding_pytorch_yolov5_resnet50')

def execute(self, img_path):
objs = self.yolo_embedding(img_path)
boxes, _, _ = towhee.glob(img_path) \
.image_decode() \
.object_detection.yolov5() \
.to_list()[0]

imgs = self.get_imgs_list(img_path, boxes)
embeddings = towhee.dc(imgs) \
.image_embedding.timm(model_name='resnet50') \
.to_list()

norm_objs = []
for feat in objs:
norm_feat = feat[0] / LA.norm(feat[0])
for feat in embeddings:
norm_feat = feat / LA.norm(feat)
norm_objs.append(norm_feat.tolist())
return norm_objs


@staticmethod
def get_imgs_list(img_path, boxes):
img_list = []
img = cv2.imread(img_path)

for box in boxes:
tmp_obj = img[int(box[1]):int(box[3]), int(box[0]):int(box[2])]
img_list.append(towhee._types.Image(tmp_obj, 'BGR'))
return img_list

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ async def search_images(image: UploadFile = File(...), table_name: str = None):


if __name__ == '__main__':
uvicorn.run(app=app, host='0.0.0.0', port=5010)
uvicorn.run(app=app, host='0.0.0.0', port=5000)
Empty file.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 88ef7b2

Please sign in to comment.