Error Box 之 'zip' object is not subscriptable

TypeError: 'zip' object is not subscriptable

def create_ssd_anchors(num_layers=6,
                       min_scale=0.2,
                       max_scale=0.95):
  box_specs_list = []
  scales = [min_scale + (max_scale - min_scale) * i / (num_layers - 1)
            for i in range(num_layers)] + [1.0]
  return zip(scales[:-1], scales[1:])

self.anchors = create_ssd_anchors()
min_size, max_size = self.anchors[0]

这是因为在Python 3.x中,zip返回一个生成器对象。这个对象不是一个列表。

解决方法:

def create_ssd_anchors(num_layers=6,
                       min_scale=0.2,
                       max_scale=0.95):
  box_specs_list = []
  scales = [min_scale + (max_scale - min_scale) * i / (num_layers - 1)
            for i in range(num_layers)] + [1.0]
  return list(zip(scales[:-1], scales[1:]))

self.anchors = create_ssd_anchors()
min_size, max_size = self.anchors[0]

TypeError: object of type 'zip' has no len()

同理!

阅读更多
个人分类: Error Box
上一篇Error Box 之 'collections.OrderedDict' object has no attribute 'iterkeys'
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