|
@@ -6,13 +6,12 @@ require './lib/LeakyReLU'
|
|
|
local iproc = require './lib/iproc'
|
|
|
local reconstruct = require './lib/reconstruct'
|
|
|
local image_loader = require './lib/image_loader'
|
|
|
-
|
|
|
local BLOCK_OFFSET = 7
|
|
|
|
|
|
torch.setdefaulttensortype('torch.FloatTensor')
|
|
|
|
|
|
local function convert_image(opt)
|
|
|
- local x = image_loader.load_float(opt.i)
|
|
|
+ local x, alpha = image_loader.load_float(opt.i)
|
|
|
local new_x = nil
|
|
|
local t = sys.clock()
|
|
|
if opt.o == "(auto)" then
|
|
@@ -39,7 +38,7 @@ local function convert_image(opt)
|
|
|
else
|
|
|
error("undefined method:" .. opt.method)
|
|
|
end
|
|
|
- image.save(opt.o, new_x)
|
|
|
+ image_loader.save_png(opt.o, new_x, alpha)
|
|
|
print(opt.o .. ": " .. (sys.clock() - t) .. " sec")
|
|
|
end
|
|
|
local function convert_frames(opt)
|
|
@@ -59,41 +58,41 @@ local function convert_frames(opt)
|
|
|
end
|
|
|
fp:close()
|
|
|
for i = 1, #lines do
|
|
|
- if opt.resume == 0 or path.exists(string.format(opt.o, i)) == false then
|
|
|
- local x = image_loader.load_float(lines[i])
|
|
|
- local new_x = nil
|
|
|
- if opt.m == "noise" and opt.noise_level == 1 then
|
|
|
- new_x = reconstruct.image(noise1_model, x, BLOCK_OFFSET, opt.crop_size)
|
|
|
- elseif opt.m == "noise" and opt.noise_level == 2 then
|
|
|
- new_x = reconstruct.image(noise2_model, x, BLOCK_OFFSET)
|
|
|
- elseif opt.m == "scale" then
|
|
|
- new_x = reconstruct.scale(scale_model, opt.scale, x, BLOCK_OFFSET, opt.crop_size)
|
|
|
- elseif opt.m == "noise_scale" and opt.noise_level == 1 then
|
|
|
- x = reconstruct.image(noise1_model, x, BLOCK_OFFSET)
|
|
|
- new_x = reconstruct.scale(scale_model, opt.scale, x, BLOCK_OFFSET, opt.crop_size)
|
|
|
- elseif opt.m == "noise_scale" and opt.noise_level == 2 then
|
|
|
- x = reconstruct.image(noise2_model, x, BLOCK_OFFSET)
|
|
|
- new_x = reconstruct.scale(scale_model, opt.scale, x, BLOCK_OFFSET, opt.crop_size)
|
|
|
- else
|
|
|
- error("undefined method:" .. opt.method)
|
|
|
- end
|
|
|
- local output = nil
|
|
|
- if opt.o == "(auto)" then
|
|
|
- local name = path.basename(lines[i])
|
|
|
- local e = path.extension(name)
|
|
|
- local base = name:sub(0, name:len() - e:len())
|
|
|
- output = path.join(path.dirname(opt.i), string.format("%s(%s).png", base, opt.m))
|
|
|
- else
|
|
|
- output = string.format(opt.o, i)
|
|
|
- end
|
|
|
- image.save(output, new_x)
|
|
|
- xlua.progress(i, #lines)
|
|
|
- if i % 10 == 0 then
|
|
|
- collectgarbage()
|
|
|
- end
|
|
|
- else
|
|
|
- xlua.progress(i, #lines)
|
|
|
- end
|
|
|
+ if opt.resume == 0 or path.exists(string.format(opt.o, i)) == false then
|
|
|
+ local x, alpha = image_loader.load_float(lines[i])
|
|
|
+ local new_x = nil
|
|
|
+ if opt.m == "noise" and opt.noise_level == 1 then
|
|
|
+ new_x = reconstruct.image(noise1_model, x, BLOCK_OFFSET, opt.crop_size)
|
|
|
+ elseif opt.m == "noise" and opt.noise_level == 2 then
|
|
|
+ new_x = reconstruct.image(noise2_model, x, BLOCK_OFFSET)
|
|
|
+ elseif opt.m == "scale" then
|
|
|
+ new_x = reconstruct.scale(scale_model, opt.scale, x, BLOCK_OFFSET, opt.crop_size)
|
|
|
+ elseif opt.m == "noise_scale" and opt.noise_level == 1 then
|
|
|
+ x = reconstruct.image(noise1_model, x, BLOCK_OFFSET)
|
|
|
+ new_x = reconstruct.scale(scale_model, opt.scale, x, BLOCK_OFFSET, opt.crop_size)
|
|
|
+ elseif opt.m == "noise_scale" and opt.noise_level == 2 then
|
|
|
+ x = reconstruct.image(noise2_model, x, BLOCK_OFFSET)
|
|
|
+ new_x = reconstruct.scale(scale_model, opt.scale, x, BLOCK_OFFSET, opt.crop_size)
|
|
|
+ else
|
|
|
+ error("undefined method:" .. opt.method)
|
|
|
+ end
|
|
|
+ local output = nil
|
|
|
+ if opt.o == "(auto)" then
|
|
|
+ local name = path.basename(lines[i])
|
|
|
+ local e = path.extension(name)
|
|
|
+ local base = name:sub(0, name:len() - e:len())
|
|
|
+ output = path.join(path.dirname(opt.i), string.format("%s(%s).png", base, opt.m))
|
|
|
+ else
|
|
|
+ output = string.format(opt.o, i)
|
|
|
+ end
|
|
|
+ image_loader.save_png(output, new_x, alpha)
|
|
|
+ xlua.progress(i, #lines)
|
|
|
+ if i % 10 == 0 then
|
|
|
+ collectgarbage()
|
|
|
+ end
|
|
|
+ else
|
|
|
+ xlua.progress(i, #lines)
|
|
|
+ end
|
|
|
end
|
|
|
end
|
|
|
|