TowHee示例程序KeyError: ‘img_path‘问题

在运行Towhee的示例代码时遇到错误,错误涉及DAGRepr和输入simg_path。通过重新编写p_insert部分,避免管道拼接,问题得到解决。修复后的代码在112至123行,成功将图像路径和向量插入Milvus集合。
摘要由CSDN通过智能技术生成

运行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 )

果然,问题解决!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值