python怎么索引txt数据中第四行_如何使用python从列表中读取数据并将特定值索引到Elasticsearch中?...

importelasticsearchfromelasticsearchimportElasticsearch,helpersimportdatetimeimportre

data=['labels: imagenet_labels.txt \n','\n','Model: efficientnet-edgetpu-S_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 23.1\n','Time(ms): 5.7\n','\n','\n','Inference: corkscrew, bottle screw\n','Score: 0.03125 \n','\n','TPU_temp(°C): 57.05\n','##################################### \n','\n','labels: imagenet_labels.txt \n','\n','Model: efficientnet-edgetpu-M_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 29.3\n','Time(ms): 10.8\n','\n','\n',"Inference: dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk\n",'Score: 0.09375 \n','\n','TPU_temp(°C): 56.8\n','##################################### \n','\n','labels: imagenet_labels.txt \n','\n','Model: efficientnet-edgetpu-L_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 45.6\n','Time(ms): 31.0\n','\n','\n','Inference: pick, plectrum, plectron\n','Score: 0.09766 \n','\n','TPU_temp(°C): 57.55\n','##################################### \n','\n','labels: imagenet_labels.txt \n','\n','Model: inception_v3_299_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 68.8\n','Time(ms): 51.3\n','\n','\n','Inference: ringlet, ringlet butterfly\n','Score: 0.48047 \n','\n','TPU_temp(°C): 57.3\n','##################################### \n','\n','labels: imagenet_labels.txt \n','\n','Model: inception_v4_299_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 121.8\n','Time(ms): 101.2\n','\n','\n','Inference: admiral\n','Score: 0.59375 \n','\n','TPU_temp(°C): 57.05\n','##################################### \n','\n','labels: imagenet_labels.txt \n','\n','Model: inception_v2_224_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 34.3\n','Time(ms): 16.6\n','\n','\n','Inference: lycaenid, lycaenid butterfly\n','Score: 0.41406 \n','\n','TPU_temp(°C): 57.3\n','##################################### \n','\n','labels: imagenet_labels.txt \n','\n','Model: mobilenet_v2_1.0_224_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 14.4\n','Time(ms): 3.3\n','\n','\n','Inference: leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea\n','Score: 0.36328 \n','\n','TPU_temp(°C): 57.3\n','##################################### \n','\n','labels: imagenet_labels.txt \n','\n','Model: mobilenet_v1_1.0_224_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 14.5\n','Time(ms): 3.0\n','\n','\n','Inference: bow tie, bow-tie, bowtie\n','Score: 0.33984 \n','\n','TPU_temp(°C): 57.3\n','##################################### \n','\n','labels: imagenet_labels.txt \n','\n','Model: inception_v1_224_quant_edgetpu.tflite \n','\n','Image: insect.jpg \n','\n','*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*\n','Time(ms): 21.2\n','Time(ms): 3.6\n','\n','\n','Inference: pick, plectrum, plectron\n','Score: 0.17578 \n','\n','TPU_temp(°C): 57.3\n','##################################### \n','\n']# declare a client instance of the Python Elasticsearch libraryclient=Elasticsearch("http://localhost:9200")#using regexregex=re.compile(r'(\w+)\((.+)\):\s(.*)|(\w+:)\s(.*)')match_regex=list(filter(regex.match,data))match=[line.rstrip('\n')forlineinmatch_regex]#using "bulk"defyield_docs():"""

Initialise les mappings

"""doc_source={"data":match}# use a yield generator so that the doc data isn't loaded into memoryyield{"_index":"coralito","_type":"coralote","_source":doc_source}try:# make the bulk call using 'actions' and get a responseresp=helpers.bulk(client,yield_docs())print("\nhelpers.bulk() RESPONSE:",resp)print("RESPONSE TYPE:",type(resp))exceptExceptionaserr:print("\nhelpers.bulk() ERROR:",err)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值