Beispiel #1
0
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)

# define loss function
region_loss = RegionLoss(num_classes=8, num_anchors=5)

lossList = []
totalLossList = []
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),
                               rgb_map.data.size(1), rgb_map.data.size(2))
Beispiel #3
0
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
epochs = range(1000)

# Define the loss function
region_loss = RegionLoss(num_classes = 8, num_anchors = 5)
loss_history = np.zeros((len(epochs), int(len(data_loader.dataset) / batch_size), 8))

for epoch in epochs:
   logging.info('Running epoch = %d' % epoch)
        loss_l = self.coord_scale * nn.MSELoss(reduction='sum')(l*coord_mask, tl*coord_mask)/2.0
        loss_im = self.coord_scale * nn.MSELoss(reduction='sum')(im*coord_mask, tim*coord_mask)/2.0
        loss_re = self.coord_scale * nn.MSELoss(reduction='sum')(re*coord_mask, tre*coord_mask)/2.0
        loss_Euler = loss_im + loss_re
        loss_conf = nn.MSELoss(reduction='sum')(conf*conf_mask, tconf*conf_mask)    # 只有这个有争议   判断有没有物体

        loss_cls = self.class_scale * nn.CrossEntropyLoss(reduction='sum')(cls, tcls)
        loss = loss_x + loss_y + loss_w + loss_l + loss_conf + loss_cls + loss_Euler
        t4 = time.time()

        if False:
            print('-----------------------------------')
            print('        activation : %f' % (t1 - t0))
            print(' create pred_boxes : %f' % (t2 - t1))
            print('     build targets : %f' % (t3 - t2))
            print('       create loss : %f' % (t4 - t3))
            print('             total : %f' % (t4 - t0))
        print('nGT %d, recall %d, proposals %d, loss: x %f, y %f, w %f, h %f, conf %f, cls %f, Euler %f, total %f' % (nGT, nCorrect, nProposals, loss_x.data, loss_y.data, loss_w.data, loss_l.data, loss_conf.data, loss_cls.data,loss_Euler.data ,loss.data))
        return loss, loss_x, loss_y, loss_w, loss_l, loss_im, loss_re, loss_Euler, loss_conf, loss_cls


if __name__ == '__main__':
    pc = np.random.randn(12, 3, 512, 1024)
    pc = torch.from_numpy(pc)
    model = ComplexYOLO()
    output = model(pc)
    # target = torch.FloatTensor(50, 7)
    # region_loss = RegionLoss(num_classes=8, num_anchors=5)
    # loss, loss_x, loss_y, loss_w, loss_l, loss_im, loss_re, loss_Euler, loss_conf, loss_cls = region_loss(output, target)