DEIM icon indicating copy to clipboard operation
DEIM copied to clipboard

training;TypeError: 'Image' object is not subscriptable

Open MercerLuo opened this issue 8 months ago • 2 comments

[rank0]: File "/home/gyd/miniconda3/envs/pytorch/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 55, in fetch [rank0]: return self.collate_fn(data) [rank0]: File "/home/gyd/DEIM-main/engine/data/dataloader.py", line 181, in call [rank0]: images = torch.cat([x[0][None] for x in items], dim=0) [rank0]: File "/home/gyd/DEIM-main/engine/data/dataloader.py", line 181, in [rank0]: images = torch.cat([x[0][None] for x in items], dim=0) [rank0]: TypeError: 'Image' object is not subscriptable

MercerLuo avatar Apr 29 '25 03:04 MercerLuo

@MercerLuo the problem come from your images x[0] is a PIL.Image not a torch tensor.

The solution is in the config file.yaml you must include dataloader.yaml which apply transform methods. For examples, I start using the python scripts

model=m
CUDA_VISIBLE_DEVICES=0,1 torchrun --master_port=7777 --nproc_per_node=2 train.py \
    -c configs/deim_dfine/deim_hgnetv2_${model}_coco.yml \
    --use-amp \
    --seed=0 \
    -t weights/deim_dfine_hgnetv2_m_coco_90e.pth

here is my deim_hgnetv2_m_coco.yml

__include__: [
  './dfine_hgnetv2_m_coco.yml',
  '../base/deim.yml',
  '../dataset/custom_detection.yml',
  '../base/dataloader.yml',
  '../base/optimizer.yml',
  '../runtime.yml',
]

output_dir: ./outputs/deim_hgnetv2_m_gender
. . .

tien-ngnvan avatar May 20 '25 03:05 tien-ngnvan

@MercerLuo the problem come from your images x[0] is a PIL.Image not a torch tensor.

The solution is in the config file.yaml you must include dataloader.yaml which apply transform methods. For examples, I start using the python scripts

model=m CUDA_VISIBLE_DEVICES=0,1 torchrun --master_port=7777 --nproc_per_node=2 train.py
-c configs/deim_dfine/deim_hgnetv2_${model}_coco.yml
--use-amp
--seed=0
-t weights/deim_dfine_hgnetv2_m_coco_90e.pth here is my deim_hgnetv2_m_coco.yml

include: [ './dfine_hgnetv2_m_coco.yml', '../base/deim.yml', '../dataset/custom_detection.yml', '../base/dataloader.yml', '../base/optimizer.yml', '../runtime.yml', ]

output_dir: ./outputs/deim_hgnetv2_m_gender . . .

My questions is what't the function of 'dataloader.yaml'?

jerrytyf avatar Jul 09 '25 11:07 jerrytyf