forked from DmitryUlyanov/texture_nets
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstylization_process.lua
More file actions
43 lines (32 loc) · 1.12 KB
/
Copy pathstylization_process.lua
File metadata and controls
43 lines (32 loc) · 1.12 KB
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
require 'cutorch'
require 'nn'
require 'cunn'
require 'cudnn'
require 'image'
require 'src/utils'
local cmd = torch.CmdLine()
cmd:option('-input_image', '', 'Image to stylize.')
cmd:option('-image_size', 0, 'Resize input image to. Do not resize if 0.')
cmd:option('-model', '', 'Path to trained model.')
cmd:option('-noise_depth', 3, 'Noise depth used to train model.')
cmd:option('-gpu', 0, 'Zero indexed gpu.')
cmd:option('-save_path', 'stylized.png', 'Path to save stylized image.')
local params = cmd:parse(arg)
cutorch.setDevice(params.gpu+1)
-- Load model
local model = torch.load(params.model):cuda()
--model:evaluate()
-- Load image and scale
local img = image.load(params.input_image, 3)
if params.image_size > 0 then
img = image.scale(img, params.image_size, params.image_size)
end
-- Create input tensor
local input = torch.FloatTensor(1, 3 + params.noise_depth, img:size(2), img:size(3))
input[1]:narrow(1, 1, 3):copy(img)
-- Stylize
local stylized = model:forward(input:cuda()):double()
-- stylized = torch.clamp(deprocess(stylized[1]), 0, 1)
stylized = deprocess(stylized[1])
-- Save
image.save(params.save_path, stylized)