运行https://github.com/towhee-io/examples/blob/main/image/reverse_image_search/2_deep_dive_image_search.ipynb中的示例代码,却出现如下错误:
<IPython.core.display.HTML object>
A new collection created: deep_dive_image_search_vgg16
Traceback (most recent call last):
File "/home/xxx/source2023/milvus-example/reverse_image_search/my3.py", line 110, in <module>
.output('mr')
File "/home/xxx/.local/lib/python3.10/site-packages/towhee/runtime/pipeline.py", line 116, in output
run_pipe = RuntimePipeline(dag_dict, config=config_kws)
File "/home/xxx/.local/lib/python3.10/site-packages/towhee/runtime/runtime_pipeline.py", line 99, in __init__
self._dag_repr = DAGRepr.from_dict(dag_dict)
File "/home/xxx/.local/lib/python3.10/site-packages/towhee/runtime/dag_repr.py", line 305, in from_dict
dag_nodes, schema_edges = DAGRepr.set_edges(nodes)
File "/home/xxx/.local/lib/python3.10/site-packages/towhee/runtime/dag_repr.py", line 229, in set_edges
edges[out_id] = DAGRepr.get_edge_from_schema(tuple(out_schema), nodes[name].inputs, nodes[name].outputs,
File "/home/xxx/.local/lib/python3.10/site-packages/towhee/runtime/dag_repr.py", line 196, in get_edge_from_schema
inputs_type = [ahead_schemas[inp].type for inp in inputs]
File "/home/xxx/.local/lib/python3.10/site-packages/towhee/runtime/dag_repr.py", line 196, in <listcomp>
inputs_type = [ahead_schemas[inp].type for inp in inputs]
KeyError: 'img_path'
相关代码行如下:
# Embedding pipeline
p_embed = (
pipe.input('img_path')
.map('img_path', 'img', ops.image_decode('rgb'))
.map('img', 'vec', ops.image_embedding.timm(model_name=MODEL, device=DEVICE))
.map('vec', 'vec', lambda x: x / numpy.linalg.norm(x, axis=0))
)
......
# Insert data
p_insert = (
p_embed.map(('img_path', 'vec'), 'mr', ops.ann_insert.milvus_client(
host=HOST,
port=PORT,
collection_name=COLLECTION_NAME
))
.output('mr')
)
针对如上代码进行研究 ,我觉得应该是p_insert和p_embed之间管道拼接有问题,于是重写了一个p_insert,不使用管道拼接的方式:
112 p_insert = (
113 pipe.input('img_path')
114 .map('img_path', 'img', ops.image_decode('rgb'))
115 .map('img', 'vec', ops.image_embedding.timm(model_name=MODEL, device=DEVICE))
116 .map('vec', 'vec', lambda x: x / numpy.linalg.norm(x, axis=0))
117 .map(('img_path', 'vec'), 'mr', ops.ann_insert.milvus_client(
118 host=HOST,
119 port=PORT,
120 collection_name=COLLECTION_NAME
121 ))
122 .output('mr')
123 )
果然,问题解决!!!