Exemple #1
0
def load_pointnet(model_path):
    model = Pointnet(num_classes=4, input_channels=72, use_xyz=False)
    if os.path.isfile(model_path):
        print("==> Loading from checkpoint '{}'".format(model_path))
        checkpoint = torch.load(model_path)
        epoch = checkpoint["epoch"]
        it = checkpoint.get("it", 0.0)
        best_prec = checkpoint["best_prec"]
        if model is not None and checkpoint["model_state"] is not None:
            model.load_state_dict(checkpoint["model_state"])
        print("==> Done")
    return model
Exemple #2
0
    test_set = Kitti3DSemSeg(args.num_points, train=False)
    test_loader = DataLoader(test_set,
                             batch_size=args.batch_size,
                             shuffle=True,
                             pin_memory=True,
                             num_workers=0)

    # train_set = Indoor3DSemSeg(args.num_points)
    train_set = Kitti3DSemSeg(args.num_points)
    train_loader = DataLoader(train_set,
                              batch_size=args.batch_size,
                              pin_memory=True,
                              num_workers=0,
                              shuffle=True)

    model = Pointnet(num_classes=34, input_channels=6, use_xyz=True)
    # 设置设备
    device_name = "cpu"
    if torch.cuda.is_available():
        device_name = "cuda"
        torch.backends.cudnn.deterministic = True
        torch.cuda.manual_seed(0)

    device = torch.device(device_name)
    print(device)
    model.cuda()
    optimizer = optim.Adam(model.parameters(),
                           lr=args.lr,
                           weight_decay=args.weight_decay)

    lr_lbmd = lambda it: max(
        batch_size=args.batch_size,
        shuffle=True,
        num_workers=4,
        pin_memory=True,
    )

    train_set = ModelNet40Cls(args.num_points, transforms=train_transforms)
    train_loader = DataLoader(
        train_set,
        batch_size=args.batch_size,
        shuffle=True,
        num_workers=4,
        pin_memory=True,
    )

    model = Pointnet(input_channels=0, num_classes=40, use_xyz=True)
    model.cuda()

    optimizer = optim.Adam(model.parameters(),
                           lr=args.lr,
                           weight_decay=args.weight_decay)
    lr_lbmd = lambda it: max(
        args.lr_decay**(int(it * args.batch_size / args.decay_step)),
        lr_clip / args.lr,
    )
    bn_lbmd = lambda it: max(
        args.bn_momentum * args.bnm_decay**
        (int(it * args.batch_size / args.decay_step)),
        bnm_clip,
    )
Exemple #4
0
    train_dataset = TripletFaceDataset(root='',
                                       n_triplets=args.num_triplet,
                                       n_points=args.num_points,
                                       class_nums=500,
                                       transforms=None,
                                       extensions='bcnc')

    train_loader = DataLoader(
        train_dataset,
        batch_size=args.batch_size,
        shuffle=True,
        num_workers=4,
        pin_memory=True,
    )

    model = Pointnet(input_channels=3, use_xyz=True)
    model.cuda()
    # 512 is dimension of feature
    classifier = {
        'MCP': layer.MarginCosineProduct(512, args.num_class).cuda(),
        'AL': layer.AngleLinear(512, args.num_class).cuda(),
        'L': torch.nn.Linear(512, args.num_class, bias=False).cuda()
    }[args.classifier_type]

    criterion = nn.TripletMarginLoss(margin=0.5, p=2)
    optimizer = optim.Adam([{
        'params': model.parameters()
    }, {
        'params': classifier.parameters()
    }],
                           lr=lr,
    test_sampler = SubsetRandomSampler(val_indices)
    test_loader = DataLoader(dataset,
                             batch_size=args.batch_size,
                             shuffle=False,
                             pin_memory=True,
                             num_workers=4,
                             sampler=test_sampler)

    train_loader = DataLoader(dataset,
                              batch_size=args.batch_size,
                              shuffle=False,
                              pin_memory=True,
                              num_workers=4,
                              sampler=train_sampler)

    model = Pointnet(input_channels=1, num_classes=8, use_xyz=True)
    model.cuda()
    optimizer = optim.Adam(model.parameters(),
                           lr=args.lr,
                           weight_decay=args.weight_decay)

    def lr_lbmd(it):
        return max(
            args.lr_decay**(int(it * args.batch_size / args.decay_step)),
            lr_clip / args.lr,
        )

    def bn_lbmd(it):
        return max(
            args.bn_momentum *
            args.bnm_decay**(int(it * args.batch_size / args.decay_step)),
Exemple #6
0
        shuffle=True,
        num_workers=2,
        pin_memory=True,
    )

    train_set = ModelNet40Cls(args.num_points, transforms=transforms)
    train_loader = DataLoader(
        train_set,
        batch_size=args.batch_size,
        shuffle=True,
        num_workers=2,
        pin_memory=True,
    )

    model = Pointnet(input_channels=0,
                     num_classes=40,
                     use_xyz=False,
                     type_r=args.typer)
    model.cuda()
    optimizer = optim.Adam(model.parameters(),
                           lr=args.lr,
                           weight_decay=args.weight_decay)
    lr_lbmd = lambda it: max(
        args.lr_decay**(int(it * args.batch_size / args.decay_step)),
        lr_clip / args.lr,
    )
    bn_lbmd = lambda it: max(
        args.bn_momentum * args.bnm_decay**
        (int(it * args.batch_size / args.decay_step)),
        bnm_clip,
    )
Exemple #7
0
        batch_size=args.batch_size,
        pin_memory=True,
        num_workers=2,
        shuffle=True,
    )

    train_set = Indoor3DSemSeg(args.num_points,use_colour=args.colours,split="train")
    train_loader = DataLoader(
        train_set,
        batch_size=args.batch_size,
        pin_memory=True,
        num_workers=2,
        shuffle=True,
    )
    if args.colours:
        model = Pointnet(num_classes=27, input_channels=7, use_xyz=True)
    else:
        model = Pointnet(num_classes=27, input_channels=3, use_xyz=True)
    model.cuda()
    optimizer = optim.Adam(
        model.parameters(), lr=args.lr, weight_decay=args.weight_decay
    )

    lr_lbmd = lambda it: max(
        args.lr_decay ** (int(it * args.batch_size / args.decay_step)),
        lr_clip / args.lr,
    )
    bnm_lmbd = lambda it: max(
        args.bn_momentum
        * args.bn_decay ** (int(it * args.batch_size / args.decay_step)),
        bnm_clip,
Exemple #8
0
        batch_size=4096,
        shuffle=True,
        pin_memory=True,
        num_workers=2,
    )

    train_set = RadarLowLvlSemSeg(args.num_points, train_rat=0.6)
    train_loader = DataLoader(
        train_set,
        batch_size=args.batch_size,
        pin_memory=True,
        num_workers=2,
        shuffle=True,
    )

    model = Pointnet(num_classes=4, input_channels=72, use_xyz=False)
    model.cuda()
    optimizer = optim.Adam(model.parameters(),
                           lr=args.lr,
                           weight_decay=args.weight_decay)

    lr_lbmd = lambda it: max(
        args.lr_decay**(int(it * args.batch_size / args.decay_step)),
        lr_clip / args.lr,
    )
    bnm_lmbd = lambda it: max(
        args.bn_momentum * args.bn_decay**
        (int(it * args.batch_size / args.decay_step)),
        bnm_clip,
    )
                              shuffle=True,
                              num_workers=2,
                              pin_memory=True,
                              drop_last=True)

    val_loader = DataLoader(val_set,
                            batch_size=args.batch_size,
                            shuffle=False,
                            num_workers=2,
                            pin_memory=True,
                            drop_last=False)

    # model
    device = torch.device("cuda" if args.cuda else "cpu")
    model = Pointnet(input_channels=args.input_plane,
                     num_classes=args.output_plane,
                     use_xyz=True)
    model.to(device)
    model = nn.DataParallel(model)
    print("Let's use", torch.cuda.device_count(), "GPUs!")

    # optimizer
    optimizer = optim.Adam(model.parameters(),
                           lr=args.lr,
                           weight_decay=args.weight_decay)

    # scheduler
    lr_lbmd = lambda it: max(
        args.lr_decay**(int(it * args.batch_size / args.decay_step)),
        lr_clip / args.lr,
    )
