Commit 6fb61526 authored by Leif's avatar Leif
Browse files

Merge remote-tracking branch 'upstream/dygraph' into dy1

parents 1fd7e118 a78afa23
...@@ -203,9 +203,9 @@ class GridGenerator(nn.Layer): ...@@ -203,9 +203,9 @@ class GridGenerator(nn.Layer):
def build_C_paddle(self): def build_C_paddle(self):
""" Return coordinates of fiducial points in I_r; C """ """ Return coordinates of fiducial points in I_r; C """
F = self.F F = self.F
ctrl_pts_x = paddle.linspace(-1.0, 1.0, int(F / 2)) ctrl_pts_x = paddle.linspace(-1.0, 1.0, int(F / 2), dtype='float64')
ctrl_pts_y_top = -1 * paddle.ones([int(F / 2)]) ctrl_pts_y_top = -1 * paddle.ones([int(F / 2)], dtype='float64')
ctrl_pts_y_bottom = paddle.ones([int(F / 2)]) ctrl_pts_y_bottom = paddle.ones([int(F / 2)], dtype='float64')
ctrl_pts_top = paddle.stack([ctrl_pts_x, ctrl_pts_y_top], axis=1) ctrl_pts_top = paddle.stack([ctrl_pts_x, ctrl_pts_y_top], axis=1)
ctrl_pts_bottom = paddle.stack([ctrl_pts_x, ctrl_pts_y_bottom], axis=1) ctrl_pts_bottom = paddle.stack([ctrl_pts_x, ctrl_pts_y_bottom], axis=1)
C = paddle.concat([ctrl_pts_top, ctrl_pts_bottom], axis=0) C = paddle.concat([ctrl_pts_top, ctrl_pts_bottom], axis=0)
...@@ -213,12 +213,14 @@ class GridGenerator(nn.Layer): ...@@ -213,12 +213,14 @@ class GridGenerator(nn.Layer):
def build_P_paddle(self, I_r_size): def build_P_paddle(self, I_r_size):
I_r_height, I_r_width = I_r_size I_r_height, I_r_width = I_r_size
I_r_grid_x = ( I_r_grid_x = (paddle.arange(
paddle.arange(-I_r_width, I_r_width, 2).astype('float32') + 1.0 -I_r_width, I_r_width, 2, dtype='float64') + 1.0
) / I_r_width # self.I_r_width ) / paddle.to_tensor(np.array([I_r_width]))
I_r_grid_y = (
paddle.arange(-I_r_height, I_r_height, 2).astype('float32') + 1.0 I_r_grid_y = (paddle.arange(
) / I_r_height # self.I_r_height -I_r_height, I_r_height, 2, dtype='float64') + 1.0
) / paddle.to_tensor(np.array([I_r_height]))
# P: self.I_r_width x self.I_r_height x 2 # P: self.I_r_width x self.I_r_height x 2
P = paddle.stack(paddle.meshgrid(I_r_grid_x, I_r_grid_y), axis=2) P = paddle.stack(paddle.meshgrid(I_r_grid_x, I_r_grid_y), axis=2)
P = paddle.transpose(P, perm=[1, 0, 2]) P = paddle.transpose(P, perm=[1, 0, 2])
...@@ -228,7 +230,7 @@ class GridGenerator(nn.Layer): ...@@ -228,7 +230,7 @@ class GridGenerator(nn.Layer):
def build_inv_delta_C_paddle(self, C): def build_inv_delta_C_paddle(self, C):
""" Return inv_delta_C which is needed to calculate T """ """ Return inv_delta_C which is needed to calculate T """
F = self.F F = self.F
hat_C = paddle.zeros((F, F), dtype='float32') # F x F hat_C = paddle.zeros((F, F), dtype='float64') # F x F
for i in range(0, F): for i in range(0, F):
for j in range(i, F): for j in range(i, F):
if i == j: if i == j:
...@@ -241,13 +243,21 @@ class GridGenerator(nn.Layer): ...@@ -241,13 +243,21 @@ class GridGenerator(nn.Layer):
delta_C = paddle.concat( # F+3 x F+3 delta_C = paddle.concat( # F+3 x F+3
[ [
paddle.concat( paddle.concat(
[paddle.ones((F, 1)), C, hat_C], axis=1), # F x F+3 [paddle.ones(
(F, 1), dtype='float64'), C, hat_C], axis=1), # F x F+3
paddle.concat( paddle.concat(
[paddle.zeros((2, 3)), paddle.transpose( [
C, perm=[1, 0])], paddle.zeros(
(2, 3), dtype='float64'), paddle.transpose(
C, perm=[1, 0])
],
axis=1), # 2 x F+3 axis=1), # 2 x F+3
paddle.concat( paddle.concat(
[paddle.zeros((1, 3)), paddle.ones((1, F))], [
paddle.zeros(
(1, 3), dtype='float64'), paddle.ones(
(1, F), dtype='float64')
],
axis=1) # 1 x F+3 axis=1) # 1 x F+3
], ],
axis=0) axis=0)
...@@ -268,7 +278,9 @@ class GridGenerator(nn.Layer): ...@@ -268,7 +278,9 @@ class GridGenerator(nn.Layer):
# rbf: n x F # rbf: n x F
rbf = paddle.multiply( rbf = paddle.multiply(
paddle.square(rbf_norm), paddle.log(rbf_norm + eps)) paddle.square(rbf_norm), paddle.log(rbf_norm + eps))
P_hat = paddle.concat([paddle.ones((n, 1)), P, rbf], axis=1) P_hat = paddle.concat(
[paddle.ones(
(n, 1), dtype='float64'), P, rbf], axis=1)
return P_hat # n x F+3 return P_hat # n x F+3
def get_expand_tensor(self, batch_C_prime): def get_expand_tensor(self, batch_C_prime):
......
...@@ -24,7 +24,9 @@ class BaseRecLabelDecode(object): ...@@ -24,7 +24,9 @@ class BaseRecLabelDecode(object):
character_type='ch', character_type='ch',
use_space_char=False): use_space_char=False):
support_character_type = [ support_character_type = [
'ch', 'en', 'en_sensitive', 'french', 'german', 'japan', 'korean' 'ch', 'en', 'en_sensitive', 'french', 'german', 'japan', 'korean', 'it',
'xi', 'pu', 'ru', 'ar', 'ta', 'ug', 'fa', 'ur', 'rs', 'oc', 'rsc', 'bg',
'uk', 'be', 'te', 'ka', 'chinese_cht', 'hi', 'mr', 'ne'
] ]
assert character_type in support_character_type, "Only {} are supported now but get {}".format( assert character_type in support_character_type, "Only {} are supported now but get {}".format(
support_character_type, character_type) support_character_type, character_type)
...@@ -60,7 +62,7 @@ class BaseRecLabelDecode(object): ...@@ -60,7 +62,7 @@ class BaseRecLabelDecode(object):
def add_special_char(self, dict_character): def add_special_char(self, dict_character):
return dict_character return dict_character
def decode(self, text_index, text_prob=None, is_remove_duplicate=True): def decode(self, text_index, text_prob=None, is_remove_duplicate=False):
""" convert text-index into text-label. """ """ convert text-index into text-label. """
result_list = [] result_list = []
ignored_tokens = self.get_ignored_tokens() ignored_tokens = self.get_ignored_tokens()
...@@ -107,10 +109,10 @@ class CTCLabelDecode(BaseRecLabelDecode): ...@@ -107,10 +109,10 @@ class CTCLabelDecode(BaseRecLabelDecode):
preds_idx = preds.argmax(axis=2) preds_idx = preds.argmax(axis=2)
preds_prob = preds.max(axis=2) preds_prob = preds.max(axis=2)
text = self.decode(preds_idx, preds_prob) text = self.decode(preds_idx, preds_prob, is_remove_duplicate=True)
if label is None: if label is None:
return text return text
label = self.decode(label, is_remove_duplicate=False) label = self.decode(label)
return text, label return text, label
def add_special_char(self, dict_character): def add_special_char(self, dict_character):
......
a
r
b
i
c
_
m
g
/
1
0
I
L
S
V
R
C
2
v
l
6
3
9
.
j
p
ا
ل
م
ر
ج
و
ح
ي
ة
5
8
7
أ
ب
ض
4
ك
س
ه
ث
ن
ط
ع
ت
غ
خ
ف
ئ
ز
إ
د
ص
ظ
ذ
ش
ى
ق
ؤ
آ
ء
s
e
n
w
t
u
z
d
A
N
G
h
o
E
T
H
O
B
y
F
U
J
X
W
P
Z
M
k
q
Y
Q
D
f
K
x
'
%
-
#
@
!
&
$
,
:
é
?
+
É
(
b
e
_
i
m
g
/
2
0
I
L
S
V
R
C
1
v
a
l
6
9
4
3
.
j
p
п
а
з
б
у
г
н
ц
ь
8
м
л
і
о
ў
ы
7
5
М
х
с
р
ф
я
е
д
ж
ю
ч
й
к
Д
в
Б
т
І
ш
ё
э
К
Л
Н
А
Ж
Г
В
П
З
Е
О
Р
С
У
Ё
Й
Т
Ч
Э
Ц
Ю
Ш
Ф
Х
Я
Ь
Ы
Ў
s
c
n
w
M
o
t
T
E
A
B
u
h
y
k
r
H
d
Y
O
U
F
f
x
D
G
N
K
P
z
J
X
W
Z
Q
%
-
q
@
'
!
#
&
,
:
$
(
?
é
+
É
!
#
$
%
&
'
(
+
,
-
.
/
0
1
2
3
4
5
6
7
8
9
:
?
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
É
é
А
Б
В
Г
Д
Е
Ж
З
И
Й
К
Л
М
Н
О
П
Р
С
Т
У
Ф
Х
Ц
Ч
Ш
Щ
Ъ
Ю
Я
а
б
в
г
д
е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
Y
E
M
H
U
B
o
b
D
d
r
W
u
y
f
X
k
q
h
J
z
Z
Q
x
-
'
$
,
%
@
é
!
#
+
É
&
:
(
?
t
e
_
i
m
g
/
5
I
L
S
V
R
C
2
0
1
v
a
l
3
4
8
9
.
j
p
ి
7
6
'
[
;
-
,
|
?
:
"
(
!
+
)
*
=
&
]
£
$
s
c
n
w
k
J
G
u
d
r
E
o
h
y
b
f
B
M
O
T
N
D
P
A
F
x
W
Y
U
H
K
X
z
Z
Q
q
É
%
#
@
é
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment