forked from willwhitney/dc-ign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.lua
73 lines (61 loc) · 1.52 KB
/
cache.lua
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'cunn'
require 'pl'
require 'paths'
require 'optim'
require 'gnuplot'
require 'math'
require 'rmsprop'
require 'cudnn'
require 'nnx'
require("UnPooling.lua")
require 'image'
bsize = 25 --50
imwidth = 150
COLOR = false
TOTALFACES = 5230
num_train_batches = 200--5000
num_test_batches = 0--TOTALFACES-num_train_batches
function cache(id, mode)
collectgarbage()
if COLOR==true then
batch = torch.zeros(bsize,3,imwidth,imwidth)
else
batch = torch.zeros(bsize,1,imwidth,imwidth)
end
for i=1,bsize do
local im_tmp = image.load('DATASET/' .. mode .. '/face_' .. id .. '/' .. i .. '.png')
if COLOR==true then
im = torch.zeros(3,150, 150)
if im:size()[2] ~= imwidth then
newim = image.scale(im, imwidth ,imwidth)
else
newim = im
end
else
im = torch.zeros(1,150, 150)
im[1] = im_tmp[1]*0.21 + im_tmp[2]*0.72 + im_tmp[3]*0.07
newim = image.scale(im[1], imwidth ,imwidth)
end
batch[i]=newim
end
if COLOR==true then
torch.save('DATASET/th_color_' .. mode .. '/batch' .. id, batch:float())
else
torch.save('DATASET/th_' .. mode .. '/batch' .. id, batch:float())
end
end
for t = 1, num_train_batches do
cache(t, 'FT_training')
print(t)
end
for t = 1, num_test_batches do
cache(t, 'FT_test')
print(t)
end
--testing speed of loading batch
-- require 'sys'
-- for rep = 1,20 do
-- sys.tic()
-- batch = torch.load('DATASET/th_lstraining/batch' .. rep)
-- print(sys.toc())
-- end