process.lua 915 Bytes
Newer Older
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
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
-- Copyright 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the license found in the
-- LICENSE file in the root directory of this source tree.

train={}
test={}
torch.manualSeed(0)
p=torch.randperm(45)

function rescaleCharacter(c)
  local cc=torch.cat(c,1)
  local m=cc:min(1)
  local s=(cc:max(1)-m):float()
  for i=1,#c do
    c[i]=(torch.cdiv((c[i]-m:expandAs(c[i])):float(),s:expandAs(c[i]))*255.99):byte()
  end
  return c
end

for char = 1,183 do
  for writer = 1,36 do
    train[#train+1]={input=rescaleCharacter(dofile('tmp/' .. char .. '.' .. p[writer] .. '.lua')),target=char}
  end
end
for char = 1,183 do
  for writer = 37,45 do
    test[#test+1]={input=rescaleCharacter(dofile('tmp/' .. char .. '.' .. p[writer] .. '.lua')),target=char}
  end
end
print(#train,#test)
os.execute('mkdir t7/')
torch.save('t7/train.t7',train)
torch.save('t7/test.t7',test)