【问题标题】:TypeError: 'map' object is not reversibleTypeError:“地图”对象不可逆
【发布时间】:2018-07-31 02:40:15
【问题描述】:

我花了将近 2 个小时来使用来自 weights.npz 的预训练模型 (tensorflow) 来检测车牌,但我无法修复它。我收到了这个错误信息,我以前从未见过。那么,如何解决呢?

Traceback(最近一次调用最后一次):文件“./detect.py”,第 189 行,在 pt1 = tuple(reversed(map(int, pt1))) TypeError: 'map' object is not reversible

【问题讨论】:

  • 这明明是python 2模块,python 3的代码应该是pt1 = tuple(reversed(list(map(int, pt1))))lists 毕竟绝对是可逆的

标签: python python-3.x opencv tensorflow


【解决方案1】:

在 python3 中,map 返回一个迭代器,而不是列表。您需要使用list 构造函数来包装对map() 的调用:

pt1 = tuple(reversed(list(map(int, pt1))))

查看更多:Getting a map() to return a list in Python 3.x

【讨论】:

    【解决方案2】:

    改用list comprehensiongenerator expression

    pt1 = tuple(int(x) for x in reversed(pt1))
    

    【讨论】:

      猜你喜欢
      • 2018-08-06
      • 2017-08-14
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 2016-07-20
      相关资源
      最近更新 更多