Android小白 2022-05-22 21:16 采纳率: 20%
浏览 236
已结题

labels.append(self.class_dict[obj["name"]]) TypeError: string indices must be integers

json文件里面有“name”对应的val值是整数,想问下大家为啥传不过来json文件里的val值,是我解析json文件出问题了吗。


json_file = './pascal_voc_classes.json'
        assert os.path.exists(json_file), "{} file not exist.".format(json_file)
        with open(json_file, 'r') as f:
            f = demjson.encode(json_file)
            self.class_dict = json.loads(f)

 labels.append(self.class_dict[obj["name"]])

Original Traceback (most recent call last):
  File "F:\Anaconda\lib\site-packages\torch\utils\data\_utils\worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "F:\Anaconda\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "F:\Anaconda\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "G:\code\deep-learning-for-image-processing-master\pytorch_object_detection\faster_rcnn\my_dataset.py", line 97, in __getitem__
    labels.append(self.class_dict[obj["name"]])
TypeError: string indices must be integers

这是我的json文件:

img

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月30日
    • 创建了问题 5月22日

    悬赏问题

    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题