This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
model_yolo_train_1x1.lua
104 lines (79 loc) · 2.37 KB
/
model_yolo_train_1x1.lua
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
--
-- Created by IntelliJ IDEA.
-- User: changqi
-- Date: 3/14/16
-- Time: 1:03 PM
-- To change this template use File | Settings | File Templates.
--
require 'nn'
require 'cunn'
local vgg = nn.Sequential();
-- building block
function Conv3(nInputPlane, nOutputPlane)
vgg:add(nn.SpatialConvolution(nInputPlane, nOutputPlane, 3, 3, 1, 1, 1, 1))
vgg:add(nn.SpatialBatchNormalization(nOutputPlane, 1e-3))
vgg:add(nn.LeakyReLU(0.1,true))
return vgg
end
function Conv1(nInputPlane, nOutputPlane)
vgg:add(nn.SpatialConvolution(nInputPlane, nOutputPlane, 1, 1, 1, 1, 0, 0))
vgg:add(nn.SpatialBatchNormalization(nOutputPlane, 1e-3))
vgg:add(nn.LeakyReLU(0.1,true))
return vgg
end
function Conv3WithMoreStride(nInputPlane, nOutputPlane)
vgg:add(nn.SpatialConvolution(nInputPlane, nOutputPlane, 3, 3, 2, 2, 1, 1))
vgg:add(nn.SpatialBatchNormalization(nOutputPlane, 1e-3))
vgg:add(nn.LeakyReLU(0.1,true))
return vgg
end
function ConvComplex(nInputPlane,nMidPlane, nOutputPlane)
Conv1(nInputPlane,nMidPlane)
Conv3(nMidPlane,nOutputPlane)
return vgg
end
local MaxPooling = nn.SpatialMaxPooling
--input: Bx1x448x448
vgg:add(nn.SpatialConvolution(1, 64, 7, 7, 2, 2, 3, 3))
vgg:add(nn.SpatialBatchNormalization(64, 1e-3))
vgg:add(nn.LeakyReLU(0.1,true))
-- Bx64x224x224
vgg:add(MaxPooling(2, 2, 2, 2):ceil());
vgg:add(nn.SpatialConvolution(64, 192, 3, 3, 1, 1, 1, 1))
vgg:add(nn.SpatialBatchNormalization(192, 1e-3))
vgg:add(nn.LeakyReLU(0.1,true))
-- Bx192x112x112
vgg:add(MaxPooling(2, 2, 2, 2):ceil());
-- Bx192x56x56
ConvComplex(192,128,256)
ConvComplex(256,256,512)
-- Bx512x56x56
vgg:add(MaxPooling(2, 2, 2, 2):ceil());
-- Bx512x28x28
ConvComplex(512,256,512)
ConvComplex(512,256,512)
ConvComplex(512,256,512)
ConvComplex(512,256,512)
ConvComplex(512,512,1024)
--Bx1024x28x28
vgg:add(MaxPooling(2, 2, 2, 2):ceil());
-- Bx1024x14x14
ConvComplex(1024,512,1024)
ConvComplex(1024,512,1024)
-- Bx1024x14x14
Conv3(1024,1024)
Conv3WithMoreStride(1024,1024)
-- Bx1024x7x7
Conv3(1024,1024)
Conv3(1024,1024)
vgg:add(nn.View(1024*7*7))
vgg:add(nn.Linear(1024*7*7,4096))
vgg:add(nn.BatchNormalization(4096))
vgg:add(nn.LeakyReLU(0.1,true))
vgg:add(nn.Dropout(0.5))
vgg:add(nn.Linear(4096,1*1*6))
-- check that we can propagate forward without errors
-- should get 2x(7*7*6) vector.
--print(vgg);
--print(vgg:cuda():forward(torch.CudaTensor(2,1,448,448)))
return vgg