Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

测试集处理 #52

Open
huisuli opened this issue Jun 6, 2023 · 4 comments
Open

测试集处理 #52

huisuli opened this issue Jun 6, 2023 · 4 comments

Comments

@huisuli
Copy link

huisuli commented Jun 6, 2023

在train.py中为什么加载数据这里val_pipeline = copy.deepcopy(train_pipeline) 测试集的处理需要复制训练集的处理,这样训练集每次都会随机裁剪尺寸,在evaluation.py里也是这样,
train_dataset = Mydataset(train_datas, train_pipeline)
val_pipeline = copy.deepcopy(train_pipeline)
val_dataset = Mydataset(val_datas, val_pipeline)
train_loader = DataLoader(train_dataset, shuffle=True, batch_size=data_cfg.get('batch_size'), num_workers=data_cfg.get('num_workers'),pin_memory=True, drop_last=True, collate_fn=collate)
val_loader = DataLoader(val_dataset, shuffle=False, batch_size=data_cfg.get('batch_size'), num_workers=data_cfg.get('num_workers'), pin_memory=True,
drop_last=True, collate_fn=collate)

@Fafa-DL
Copy link
Owner

Fafa-DL commented Jun 8, 2023

是的,当时官方也是这样做的。如果测试时固定大小我也有做过,精度会有一定下降。建议多次取均值,下一次更新考虑自主选择测试方法

@huisuli
Copy link
Author

huisuli commented Jun 8, 2023

那我也可以把测试集这部分加上标签,送进去训练和测试,这样也行吧?
val_pipeline = [
dict(type='LoadImageFromFile'),
dict(
type='CenterCrop',
crop_size=384,
efficientnet_style=True,
interpolation='bicubic'),
dict(type='Normalize', **img_norm_cfg),
dict(type='ImageToTensor', keys=['img']),
dict(type='ToTensor', keys=['gt_label']),
dict(type='Collect', keys=['img', 'gt_label'])
]

@MadMrFox
Copy link

测试时将训练参数设置不做任何增强和裁剪就可以稳定输出了,唯一的问题是,训练时进行了增强数据,测试时不做处理的结果会差很多。
以resnet50.py为例
原本的
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(
type='RandAugment',
policies=policies,
num_policies=2,
magnitude_level=12),
dict(
type='RandomResizedCrop',
size=224,
efficientnet_style=True,
interpolation='bicubic',
backend='pillow'),
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'),
dict(type='ColorJitter', brightness=0.4, contrast=0.4, saturation=0.4),
dict(type='Lighting', **img_lighting_cfg),
dict(
type='Normalize',
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
to_rgb=False),
dict(type='ImageToTensor', keys=['img']),
dict(type='ToTensor', keys=['gt_label']),
dict(type='Collect', keys=['img', 'gt_label'])
]
改为
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='Resize', size=224),
dict(
type='Normalize',
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
to_rgb=False),
dict(type='ImageToTensor', keys=['img']),
dict(type='ToTensor', keys=['gt_label']),
dict(type='Collect', keys=['img', 'gt_label'])
]

@Fafa-DL
Copy link
Owner

Fafa-DL commented Sep 6, 2024

已修复评估时结果不稳定问题,可拉取最新代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants