mmdetection icon indicating copy to clipboard operation
mmdetection copied to clipboard

"tasks" must be a tuple object or a sequence object, but got <class 'dict_values'>

Open xiaojing12581 opened this issue 1 year ago • 6 comments

colab中 nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2022 NVIDIA Corporation Built on Wed_Sep_21_10:33:58_PDT_2022 Cuda compilation tools, release 11.8, V11.8.89 Build cuda_11.8.r11.8/compiler.31833905_0 gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

运行 import os.path as osp import mmcv from mmengine.fileio import dump, load from mmengine.utils import track_iter_progress

def convert_balloon_to_coco(ann_file, out_file, image_prefix): data_infos = load(ann_file)

annotations = []
images = []
obj_count = 0
for idx, v in enumerate(track_iter_progress(data_infos.values())):
    filename = v['filename']
    img_path = osp.join(image_prefix, filename)
    height, width = mmcv.imread(img_path).shape[:2]

    images.append(
        dict(id=idx, file_name=filename, height=height, width=width))
    
    for _, obj in v['regions'].items():
        assert not obj['region_attributes']
        obj = obj['shape_attributes']
        px = obj['all_points_x']
        py = obj['all_points_y']
        poly = [(x + 0.5, y + 0.5) for x, y in zip(px, py)]
        poly = [p for x in poly for p in x]

        x_min, y_min, x_max, y_max = (min(px), min(py), max(px), max(py))

        data_anno = dict(
            image_id=idx,
            id=obj_count,
            category_id=0,
            bbox=[x_min, y_min, x_max - x_min, y_max - y_min],
            area=(x_max - x_min) * (y_max - y_min),
            segmentation=[poly],
            iscrowd=0)
        annotations.append(data_anno)
        obj_count += 1

coco_format_json = dict(
    images=images,
    annotations=annotations,
    categories=[{
        'id': 0,
        'name': 'balloon'
    }])
dump(coco_format_json, out_file)

if name == 'main': convert_balloon_to_coco(ann_file='data/balloon/train/via_region_data.json', out_file='data/balloon/train.json', image_prefix='data/balloon/train') convert_balloon_to_coco(ann_file='data/balloon/val/via_region_data.json', out_file='data/balloon/val.json', image_prefix='data/balloon/val') 在for idx, v in enumerate(track_iter_progress(data_infos.values())):这句提示报错如下:

TypeError Traceback (most recent call last) in <cell line: 50>() 49 50 if name == 'main': ---> 51 convert_balloon_to_coco(ann_file='data/balloon/train/via_region_data.json', 52 out_file='data/balloon/train.json', 53 image_prefix='data/balloon/train')

1 frames /usr/local/lib/python3.10/dist-packages/mmengine/utils/progressbar.py in track_iter_progress(tasks, bar_width, file) 238 task_num = len(tasks) 239 else: --> 240 raise TypeError( 241 '"tasks" must be a tuple object or a sequence object, but got ' 242 f'{type(tasks)}')

TypeError: "tasks" must be a tuple object or a sequence object, but got <class 'dict_values'>

xiaojing12581 avatar Dec 13 '23 15:12 xiaojing12581

I had got the same problem

lijoe123 avatar Dec 14 '23 03:12 lijoe123

The same issue.

I launched this tutorial (recent commit: e95c5a4) in Google Collab.

angarsky avatar Dec 19 '23 14:12 angarsky

A workaround I found is to cast data_infos as a Sequence (e.g. a list) in convert_balloon_to_coco before the loop:

data_infos = list(data_infos.values())

Abdol avatar Dec 21 '23 15:12 Abdol

Better add list() to 12 row.

for idx, v in enumerate(track_iter_progress(list(data_infos.values()))):

If you just add row

data_infos = list(data_infos.values())

you can give

AttributeError: 'list' object has no attribute 'values'

MACTEPBEKA avatar Feb 29 '24 10:02 MACTEPBEKA

for idx, v in enumerate(track_iter_progress(list(data_infos.values()))): works for me

loushuai avatar May 16 '24 05:05 loushuai

for idx, v in enumerate(mmengine.track_iter_progress(list(data_infos.values()))):

works for me

Syed05 avatar May 30 '24 13:05 Syed05