-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnet64.lua
142 lines (134 loc) · 4.96 KB
/
net64.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require 'voxlayers'
-- Generator
local netG = nn.Sequential()
-- 200x1x1x1 -> 512x4x4x4
--netG:add(nn.VolumetricDropout(0.2))
netG:add(nn.VolumetricFullConvolution(200,512,4,4,4))
netG:add(nn.VolumetricBatchNormalization(512))
netG:add(nn.ReLU())
-- 512x4x4x4 -> 256x8x8x8
--netG:add(nn.VolumetricDropout(0.5))
netG:add(nn.VolumetricFullConvolution(512,256,4,4,4,2,2,2,1,1,1))
netG:add(nn.VolumetricBatchNormalization(256))
netG:add(nn.ReLU())
-- 256x8x8x8 -> 128x16x16x16
--netG:add(nn.VolumetricDropout(0.5))
netG:add(nn.VolumetricFullConvolution(256,128,4,4,4,2,2,2,1,1,1))
netG:add(nn.VolumetricBatchNormalization(128))
netG:add(nn.ReLU())
-- 128x16x16x16 -> 64x32x32x32
--netG:add(nn.VolumetricDropout(0.5))
netG:add(nn.VolumetricFullConvolution(128,64,4,4,4,2,2,2,1,1,1))
netG:add(nn.VolumetricBatchNormalization(64))
netG:add(nn.ReLU())
-- 64x32x32x32 -> 1x64x64x64
netG:add(nn.VolumetricFullConvolution(64,1,4,4,4,2,2,2,1,1,1))
netG:add(nn.Sigmoid())
-- Discriminator (same as Generator but uses LeakyReLU)
local netD = nn.Sequential()
-- 1x64x64x64 -> 64x32x32x32
netD:add(nn.VolumetricConvolution(1,64,4,4,4,2,2,2,1,1,1))
netD:add(nn.VolumetricBatchNormalization(64))
netD:add(nn.LeakyReLU(opt.leakyslope, true))
-- 64x32x32x32 -> 128x16x16x16
netD:add(nn.VolumetricDropout(0.5))
netD:add(nn.VolumetricConvolution(64,128,4,4,4,2,2,2,1,1,1))
netD:add(nn.VolumetricBatchNormalization(128))
netD:add(nn.LeakyReLU(opt.leakyslope, true))
-- 128x16x16x16 -> 256x8x8x8
netD:add(nn.VolumetricDropout(0.5))
netD:add(nn.VolumetricConvolution(128,256,4,4,4,2,2,2,1,1,1))
netD:add(nn.VolumetricBatchNormalization(256))
netD:add(nn.LeakyReLU(opt.leakyslope, true))
-- 256x8x8x8 -> 512x4x4x4
netD:add(nn.VolumetricDropout(0.5))
netD:add(nn.VolumetricConvolution(256,512,4,4,4,2,2,2,1,1,1))
netD:add(nn.VolumetricBatchNormalization(512))
netD:add(nn.LeakyReLU(opt.leakyslope, true))
-- 512x4x4x4 -> 1x1x1x1
netD:add(nn.VolumetricDropout(0.5))
netD:add(nn.VolumetricConvolution(512,1,4,4,4))
netD:add(nn.Sigmoid())
netD:add(nn.View(1):setNumInputDims(4))
-- Projector (project output into latent space)
local netP = nn.Sequential()
-- 1x64x64x64 -> 64x32x32x32
netP:add(nn.VolumetricConvolution(1,64,4,4,4,2,2,2,1,1,1))
netP:add(nn.VolumetricBatchNormalization(64))
netP:add(nn.LeakyReLU(opt.leakyslope, true))
-- 64x32x32x32 -> 128x16x16x16
netP:add(nn.VolumetricConvolution(64,128,4,4,4,2,2,2,1,1,1))
netP:add(nn.VolumetricBatchNormalization(128))
netP:add(nn.LeakyReLU(opt.leakyslope, true))
-- 128x16x16x16 -> 256x8x8x8
netP:add(nn.VolumetricConvolution(128,256,4,4,4,2,2,2,1,1,1))
netP:add(nn.VolumetricBatchNormalization(256))
netP:add(nn.LeakyReLU(opt.leakyslope, true))
-- 256x8x8x8 -> 512x4x4x4
netP:add(nn.VolumetricConvolution(256,512,4,4,4,2,2,2,1,1,1))
netP:add(nn.VolumetricBatchNormalization(512))
netP:add(nn.LeakyReLU(opt.leakyslope, true))
-- 512x4x4x4 -> 200x1x1x1
netP:add(nn.VolumetricConvolution(512,200,4,4,4))
--netP:add(nn.Sigmoid())
netP:add(nn.Tanh())
--netP:add(nn.Mul())
-- Volumetric Classifier (learn better features representations)
-- could be own adaptation of VoxNet or something different
local netC = nn.Sequential()
-- 1x64x64x64 -> 32x32x32x32
netC:add(nn.VolumetricConvolution(1,32,4,4,4,2,2,2,1,1,1))
netC:add(nn.VolumetricBatchNormalization(32))
netC:add(nn.LeakyReLU(opt.leakyslope, true))
netC:add(nn.VolumetricDropout(0.2))
-- 32x32x32x32 -> 32x15x15x15
netC:add(nn.VolumetricConvolution(32,32,5,5,5,2,2,2,1,1,1))
netC:add(nn.VolumetricBatchNormalization(32))
netC:add(nn.LeakyReLU(opt.leakyslope,true))
netC:add(nn.VolumetricDropout(0.3))
-- 32x15x15x15 -> 32x12x12x12
netC:add(nn.VolumetricConvolution(32,32,3,3,3,1,1,1))
netC:add(nn.VolumetricBatchNormalization(32))
netC:add(nn.LeakyReLU(opt.leakyslope,true))
-- 32x12x12x12 -> 32x6x6x6
netC:add(nn.VolumetricMaxPooling(2,2,2))
netC:add(nn.VolumetricBatchNormalization(32))
netC:add(nn.VolumetricDropout(0.4))
-- 32x6x6x6 -> 128
netC:add(nn.View(6912))
netC:add(nn.Linear(6912,128))
netC:add(nn.ReLU(true))
netC:add(nn.Dropout(0.5))
-- 128 -> 101
netC:add(nn.Linear(128,opt.nc or 101))
-- Voxception
local netC_Vox = nn.Sequential()
-- 1x64x64x64 -> 32x32x32x32
netC_Vox:add(vl.Voxception(5,1,16,opt))
netC_Vox:add(vl.VoxceptionDown(5,32,8,opt))
netC_Vox:add(nn.VolumetricDropout(0.2))
-- 32x32x32x32 -> 32x16x16x16
netC_Vox:add(vl.Voxception(5,32,16,opt))
netC_Vox:add(vl.VoxceptionDown(5,32,8,opt))
netC_Vox:add(nn.VolumetricDropout(0.4))
-- 32x16x16x16 -> 64x8x8x8
netC_Vox:add(vl.Voxception(5,32,32,opt))
netC_Vox:add(vl.VoxceptionDown(5,64,16,opt))
netC_Vox:add(nn.VolumetricDropout(0.5))
-- 64x8x8x8 -> 128x4x4x4
netC_Vox:add(vl.Voxception(5,64,64,opt))
netC_Vox:add(vl.VoxceptionDown(5,128,32,opt))
netC_Vox:add(nn.VolumetricDropout(0.5))
-- 128x4x4x4 -> 101
netC_Vox:add(nn.View(8192))
netC_Vox:add(nn.Linear(8192,128))
netC_Vox:add(nn.Dropout(0.5))
netC_Vox:add(nn.LeakyReLU(opt.leakyslope, true))
netC_Vox:add(nn.Linear(128,opt.nc or 101))
net64 = {}
net64.netG = netG
net64.netD = netD
net64.netP = netP
net64.netC = netC
net64.netC_Vox = netC_Vox
return net64