Exemple #10
0
    division,
    absolute_import,
    with_statement,
    print_function,
    unicode_literals,
)
import numpy as np
import time
import glob
import torch
import torch.optim as optim
import torch.optim.lr_scheduler as lr_sched
import torch.nn as nn
from torch.utils.data import DataLoader
from torchvision import transforms
import etw_pytorch_utils as pt_utils
import pprint
import os.path as osp
import os, sys
import argparse

sys.path.append('../..')
from pointnet2.models import Pointnet2ClsMSG as Pointnet
from pointnet2.models.pointnet2_msg_cls import model_fn_decorator
from pointnet2.data import ScanNet
import pointnet2.data.data_utils as d_utils

if __name__ == "__main__":
    # model
    model = Pointnet(input_channels=3, num_classes=21, use_xyz=True)
    print('#parameters %d' % sum([x.nelement() for x in model.parameters()]))
        batch_size=args.batch_size,
        shuffle=True,
        pin_memory=True,
        num_workers=2,
    )
    print("Loaded Test Set")
    train_set = Indoor3DSemSeg(args.num_points)
    train_loader = DataLoader(
        train_set,
        batch_size=args.batch_size,
        pin_memory=True,
        num_workers=2,
        shuffle=True,
    )
    print("Loaded Train Set")
    model = Pointnet(num_classes=21, input_channels=0, use_xyz=True)
    model.cuda()
    print("Initialized Model")
    optimizer = optim.Adam(model.parameters(),
                           lr=args.lr,
                           weight_decay=args.weight_decay)

    lr_lbmd = lambda it: max(
        args.lr_decay**(int(it * args.batch_size / args.decay_step)),
        lr_clip / args.lr,
    )
    bnm_lmbd = lambda it: max(
        args.bn_momentum * args.bn_decay**
        (int(it * args.batch_size / args.decay_step)),
        bnm_clip,
    )
gpu_index = paras.gpu
os.environ["CUDA_VISIBLE_DEVICES"] = gpu_index
lr_clip = 1e-5
bnm_clip = 1e-2

if __name__ == "__main__":
    args = parser.parse_args()

    test_set = Indoor3DSemSeg(args.num_points, train=False)
    test_loader = DataLoader(test_set,
                             batch_size=args.batch_size,
                             shuffle=False,
                             pin_memory=True,
                             num_workers=2)

    model = Pointnet(3, input_channels=6).cuda()
    model.load_state_dict(
        torch.load(
            '/home1/xuhui/Pointnet2_PyTorch-master/pointnet2/train/checkpoints/poitnet2_semseg_best.pth.tar'
        )['model_state'])
    model.eval()

    # for i, data in tqdm.tqdm(enumerate(test_loader, 0), total=len(test_loader),
    #                              leave=False, desc='val'):
    for i, data in enumerate(test_loader):
        f = open(os.path.join(preds_path, str(i).zfill(2) + '.txt'), 'w')
        inputs, labels = data
        inputs = inputs.to('cuda', non_blocking=True)
        labels = labels.to('cuda', non_blocking=True)
        # print(labels)
        preds = model(inputs)