-
Notifications
You must be signed in to change notification settings - Fork 114
/
main.py
42 lines (28 loc) · 1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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):
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))
output = model(rgb_map.float().cuda())
loss = region_loss(output,target)
loss.backward()
optimizer.step()
if (epoch % 2 == 0):
torch.save(model, "ComplexYOLO_epoch"+str(epoch))