示例#1
0
def main(train_args):

    trainset = "/mnt/iusers01/eee01/mchiwml4/CamVid/train"
    validset = "/mnt/iusers01/eee01/mchiwml4/CamVid/val"

    transform = transforms.Compose(
        [transforms.ToTensor(),
         transforms.Normalize(mean, std)])

    train_joint_transform = jointtransform.Compose(
        [jointtransform.RandomHorizontallyFlip()])

    train_dataset = DataLoader(Loaddata(trainset,
                                        transform=transform,
                                        target_transform=MaskToTensor(),
                                        joint_transform=train_joint_transform),
                               batch_size=train_args.batch_size,
                               shuffle=True,
                               num_workers=8)
    valid_dataset = DataLoader(Loaddata(validset,
                                        transform=transform,
                                        target_transform=MaskToTensor()),
                               batch_size=1,
                               shuffle=True,
                               num_workers=8)

    label_num = 11
    model = ducmodel.ResNetDUCHDC(label_num)

    model = model.cuda()
    weight = torch.Tensor(class_weight).cuda()

    criterion = CrossEntropyLoss2d(weight=weight).cuda()

    lr_ = train_args.lr
    optimizer = optim.SGD([{
        'params': get_1x_lr_params(model),
        'lr': lr_
    }, {
        'params': get_10x_lr_params(model),
        'lr': lr_ * 10
    }],
                          momentum=train_args.momentum,
                          weight_decay=train_args.weight_decay)

    #    optimizer.param_groups[0]['lr'] = lr_
    #    optimizer.param_groups[1]['lr'] = lr_*10

    if train_args.load_param is not None:
        model.load_state_dict(torch.load(train_args.load_param))
    if train_args.load_optim is not None:
        optimizer.load_state_dict(torch.load(train_args.load_optim))

    max_epochs = train_args.epoch_num
    savefolder = train_args.save_folder
    train_model(model, criterion, optimizer, lr_, max_epochs, train_dataset,
                valid_dataset, savefolder)
示例#2
0
def main(train_args):

    path = "/mnt/iusers01/eee01/mchiwml4/dataset/cityscapes/"

    transform = transforms.Compose([transforms.Normalize(mean, std)])

    train_joint_transform = jointtransform.Compose([
        jointtransform.Resize((1024, 512)),
        jointtransform.RandomHorizontallyFlip(),
        jointtransform.ToTensor()
    ])

    val_joint_transform = jointtransform.Compose([jointtransform.ToTensor()])

    train_dataset = DataLoader(Loaddata(path,
                                        split="train",
                                        transform=transform,
                                        joint_transform=train_joint_transform),
                               batch_size=1,
                               shuffle=True,
                               num_workers=4)
    valid_dataset = DataLoader(Loaddata(path,
                                        split="val",
                                        transform=transform,
                                        joint_transform=val_joint_transform),
                               batch_size=1,
                               shuffle=False,
                               num_workers=4)

    label_num = 19
    model = deeplab_v2.Deeplab_Resnet(label_num)
    model = model.cuda()

    weight = torch.Tensor(class_weight).cuda()

    criterion = CrossEntropyLoss2d(weight=weight).cuda()

    lr_ = train_args.lr
    optimizer = optim.SGD([{
        'params': get_1x_lr_params(model),
        'lr': lr_
    }, {
        'params': get_10x_lr_params(model),
        'lr': lr_
    }],
                          momentum=train_args.momentum,
                          weight_decay=train_args.weight_decay)

    if train_args.load_param is not None:
        model.load_state_dict(torch.load(train_args.load_param))
    if train_args.load_optim is not None:
        optimizer.load_state_dict(torch.load(train_args.load_optim))

    max_epochs = train_args.epoch_num

    train_model(model, criterion, optimizer, lr_, max_epochs, train_dataset,
                valid_dataset)
示例#3
0
def main(train_args):

    trainset = "/mnt/iusers01/eee01/mchiwml4/CamVid/train"
    validset = "/mnt/iusers01/eee01/mchiwml4/CamVid/val"

    transform = transforms.Compose(
        [transforms.ToTensor(),
         transforms.Normalize(mean, std)])

    train_joint_transform = jointtransform.Compose(
        [jointtransform.RandomHorizontallyFlip()])

    train_dataset = DataLoader(Loaddata(trainset,
                                        transform=transform,
                                        target_transform=MaskToTensor(),
                                        joint_transform=train_joint_transform),
                               batch_size=train_args.batch_size,
                               shuffle=True,
                               num_workers=8)
    valid_dataset = DataLoader(Loaddata(validset,
                                        transform=transform,
                                        target_transform=MaskToTensor()),
                               batch_size=1,
                               shuffle=True,
                               num_workers=8)

    label_num = 11
    model = linknetmodel.linknet(label_num)

    model = model.cuda()

    weight = torch.Tensor(class_weight).cuda()

    criterion = CrossEntropyLoss2d(weight=weight).cuda()

    lr_ = train_args.lr
    optimizer = optim.RMSprop(model.parameters(),
                              lr=lr_,
                              momentum=train_args.momentum,
                              weight_decay=train_args.weight_decay)

    if train_args.load_param is not None:
        model.load_state_dict(torch.load(train_args.load_param))
    if train_args.load_optim is not None:
        optimizer.load_state_dict(torch.load(train_args.load_optim))

    max_epochs = train_args.epoch_num

    train_model(model, criterion, optimizer, lr_, max_epochs, train_dataset,
                valid_dataset)
示例#4
0
from utils import check_mkdir
import os
import datetime
from tensorboardX import SummaryWriter


trainset="/mnt/iusers01/eee01/mchiwml4/CamVid/train"
validset="/mnt/iusers01/eee01/mchiwml4/CamVid/val"
testset="/mnt/iusers01/eee01/mchiwml4/CamVid/test"
transform = transforms.Compose([
                transforms.ToTensor(), 
                transforms.Normalize(mean, std)
                ])
    
train_joint_transform = jointtransform.Compose([
    jointtransform.RandomHorizontallyFlip()
])

train_dataset = DataLoader(
        Loaddata(trainset, transform=transform, target_transform=MaskToTensor(), joint_transform=train_joint_transform),
        batch_size=4, shuffle=True, num_workers=8)
valid_dataset = DataLoader(
        Loaddata(validset, transform=transform, target_transform=MaskToTensor()),
        batch_size=1, shuffle=True, num_workers=8)


train_size = len(Loaddata(trainset))
valid_size = len(Loaddata(validset))

def get_1x_lr_params(model):
    b = []