towhee icon indicating copy to clipboard operation
towhee copied to clipboard

[Bug]: File "pydantic\json.py", line 45, in pydantic.json.lambda UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Open suforme opened this issue 3 years ago • 5 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

from pymilvus import connections, FieldSchema, CollectionSchema, DataType, Collection, utility

connections.connect(host='192.168.0.101', port='19530')

def create_milvus_collection(collection_name, dim): if utility.has_collection(collection_name): utility.drop_collection(collection_name)

fields = [
    FieldSchema(name='path', dtype=DataType.VARCHAR, descrition='path to image', max_length=500, 
                is_primary=True, auto_id=False),
    FieldSchema(name='embedding', dtype=DataType.FLOAT_VECTOR, descrition='image embedding vectors', dim=dim)
]
schema = CollectionSchema(fields=fields, description='reverse image search')
collection = Collection(name=collection_name, schema=schema)

index_params = {
    'metric_type':'L2',
    'index_type':"IVF_FLAT",
    'params':{"nlist":2048}
}
collection.create_index(field_name="embedding", index_params=index_params)
return collection

import towhee bench_collection = create_milvus_collection('resnet50', 2048) ( towhee.glob'path' .image_decode'path', 'img' .image_embedding.timm'img', 'vec' .tensor_normalize'vec', 'vec' .ann_insert.milvus('path', 'vec'), 'mr' )

import time import towhee from fastapi import FastAPI from pymilvus import connections, Collection

app = FastAPI() connections.connect(host='192.168.0.101', port='19530') milvus_collection = Collection('resnet50')

@towhee.register(name='get_path_id') def get_path_id(path): timestamp = int(time.time()*10000) id_img[timestamp] = path return timestamp

@towhee.register(name='milvus_insert') class MilvusInsert: def init(self, collection): self.collection = collection

def __call__(self, *args, **kwargs):
    data = []
    for iterable in args:
        data.append([iterable])
    mr = self.collection.insert(data)
    self.collection.load()
    return str(mr)

with towhee.api'file' as api: app_insert = ( api.image_load'file', 'img' .save_image'img', 'path' .get_path_id'path', 'id' .image_embedding.timm'img', 'vec' .tensor_normalize'vec', 'vec' .milvus_insert('id', 'vec'), 'res' .select'id', 'path' .serve('/insert', app) )

with towhee.api'file' as api: app_search = ( api.image_load'file', 'img' .image_embedding.timm'img', 'vec' .tensor_normalize'vec', 'vec' .milvus_search'vec', 'result' .runas_op['result', 'res_file'](func=lambda res: str([x.id for x in res])) .select'res_file' .serve('/search', app) )

with towhee.api() as api: app_count = ( api.map(lambda _: milvus_collection.num_entities) .serve('/count', app) )

import uvicorn import nest_asyncio

nest_asyncio.apply() uvicorn.run(app=app, host='localhost', port=8000)

Expected Behavior

微信截图_20220913174203 微信截图_20220913174221 微信截图_20220913174248

Steps To Reproduce

No response

Environment

- Towhee version(e.g. v0.1.3 or 8b23a93):
- OS(Ubuntu or CentOS):
- CPU/Memory:
- GPU:
- Others:

Anything else?

No response

suforme avatar Sep 13 '22 09:09 suforme

@suforme thank you for the issue.

Could you please provide which towhee version you are using?

binbinlv avatar Sep 13 '22 10:09 binbinlv

@shiyu22

Could you please help on this issue about milvus search scenario within towhee? thanks.

binbinlv avatar Sep 13 '22 10:09 binbinlv

Hi @suforme, can you run with curl command, such as curl -X POST "http://0.0.0.0:8000/search" --data-binary @test/lion/n02129165_13728.JPEG -H 'Content-Type: image/jpeg'?

BTW, you can try the latest notebook and run with Body data in postman: image

shiyu22 avatar Sep 13 '22 11:09 shiyu22

towhee 0.8.0 towhee.models 0.8.0

suforme avatar Sep 13 '22 11:09 suforme

Python 3.10.6 @binbinlv

suforme avatar Sep 13 '22 11:09 suforme

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Rotten issues close after 30d of inactivity. Close the stale issues and pull requests after 7 days of inactivity. Reopen the issue with /reopen.

stale[bot] avatar Oct 13 '22 23:10 stale[bot]