3 Star 0 Fork 0

mirrors_DmitryUlyanov/texture_nets

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
demo.lua 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
elmar-haussmann 提交于 2017-04-04 16:09 . Add RiseML demo.
require 'nn'
require 'image'
require 'InstanceNormalization'
require 'src/utils'
require 'riseml'
local cmd = torch.CmdLine()
cmd:option('-image_size', 0, 'Resize input image to. Do not resize if 0.')
cmd:option('-model', '', 'Path to trained model.')
cmd:option('-cpu', false, 'use this flag to run on CPU')
local params = cmd:parse(arg)
-- Load model and set type
local model = torch.load(params.model)
if params.cpu then
tp = 'torch.FloatTensor'
else
require 'cutorch'
require 'cunn'
require 'cudnn'
tp = 'torch.CudaTensor'
model = cudnn.convert(model, cudnn)
end
model:type(tp)
model:evaluate()
local function run_image(img_data)
-- Load image and scale
local byte_tensor = torch.ByteTensor(torch.ByteStorage():string(img_data))
local img = image.decompressJPG(byte_tensor, 3):float()
if params.image_size > 0 then
img = image.scale(img, params.image_size, params.image_size)
end
-- Stylize
local input = img:add_dummy()
local stylized = model:forward(input:type(tp)):double()
stylized = deprocess(stylized[1])
-- Return
return image.compressJPG(torch.clamp(stylized,0,1)):storage():string()
end
riseml.serve(run_image)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_DmitryUlyanov/texture_nets.git
git@gitee.com:mirrors_DmitryUlyanov/texture_nets.git
mirrors_DmitryUlyanov
texture_nets
texture_nets
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385