Skip to content

Commit 3961154

Browse files
author
lijc08
committed
init
1 parent 01e5826 commit 3961154

File tree

8 files changed

+25
-10
lines changed

8 files changed

+25
-10
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
.idea
3+
*.so
4+
build

data/wider_voc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def __init__(self, root, preproc=None, target_transform=None):
8282
self.ids = list()
8383
with open(os.path.join(self.root, 'img_list.txt'), 'r') as f:
8484
self.ids = [tuple(line.split()) for line in f]
85+
# self.ids = self.ids[:128]
8586

8687
def __getitem__(self, index):
8788
img_id = self.ids[index]

layers/functions/__init__.py

Whitespace-only changes.

layers/functions/prior_box.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
import torch
23
from itertools import product as product
34
import numpy as np

layers/modules/multibox_loss.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
import torch
23
import torch.nn as nn
34
import torch.nn.functional as F

make.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ cd ./utils/
33

44
CUDA_PATH=/usr/local/cuda/
55

6-
python3 build.py build_ext --inplace
6+
python build.py build_ext --inplace
77

88
cd ..

train.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# coding=utf-8
12
from __future__ import print_function
23
import os
3-
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
4+
5+
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
46
import torch
57
import torch.optim as optim
68
import torch.backends.cudnn as cudnn
@@ -15,11 +17,11 @@
1517
from models.faceboxes import FaceBoxes
1618

1719
parser = argparse.ArgumentParser(description='FaceBoxes Training')
18-
parser.add_argument('--training_dataset', default='./data/WIDER_FACE', help='Training dataset directory')
20+
parser.add_argument('--training_dataset', default='~/datasets/widerface/WIDER_train', help='Training dataset directory')
1921
parser.add_argument('-b', '--batch_size', default=32, type=int, help='Batch size for training')
2022
parser.add_argument('--num_workers', default=8, type=int, help='Number of workers used in dataloading')
2123
parser.add_argument('--cuda', default=True, type=bool, help='Use cuda to train model')
22-
parser.add_argument('--ngpu', default=2, type=int, help='gpus')
24+
parser.add_argument('--ngpu', default=1, type=int, help='gpus')
2325
parser.add_argument('--lr', '--learning-rate', default=1e-3, type=float, help='initial learning rate')
2426
parser.add_argument('--momentum', default=0.9, type=float, help='momentum')
2527
parser.add_argument('--resume_net', default=None, help='resume net for retraining')
@@ -50,11 +52,12 @@
5052
state_dict = torch.load(args.resume_net)
5153
# create new OrderedDict that does not contain `module.`
5254
from collections import OrderedDict
55+
5356
new_state_dict = OrderedDict()
5457
for k, v in state_dict.items():
5558
head = k[:7]
5659
if head == 'module.':
57-
name = k[7:] # remove `module.`
60+
name = k[7:] # remove `module.`
5861
else:
5962
name = k
6063
new_state_dict[name] = v
@@ -82,9 +85,12 @@ def train():
8285
epoch = 0 + args.resume_epoch
8386
print('Loading Dataset...')
8487

88+
args.training_dataset = os.path.expanduser(args.training_dataset)
8589
dataset = VOCDetection(args.training_dataset, preproc(img_dim, rgb_means), AnnotationTransform())
8690

87-
epoch_size = math.ceil(len(dataset) / args.batch_size)
91+
print("len(dataset):", len(dataset))
92+
epoch_size = int(math.ceil(len(dataset) / args.batch_size))
93+
print("epoch_size:", epoch_size)
8894
max_iter = args.max_epoch * epoch_size
8995

9096
stepvalues = (200 * epoch_size, 250 * epoch_size)
@@ -119,7 +125,7 @@ def train():
119125

120126
# forward
121127
out = net(images)
122-
128+
123129
# backprop
124130
optimizer.zero_grad()
125131
loss_l, loss_c = criterion(out, priors, targets)
@@ -128,7 +134,7 @@ def train():
128134
optimizer.step()
129135
load_t1 = time.time()
130136
print('Epoch:' + repr(epoch) + ' || epochiter: ' + repr(iteration % epoch_size) + '/' + repr(epoch_size) +
131-
'|| Totel iter ' + repr(iteration) + ' || L: %.4f C: %.4f||' % (cfg['loc_weight']*loss_l.item(), loss_c.item()) +
137+
'|| Totel iter ' + repr(iteration) + ' || L: %.4f C: %.4f||' % (cfg['loc_weight'] * loss_l.item(), loss_c.item()) +
132138
'Batch time: %.4f sec. ||' % (load_t1 - load_t0) + 'LR: %.8f' % (lr))
133139

134140
torch.save(net.state_dict(), args.save_folder + 'Final_FaceBoxes.pth')
@@ -140,12 +146,13 @@ def adjust_learning_rate(optimizer, gamma, epoch, step_index, iteration, epoch_s
140146
# https://github.com/pytorch/examples/blob/master/imagenet/main.py
141147
"""
142148
if epoch < 0:
143-
lr = 1e-6 + (args.lr-1e-6) * iteration / (epoch_size * 5)
149+
lr = 1e-6 + (args.lr - 1e-6) * iteration / (epoch_size * 5)
144150
else:
145151
lr = args.lr * (gamma ** (step_index))
146152
for param_group in optimizer.param_groups:
147153
param_group['lr'] = lr
148154
return lr
149-
155+
156+
150157
if __name__ == '__main__':
151158
train()

utils/box_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
import torch
23
import numpy as np
34

0 commit comments

Comments
 (0)