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

预训练模型用于分割任务 #46

Open
chenyuabc10 opened this issue Dec 16, 2024 · 6 comments
Open

预训练模型用于分割任务 #46

chenyuabc10 opened this issue Dec 16, 2024 · 6 comments

Comments

@chenyuabc10
Copy link

作者您好,想向您请教下您是如何从预训练的ViT-B或ViTAE-B主干权重得到的分割任务中ViT-B + RVSA这里的权重呢,这一步的代码在哪里?也就是说如果我直接使用您的ViT-B或ViTAE-B预训练权重要怎样处理才能得到能用于mmsegmentation里pretrained=字段能够使用的权重呢?期望您的回复,感谢🙏。

@DotWang
Copy link
Collaborator

DotWang commented Dec 16, 2024

@chenyuabc10 readme提供的ViT/ViTAE预训练权重不包含RVSA,模型结构代码完成了RVSA的替换,即就是微调时候模型的结构,所以做法就是预训练完成后,将ViT的权重加载到包含RVSA结构的网络中,在不同任务上进行微调

你说的是pretrained=字段能够使用的权重就是"ViT-B或ViTAE-B的预训练权重"

@chenyuabc10
Copy link
Author

您好,我还有一个问题,我在使用MAE方法预训练模型时,我将txt文件设置为如下格式:
train_labels_100.txt:
P0002186.jpg
P0297250.jpg
P0825073.jpg
P0899704.jpg
P0768497.jpg
遇到报错:
ValueError: not enough values to unpack (expected 3, got 1)
使用的启动命令如下:
python -m torch.distributed.launch --nproc_per_node 8 --master_port 10000 main_pretrain.py --dataset 'millionAID' --model 'mae_vit_base_patch16' --batch_size 256 --epochs 1600 --warmup_epochs 40 --input_size 224 --mask_ratio 0.75 --blr 1.5e-4 --weight_decay 0.05 --gpu_num 8 --output_dir '../mae-main/output/'
MAE无监督方法也需要标签吗?还是说随便加一些标签只需要满足3个value的格式即可,训练时不会用到?期望您的回复,十分感谢!

@DotWang
Copy link
Collaborator

DotWang commented Dec 24, 2024

@chenyuabc10 无监督不需要标签,你只要读文件名就行

@chenyuabc10
Copy link
Author

@DotWang 是这里只要读fname吗?把关于target的内容都删掉吗?或者我为图片随意添加标签凑够三个value可以吗?训练时不会用到标签的话?
class MillionAIDDataset(data.Dataset):
def init(self, root, train=True, transform=None, tag=100):

    print(os.getcwd())

    with open(os.path.join(root, 'train_labels_{}.txt'.format(tag)), mode='r') as f:
        train_infos = f.readlines()
    f.close()

    trn_files = []
    trn_targets = []

    for item in train_infos:
        fname, _, idx = item.strip().split()
        trn_files.append(os.path.join(root + '/all_img', fname))
        trn_targets.append(int(idx))

    with open(os.path.join(root, 'valid_labels.txt'), mode='r') as f:
        valid_infos = f.readlines()
    f.close()

    val_files = []
    val_targets = []

    for item in valid_infos:
        fname, _, idx = item.strip().split()
        val_files.append(os.path.join(root + '/all_img', fname))
        val_targets.append(int(idx))

    if train:
        self.files = trn_files
        self.targets = trn_targets
    else:
        self.files = val_files
        self.targets = val_targets

    self.transform = transform

    print('Creating MillionAID dataset with {} examples'.format(len(self.targets)))

def __len__(self):
    return len(self.targets)

def __getitem__(self, i):
    img_path = self.files[i]

    img = Image.open(img_path)

    #if self.transform != None:

    img = self.transform(img)

    return img, self.targets[i]

@DotWang
Copy link
Collaborator

DotWang commented Dec 25, 2024

@chenyuabc10 是,跟target没关系

你看engine_pretrain.py,第39行:

for data_iter_step, (samples, _) in enumerate(metric_logger.log_every(data_loader, print_freq, header)):

要是你删掉target的部分,其他代码就相应改了

@chenyuabc10
Copy link
Author

好的明白,感谢您的耐心回答

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

2 participants