process.lua 994 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
36
-- 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.

local threads=require 'threads'
t=threads.Threads(30)
for j=1,30 do
  t:addjob(function()
      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
      end
      for i=j,898573,30 do
        ch=dofile('t7/train/'..i..'.lua')
        os.remove('t7/train/'..i..'.lua')
        rescaleCharacter(ch.input)
        torch.save('t7/train/'..i..'.t7',ch)
      end
      for i=j,224559,30 do
        ch=dofile('t7/test/'..i..'.lua')
        os.remove('t7/test/'..i..'.lua')
        rescaleCharacter(ch.input)
        torch.save('t7/test/'..i..'.t7',ch)
      end
    end
  )
end
for i=1,30 do
  t:dojob()
end