Skip to content

Instantly share code, notes, and snippets.

@soumith
Created June 22, 2015 21:34
Show Gist options
  • Save soumith/e3f722173ea16c1ea0d9 to your computer and use it in GitHub Desktop.
Save soumith/e3f722173ea16c1ea0d9 to your computer and use it in GitHub Desktop.
CIFAR-10 eyescream
----------------------------------------------------------------------
-- CIFAR 8x8
opt.scale = 8
opt.geometry = {3, opt.scale, opt.scale}
local input_sz = opt.geometry[1] * opt.geometry[2] * opt.geometry[3]
local numhid = 600
model_D = nn.Sequential()
model_D:add(nn.Reshape(input_sz))
model_D:add(nn.Linear(input_sz, numhid))
model_D:add(nn.ReLU())
model_D:add(nn.Dropout())
model_D:add(nn.Linear(numhid, numhid))
model_D:add(nn.ReLU())
model_D:add(nn.Dropout())
model_D:add(nn.Linear(numhid,1))
model_D:add(nn.Sigmoid())
local numhid = 1200
model_G = nn.Sequential()
model_G:add(nn.Linear(opt.noiseDim, numhid))
model_G:add(nn.ReLU())
model_G:add(nn.Linear(numhid, numhid))
model_G:add(nn.Sigmoid())
model_G:add(nn.Linear(numhid, input_sz))
model_G:add(nn.Reshape(opt.geometry[1], opt.geometry[2], opt.geometry[3]))
----------------------------------------------------------------------
-- CIFAR 8->14
opt.coarseSize = 8
opt.fineSize = 14
opt.geometry = {3, opt.fineSize, opt.fineSize}
local input_sz = opt.geometry[1] * opt.geometry[2] * opt.geometry[3]
local nplanes = 64
model_D = nn.Sequential()
model_D:add(nn.CAddTable())
model_D:add(nn.SpatialConvolution(3, nplanes, 5, 5))
model_D:add(nn.ReLU())
model_D:add(nn.SpatialConvolution(nplanes, nplanes, 5, 5, 2, 2))
local sz =math.floor( ( (opt.fineSize - 5 + 1) - 5) / 2 + 1)
model_D:add(nn.Reshape(nplanes*sz*sz))
model_D:add(nn.ReLU())
model_D:add(nn.Dropout())
model_D:add(nn.Linear(nplanes*sz*sz, 1))
model_D:add(nn.Sigmoid())
local nplanes = 64
model_G = nn.Sequential()
model_G:add(nn.JoinTable(2, 2))
model_G:add(nn.SpatialConvolutionUpsample(3+1, nplanes, 5, 5, 1)) -- 3 color channels + conditional
model_G:add(nn.ReLU())
model_G:add(nn.SpatialConvolutionUpsample(nplanes, nplanes, 5, 5, 1))
model_G:add(nn.ReLU())
model_G:add(nn.SpatialConvolutionUpsample(nplanes, 3, 5, 5, 1))
model_G:add(nn.View(opt.geometry[1], opt.geometry[2], opt.geometry[3]))
----------------------------------------------------------------------
-- CIFAR 14->28
opt.coarseSize = 14
opt.fineSize = 28
opt.geometry = {3, opt.fineSize, opt.fineSize}
local input_sz = opt.geometry[1] * opt.geometry[2] * opt.geometry[3]
local nplanes = 128
model_D = nn.Sequential()
model_D:add(nn.CAddTable())
model_D:add(nn.SpatialConvolution(3, nplanes, 5, 5))
model_D:add(nn.ReLU())
model_D:add(nn.SpatialConvolution(nplanes, nplanes, 5, 5, 2, 2))
local sz =math.floor( ( (opt.fineSize - 5 + 1) - 5) / 2 + 1)
model_D:add(nn.Reshape(nplanes*sz*sz))
model_D:add(nn.ReLU())
model_D:add(nn.Dropout())
model_D:add(nn.Linear(nplanes*sz*sz, 1))
model_D:add(nn.Sigmoid())
local nplanes = 128
model_G = nn.Sequential()
model_G:add(nn.JoinTable(2, 2))
model_G:add(nn.SpatialConvolutionUpsample(3+1, nplanes, 7, 7, 1)) -- 3 color channels + conditional
model_G:add(nn.ReLU())
model_G:add(nn.SpatialConvolutionUpsample(nplanes, nplanes, 7, 7, 1))
model_G:add(nn.ReLU())
model_G:add(nn.SpatialConvolutionUpsample(nplanes, 3, 5, 5, 1))
model_G:add(nn.View(opt.geometry[1], opt.geometry[2], opt.geometry[3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment