错误提示:TypeError: 'dict_keys' object is not subscriptable
代码原文:
img_name_to_tokens = parse_token_file(input_description_file)
all_img_names = img_name_to_tokens.keys()
logging.info('num of all images: %d' % len(all_img_names))
pprint.pprint(img_name_to_tokens.keys()[0:10])
解决方法:
img_name_to_tokens.keys() 改为 list(img_name_to_tokens.keys())
img_name_to_tokens = parse_token_file(input_description_file)
all_img_names = img_name_to_tokens.keys()
logging.info('num of all images: %d' % len(all_img_names))
pprint.pprint(list(img_name_to_tokens.keys())[0:10])