2015-10-28 19:30:47 +13:00
|
|
|
local __FILE__ = (function() return string.gsub(debug.getinfo(2, 'S').source, "^@", "") end)()
|
|
|
|
package.path = path.join(path.dirname(__FILE__), "lib", "?.lua;") .. package.path
|
|
|
|
|
|
|
|
require 'pl'
|
2015-06-13 18:02:02 +12:00
|
|
|
require 'image'
|
2015-10-28 19:30:47 +13:00
|
|
|
local compression = require 'compression'
|
|
|
|
local settings = require 'settings'
|
|
|
|
local image_loader = require 'image_loader'
|
2015-10-30 02:44:15 +13:00
|
|
|
local iproc = require 'iproc'
|
2015-06-13 18:02:02 +12:00
|
|
|
|
2015-05-17 17:42:53 +12:00
|
|
|
local function load_images(list)
|
2015-07-12 00:53:45 +12:00
|
|
|
local MARGIN = 32
|
2015-10-28 19:30:47 +13:00
|
|
|
local lines = utils.split(file.read(list), "\n")
|
2015-05-17 17:42:53 +12:00
|
|
|
local x = {}
|
2015-10-28 19:30:47 +13:00
|
|
|
for i = 1, #lines do
|
|
|
|
local line = lines[i]
|
2015-10-26 13:23:52 +13:00
|
|
|
local im, alpha = image_loader.load_byte(line)
|
|
|
|
if alpha then
|
2015-10-28 19:30:47 +13:00
|
|
|
io.stderr:write(string.format("\n%s: skip: image has alpha channel.\n", line))
|
2015-05-17 17:42:53 +12:00
|
|
|
else
|
2015-10-30 02:44:15 +13:00
|
|
|
im = iproc.crop_mod4(im)
|
2015-10-26 13:23:52 +13:00
|
|
|
local scale = 1.0
|
2015-11-16 17:44:49 +13:00
|
|
|
if settings.random_half_rate > 0.0 then
|
2015-10-26 13:23:52 +13:00
|
|
|
scale = 2.0
|
|
|
|
end
|
|
|
|
if im then
|
|
|
|
if im:size(2) > (settings.crop_size * scale + MARGIN) and im:size(3) > (settings.crop_size * scale + MARGIN) then
|
2015-10-28 19:30:47 +13:00
|
|
|
table.insert(x, compression.compress(im))
|
2015-10-26 13:23:52 +13:00
|
|
|
else
|
2015-10-28 19:30:47 +13:00
|
|
|
io.stderr:write(string.format("\n%s: skip: image is too small (%d > size).\n", line, settings.crop_size * scale + MARGIN))
|
2015-10-26 13:23:52 +13:00
|
|
|
end
|
|
|
|
else
|
2015-10-28 19:30:47 +13:00
|
|
|
io.stderr:write(string.format("\n%s: skip: load error.\n", line))
|
2015-10-26 13:23:52 +13:00
|
|
|
end
|
2015-05-17 17:42:53 +12:00
|
|
|
end
|
2015-10-28 19:30:47 +13:00
|
|
|
xlua.progress(i, #lines)
|
|
|
|
if i % 10 == 0 then
|
2015-05-17 17:42:53 +12:00
|
|
|
collectgarbage()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return x
|
|
|
|
end
|
2015-10-28 19:30:47 +13:00
|
|
|
|
2015-10-26 13:23:52 +13:00
|
|
|
torch.manualSeed(settings.seed)
|
2015-05-17 17:42:53 +12:00
|
|
|
print(settings)
|
|
|
|
local x = load_images(settings.image_list)
|
|
|
|
torch.save(settings.images, x)
|