-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
49 lines (38 loc) · 1.22 KB
/
main.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
require 'image'
require 'xlua'
require 'nn'
require 'dpnn'
require 'optim'
require 'lfs'
local argparse = require 'argparse'
local parser = argparse('oneira art', 'a fine-art generator')
parser:option('-o --output', 'output directory for generated images')
parser:option('-s --size', 'number of samples generated')
parser:option('-m --model', 'location of model')
args = parser:parse()
input = args.input
output_folder = args.output
batch_size = tonumber(args.size)
model_path = args.model
torch.setnumthreads(4)
--pad zeros to the end of generated images, up to four
function getNumber(num)
length = #tostring(num)
filename = ""
for i=1, (4 - length) do
filename = filename .. 0
end
filename = filename .. num
return filename
end
z_dim = 100
--the model contains a variational autoencoder, with an encoder, variational sampler, and decoder.
--the decoder is all we need for the generation
model = torch.load(model_path).modules[3]
--noise to pass through decoder to generate random samples from Z
noise_x = torch.Tensor(batch_size, z_dim, 1, 1):float()
noise_x:normal(0, 0.01)
generations = model:forward(noise_x)
for i = 1, batch_size do
image.save(output_folder .. getNumber(i) .. '.png', generations[i])
end