def buildDataset(self, phase): self.dataset = KittiDataset(root_dir=self.data_dir, class_list=self.class_list, boundary=self.boundary, split=self.split) if phase == 'val': self.dataset.toggleVal()
import torch import torch.nn as nn import torch.optim as optim import torch.utils.data as data import numpy as np import visdom viz = visdom.Visdom(env='loss') from complexYOLO import ComplexYOLO from kitti import KittiDataset from region_loss import RegionLoss batch_size = 4 # dataset dataset = KittiDataset(root='/home/ding/Documents/deeplearning/kitti', set='train') data_loader = data.DataLoader(dataset, batch_size, shuffle=True, pin_memory=False) model = ComplexYOLO() model.cuda() # define optimizer optimizer = optim.SGD(model.parameters(), lr=1e-5, momentum=0.9, weight_decay=0.0005)
# from loss2 import RegionLoss from tensorboardX import SummaryWriter from eval import draw_image_train from config import cfg import os os.environ['CUDA_VISIBLE_DEVICES'] = '0' writer = SummaryWriter() batch_size = 8 data_dir = cfg.DATA_DIR # dataset dataset = KittiDataset(root=data_dir, set='train') data_loader = data.DataLoader(dataset, batch_size, shuffle=True, pin_memory=False) # val data val_set = KittiDataset(root=data_dir, set='val') val_loader = data.DataLoader(val_set, batch_size, shuffle=True, pin_memory=False) # model = DataParallel(ComplexYOLO()) # model = ComplexYOLO() model = torch.load('ComplexYOLO_epoch%s' % 130)
date_str = str(datetime.date.today()) logging_file = 'training_log_' + date_str + '.log' logging.basicConfig(filename=logging_file, level=logging.DEBUG, format='%(asctime)s %(message)s') batch_size = 12 # Remove old loggings in the tensorboard folder ts_dir = './logs' for ts_file in os.listdir(ts_dir): ts_path = os.path.join(ts_dir, ts_file) os.unlink(ts_path) # dataset dataset = KittiDataset(root='/home/yd2466/Complex-YOLO/data', set='train') data_loader = data.DataLoader(dataset, batch_size, shuffle=True, pin_memory=False) model = ComplexYOLO() model.cuda() # define optimizer optimizer = optim.SGD(model.parameters(), lr=1e-5, momentum=0.9, weight_decay=0.0005) # define the number of epochs
import torch import torch.nn as nn import torch.optim as optim import torch.utils.data as data import numpy as np from complexYOLO import ComplexYOLO from kitti import KittiDataset from region_loss import RegionLoss batch_size=12 # dataset dataset=KittiDataset(root='/home/ai/KITTI',set='train') data_loader = data.DataLoader(dataset, batch_size, shuffle=True) model = ComplexYOLO() model.cuda() # define optimizer optimizer = optim.Adam(model.parameters()) # define loss function region_loss = RegionLoss(num_classes=8, num_anchors=5) for epoch in range(200): for batch_idx, (rgb_map, target) in enumerate(data_loader):
import torch import torch.nn as nn import torch.optim as optim import torch.utils.data as data import numpy as np from complexYOLO import ComplexYOLO from kitti import KittiDataset from region_loss import RegionLoss batch_size = 12 # dataset dataset = KittiDataset(root='/home/yuliu/KITTI', set='train') data_loader = data.DataLoader(dataset, batch_size, shuffle=True, pin_memory=False) model = ComplexYOLO() model.cuda() # define optimizer optimizer = optim.SGD(model.parameters(), lr=1e-5, momentum=0.9, weight_decay=0.0005) # define loss function region_loss = RegionLoss(num_classes=8, num_anchors=5)
logging_file = 'training_log_' + date_str + '.log' logging.basicConfig(filename=logging_file, level=logging.DEBUG, format='%(asctime)s %(message)s') # Remove old loggings in the tensorboard folder ts_dir = './logs' for ts_file in os.listdir(ts_dir): ts_path = os.path.join(ts_dir, ts_file) os.unlink(ts_path) dirname = os.path.dirname(__file__) # Construct training dataset train_data_path = os.path.join(dirname, 'data') dataset = KittiDataset(root=train_data_path, set='train') data_loader = data.DataLoader(dataset, batch_size, shuffle=True, pin_memory=False) # Initialize a model model = ComplexYOLO() model.cuda() # Define optimizer optimizer = optim.SGD(model.parameters(), lr=lr, momentum=momentum, weight_decay=weight_decay)
import torch import torch.nn as nn import torch.optim as optim import torch.utils.data as data import numpy as np from complexYOLO import ComplexYOLO from kitti import KittiDataset from region_loss import RegionLoss batch_size = 12 # dataset dataset = KittiDataset(root='./', set='train') data_loader = data.DataLoader(dataset, batch_size, shuffle=True) model = ComplexYOLO() model.cuda() # define optimizer optimizer = optim.Adam(model.parameters(), lr=0.001) # define loss function region_loss = RegionLoss(num_classes=8, num_anchors=5) for epoch in range(20): for batch_idx, (rgb_map, target) in enumerate(data_loader): optimizer.zero_grad() rgb_map = rgb_map.view(rgb_map.data.size(0), rgb_map.data.size(3),
""" @description:这是测试输出中间层特征得例子 """ import torch from kitti import KittiDataset import torch.utils.data as data import scipy.misc as misc batch_size = 12 model = torch.load('ComplexYOLO_epoch%s' % 130) model.cuda() print(model) # dataset dataset = KittiDataset(root='/home/yxk/data/Kitti/object', set='train') data_loader = data.DataLoader(dataset, batch_size, num_workers=6, shuffle=True, pin_memory=False) for batch_idx, (rgb_map, target) in enumerate(data_loader): rgb_map = rgb_map.view(rgb_map.data.size(0), rgb_map.data.size(3), rgb_map.data.size(1), rgb_map.data.size(2)) x = rgb_map.float().cuda() for name, module in model._modules.items(): x = module(x) print(x.shape) model = torch.load('ComplexYOLO_epoch%s' % 70)
import torch.nn as nn import torch.optim as optim import torch.utils.data as data import numpy as np from complexYOLO import ComplexYOLO from kitti import KittiDataset from region_loss import RegionLoss import os os.environ["CUDA_VISIBLE_DEVICES"] = "0" batch_size = 12 # dataset dataset = KittiDataset(root='/home/Documents/training/training/', set='train') data_loader = data.DataLoader(dataset, batch_size, shuffle=True) model = ComplexYOLO() model.cuda() # define optimizer optimizer = optim.Adam(model.parameters()) # define loss function region_loss = RegionLoss(num_classes=8, num_anchors=5) for epoch in range(400): for batch_idx, (rgb_map, target) in enumerate(data_loader): optimizer.zero_grad()
class Solver(): def __init__(self, args): self.data_dir = args.data_dir self.log = args.do_log self.split = args.split self.epochs = args.epochs self.batch_size = args.batch_size self.lr = args.lr self.momentum = args.momentum self.weight_decay = args.weight_decay with open('config.json', 'r') as f: config = json.load(f) self.boundary = config["boundary"] self.class_list = config["class_list"] self.anchors = config["anchors"] self.num_anchors = len(self.anchors) // 2 self.num_classes = len(self.class_list) + 1 self.save_dir = args.save_dir self.device = torch.device( 'cuda' if torch.cuda.is_available() else 'cpu') self.buildModel() def buildModel(self): self.model = ComplexYOLO() self.model.to(self.device) def buildDataset(self, phase): self.dataset = KittiDataset(root_dir=self.data_dir, class_list=self.class_list, boundary=self.boundary, split=self.split) if phase == 'val': self.dataset.toggleVal() def buildLogger(self): pass def train(self): self.buildDataset('train') opt = optim.SGD(self.model.parameters(), lr=self.lr) region_loss = RegionLoss(num_classes=self.num_classes, num_anchors=self.num_anchors) region_loss = region_loss.to(self.device) # Dataloader data_loader = DataLoader(self.dataset, self.batch_size, shuffle=True, pin_memory=False) log_step = 10 best_loss = 10000 self.model.train() for epoch in range(self.epochs): running_loss = 0 running_nCorrect = 0 running_nGT = 0 for idx, data in enumerate(data_loader): # pdb.set_trace() rgb_map = data[0] target = data[1] rgb_map = rgb_map.float().to(self.device) output = self.model(rgb_map) loss, nCorrect, nGT = region_loss(output, target) loss.backward() running_loss += loss.item() running_nCorrect += nGT running_nCorrect += nCorrect if idx % log_step == 0: mean_loss = running_loss / log_step print("Epoch: {}, Loss: {m:=5.4f}".format(epoch, m=mean_loss)) print("nCorrect = {m:=5.4f}, nGT = {p:=5.4f}".format( m=running_nCorrect / log_step, p=running_nGT / log_step)) if mean_loss < best_loss: best_loss = mean_loss path = os.path.join( self.save_dir, 'ep-{}-{m:=5.4f}.pth'.format(epoch, m=mean_loss)) torch.save(self.model.state_dict(), path) print("Saved model for {} epoch\n".format(epoch)) running_loss = 0 running_nCorrect = 0 running_nGT = 0 opt.step() def test(self): pass
from config import cfg from threading import Thread from kitti import KittiDataset from visualization import vis_points from load_points import load_kitti_velodyne, get_filtered_lidar, kitti_velo_to_cam dataset = KittiDataset(cfg) index = dataset._load_index() print(len(index), type(index)) print(index) print(dataset.label_path_at(5)) print(dataset.lidar_path_at(5)) print(dataset.image_path_at(5)) print(dataset.calib_path_at(5)) origin = load_kitti_velodyne(dataset.lidar_path_at(5)) crop = get_filtered_lidar(origin) # vis_mayavi(origin) xyzi = kitti_velo_to_cam(origin, dataset.calib_path_at(5)) vis_points(xyzi)
format='%(asctime)s %(message)s') # Remove old loggings in the tensorboard folder # ts_dir = './logs' # for ts_file in os.listdir(ts_dir): # ts_path = os.path.join(ts_dir, ts_file) # os.unlink(ts_path) dirname = os.path.dirname(__file__) # Construct training dataset with open('config.json', 'r') as f: config = json.load(f) train_data_path = os.path.join(dirname, 'data') dataset = KittiDataset(root_dir=args.data_dir, class_list=config["class_list"], boundary=config["boundary"], set='lidar') data_loader = data.DataLoader(dataset, batch_size, shuffle=True, pin_memory=False) # Initialize a model model = ComplexYOLO() model.cuda() # Define optimizer optimizer = optim.SGD(model.parameters(), lr=lr, momentum=momentum, weight_decay=weight_decay)