1
0
Fork 0
mirror of synced 2024-06-01 18:49:33 +12:00

Add use_transparent_png option

This commit is contained in:
nagadomi 2016-05-19 23:02:02 +09:00
parent db68eb208e
commit 145b47dbf5
2 changed files with 30 additions and 15 deletions

View file

@ -32,12 +32,24 @@ local function load_images(list)
local MARGIN = 32
local lines = utils.split(file.read(list), "\n")
local x = {}
local skip_notice = false
for i = 1, #lines do
local line = lines[i]
local im, meta = image_loader.load_byte(line)
local skip = false
if meta and meta.alpha then
if settings.use_transparent_png then
im = alpha_util.fill(im, meta.alpha, torch.random(0, 1))
else
skip = true
end
end
if skip then
if not skip_notice then
io.stderr:write("skip transparent png (settings.use_transparent_png=0)\n")
skip_notice = true
end
else
if settings.max_training_image_size > 0 then
im = crop_if_large(im, settings.max_training_image_size)
end
@ -55,6 +67,7 @@ local function load_images(list)
else
io.stderr:write(string.format("\n%s: skip: load error.\n", line))
end
end
xlua.progress(i, #lines)
if i % 10 == 0 then
collectgarbage()

View file

@ -53,6 +53,7 @@ cmd:option("-downsampling_filters", "Box,Lanczos,Sinc", '(comma separated)downsa
cmd:option("-gamma_correction", 0, 'Resizing with colorspace correction(sRGB:gamma 2.2) in scale training (0|1)')
cmd:option("-upsampling_filter", "Box", 'upsampling filter for 2x scale training (dev)')
cmd:option("-max_training_image_size", -1, 'if training image is larger than N, image will be crop randomly when data converting')
cmd:option("-use_transparent_png", 0, 'use transparent png (0|1)')
local function to_bool(settings, name)
if settings[name] == 1 then
@ -69,6 +70,7 @@ end
to_bool(settings, "plot")
to_bool(settings, "save_history")
to_bool(settings, "gamma_correction")
to_bool(settings, "use_transparent_png")
if settings.plot then
require 'gnuplot'