In [1]:
# import modules 
% matplotlib inline

import os
import time
import h5py
import pylab
import random
import pandas as pd
import numpy as np
import cPickle as pkl
from lasagne import layers, updates
from scipy.misc import imread, imresize
from lasagne.nonlinearities import softmax
from nolearn.lasagne import NeuralNet, BatchIterator

icdar_root = 'icdar03/train/case-sensitive-train.mat'
project_root = 'workspace/.project/project'
data_root = os.path.join(os.path.expanduser('~'), project_root, 'datasets')
model_root = os.path.join(os.path.expanduser('~'), project_root, 'models')


Using gpu device 0: GeForce GT 740M (CNMeM is disabled)

In [2]:
f = h5py.File(os.path.join(data_root, icdar_root), "r")

In [3]:
f.keys()


Out[3]:
[u'#refs#', u'gt']

In [4]:
som1 = f['gt']['images']
som2 = f['gt']['labels']

In [ ]:
start_time = time.time()
som1_np = []
for i in som1:
    for j in f[i.item()]:
        som1_np.append(np.array(f[j.item()]).T)
        
images = np.stack(som1_np)
print time.time() - start_time

In [76]:
som1_np[1].shape


Out[76]:
(24, 24)

In [77]:
i = random.randrange(0, images.shape[0])
pylab.imshow(images[i])
pylab.gray()
pylab.axis('off')
pylab.show()



In [78]:
images.shape[0]


Out[78]:
107454

In [85]:
start_time = time.time()
som2_np = []
for i in som2:
    for j in f[i.item()]:
        print chr(j);break
        #som2_np.append(f[j.item()])
        
#labels = np.stack(som2_np)
#print time.time() - start_time


0
1
2
3
4
5
6
7
8
9
A
a
B
b
C
c
D
d
E
e
F
f
G
g
H
h
I
i
J
j
K
k
L
l
M
m
N
n
O
o
P
p
Q
q
R
r
S
s
T
t
U
u
V
v
W
w
X
x
Y
y
Z
z

In [5]:
start_time = time.time()
no_in_class = []
for i in som1:
    cnt = 0
    for j in f[i.item()]:
        cnt += 1
    no_in_class.append(cnt)
    
print time.time() - start_time


11.194175005

In [6]:
no_in_class


Out[6]:
[817,
 739,
 686,
 517,
 552,
 494,
 484,
 463,
 488,
 445,
 4497,
 3935,
 1054,
 725,
 2130,
 1549,
 2058,
 1769,
 5969,
 6059,
 1109,
 993,
 1246,
 1015,
 2369,
 2118,
 3471,
 3516,
 302,
 155,
 608,
 509,
 2379,
 2062,
 1484,
 1229,
 3429,
 3534,
 3787,
 3953,
 1425,
 1006,
 152,
 143,
 3435,
 3277,
 3681,
 3100,
 4132,
 3876,
 1378,
 1427,
 637,
 552,
 1002,
 844,
 267,
 219,
 940,
 995,
 149,
 119]

In [ ]: