forked from Halfish/lstm-ctc-ocr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_dump.lua
32 lines (25 loc) · 784 Bytes
/
2_dump.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
require 'image'
require 'io'
local num = tonumber(arg[1]) or 10
print(num)
local decoder_util = require 'decoder'
local decoder = decoder_util.create('codec_num.txt')
local fullset = {}
fullset.size = num
local height, width = 36, 255
local strlen = 20
local inputs = torch.Tensor(fullset.size, height, width)
local targets = {}
for i = 1, num do
local filename = './lines/' .. tostring(i) .. '.jpg'
inputs[i] = image.load(filename, 1)
local file = io.open('./lines/' .. tostring(i) .. '.txt', 'r')
local labelstr = file:read()
labelstr = string.gsub(labelstr, '\n', '')
file:close()
table.insert(targets, decoder:str2target(labelstr))
end
fullset.inputs = inputs
fullset.targets = targets
print('saving data...')
torch.save('fullset.dat', fullset)