Fafa-DL / Awesome-Backbones

Integrate deep learning models for image classification | Backbone learning/comparison/magic modification project
1.57k stars 249 forks source link

run EfficientNetV2 but the trainpipline always went wrong #127

Closed DC-hydrid closed 2 months ago

DC-hydrid commented 2 months ago

This is the information

Traceback (most recent call last): File "/home/l1ydr1d/MedSAM2/MedSAM-MedSAM2/Awesome-Backbones/tools/train.py", line 170, in main() File "/home/l1ydr1d/MedSAM2/MedSAM-MedSAM2/Awesome-Backbones/tools/train.py", line 164, in main train(model, runner, lr_update_func, device, epoch, data_cfg.get('train').get('epoches'), data_cfg.get('test'), meta) File "/home/l1ydr1d/MedSAM2/MedSAM-MedSAM2/Awesome-Backbones/utils/train_utils.py", line 208, in train for iter, batch in enumerate(runner.get('train_loader')):
File "/home/l1ydr1d/miniconda3/envs/medsam2_py310_torch2-3-1_cuda121_env/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 631, in next data = self._next_data() File "/home/l1ydr1d/miniconda3/envs/medsam2_py310_torch2-3-1_cuda121_env/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1346, in _next_data return self._process_data(data) File "/home/l1ydr1d/miniconda3/envs/medsam2_py310_torch2-3-1_cuda121_env/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1372, in _process_data data.reraise() File "/home/l1ydr1d/miniconda3/envs/medsam2_py310_torch2-3-1_cuda121_env/lib/python3.10/site-packages/torch/_utils.py", line 705, in reraise raise exception KeyError: Caught KeyError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/l1ydr1d/miniconda3/envs/medsam2_py310_torch2-3-1_cuda121_env/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop data = fetcher.fetch(index) # type: ignore[possibly-undefined] File "/home/l1ydr1d/miniconda3/envs/medsam2_py310_torch2-3-1_cuda121_env/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/l1ydr1d/miniconda3/envs/medsam2_py310_torch2-3-1_cuda121_env/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/l1ydr1d/MedSAM2/MedSAM-MedSAM2/Awesome-Backbones/utils/dataloader.py", line 43, in getitem results = self.pipeline(copy.deepcopy(self.data_infos[index])) File "/home/l1ydr1d/MedSAM2/MedSAM-MedSAM2/Awesome-Backbones/core/datasets/compose.py", line 33, in call data = t(data) File "/home/l1ydr1d/MedSAM2/MedSAM-MedSAM2/Awesome-Backbones/core/datasets/transforms.py", line 764, in call self._resize_img(results) File "/home/l1ydr1d/MedSAM2/MedSAM-MedSAM2/Awesome-Backbones/core/datasets/transforms.py", line 726, in _resize_img img = results[key] KeyError: 'img'

the Train Pipline setting is:

train_pipeline = [

dict(type='LoadImageFromFile'),

dict(type='Resize', size=(256, 256), backend='pillow'),
dict(
    type='RandomResizedCrop',
    size=224,
    efficientnet_style=True,
    interpolation='bicubic',
    ),
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'),
dict(type='AutoAugment', policies=policies),
dict(type='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='ToTensor', keys=['gt_label']),
dict(type='Collect', keys=['img', 'gt_label'])

]

DC-hydrid commented 2 months ago

Sorry,I find the reasson. I edit the first setting in the Train Pipline "LoadFromFile". I comment it out because it shows that transformers has no attribute "LoadFromFile". At the first time I thought that maybe the code from torchvision import transformers are wrong. After read the source code, I have some new realize. But in fact, I still not have a comprehensive understand of the register part. T~T