首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从每个类的列表中自信地生成图像captcha的可能解决方案

从每个类的列表中自信地生成图像captcha的可能解决方案
EN

Stack Overflow用户
提问于 2022-06-28 23:14:55
回答 1查看 86关注 0票数 1

我有一个YOLOV5模型,它使用对象检测来解决captchas问题。它返回一个格式的列表:

代码语言:javascript
复制
<object-class> <x> <y> <width> <height> <confidence>

对于每一个类别的检测。

示例:

输入:

输出:

代码语言:javascript
复制
[[
['7l', 0.19, '0.443182', '0.104895', '0.431818', '0.972055'], 
['4l', 0.33, '0.534091', '0.104895', '0.431818', '0.965045'], 
['5l', 0.6, '0.238636', '0.118881', '0.431818', '0.974508'], 
['9l', 0.92, '0.659091', '0.104895', '0.409091', '0.879532'], 
['0l', 0.93, '0.659091', '0.0979021', '0.363636', '0.651053']
]]

如您所见,类9l和0l具有相同的x值,这意味着模型对于一个对象有两个答案。

如何将此列表分成两个可能的列表,如:

7l 4l 5l 9l7l 4l 5l 0l

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-29 12:39:53

首先,您可以将数据转换为字典。

代码语言:javascript
复制
{'0.443182': ['7l'], '0.534091': ['4l'], '0.238636': ['5l'], '0.659091': ['9l', '0l']}

下一次只得到值

代码语言:javascript
复制
[['7l'], ['4l'], ['5l'], ['9l', '0l']]

最后使用itertools.product(['7l'], ['4l'], ['5l'], ['9l', '0l'])生成

代码语言:javascript
复制
('7l', '4l', '5l', '9l')
('7l', '4l', '5l', '0l')

完整的工作代码。

因为标准字典不一定要保持顺序,所以我使用OrderedDict()

代码语言:javascript
复制
import collections
import itertools

data = [[
['7l', 0.19, '0.443182', '0.104895', '0.431818', '0.972055'], 
['4l', 0.33, '0.534091', '0.104895', '0.431818', '0.965045'], 
['5l', 0.6, '0.238636', '0.118881', '0.431818', '0.974508'], 
['9l', 0.92, '0.659091', '0.104895', '0.409091', '0.879532'], 
['0l', 0.93, '0.659091', '0.0979021', '0.363636', '0.651053']
]]

#converted = {}
converted = collections.OrderedDict()

for item in data[0]:
    class_ = item[0]
    x      = item[2]
    #if x not in converted:
    #    converted[x] = []
    #converted[x].append(class_)
    converted.setdefault(x, []).append(class_)
        
print('converted:', converted)

values = list(converted.values())

print('values:', values)

products = list(itertools.product(*values))
print('products:', products)

for item in products:
    print('item:', "".join(item))

结果:

代码语言:javascript
复制
converted: OrderedDict([('0.443182', ['7l']), ('0.534091', ['4l']), ('0.238636', ['5l']), ('0.659091', ['9l', '0l'])])
values: [['7l'], ['4l'], ['5l'], ['9l', '0l']]
products: [('7l', '4l', '5l', '9l'), ('7l', '4l', '5l', '0l')]
item: 7l4l5l9l
item: 7l4l5l0l
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72794129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档