Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
30279833
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
Star
32962
Fork
6643
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
108
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
108
Issue
108
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
30279833
编写于
1月 19, 2021
作者:
W
WenmuZhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tps 前反向对齐
上级
c3566221
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
15 deletion
+60
-15
ppocr/modeling/transforms/tps.py
ppocr/modeling/transforms/tps.py
+60
-15
未找到文件。
ppocr/modeling/transforms/tps.py
浏览文件 @
30279833
...
...
@@ -203,9 +203,9 @@ class GridGenerator(nn.Layer):
def
build_C_paddle
(
self
):
""" Return coordinates of fiducial points in I_r; C """
F
=
self
.
F
ctrl_pts_x
=
paddle
.
linspace
(
-
1.0
,
1.0
,
int
(
F
/
2
))
ctrl_pts_y_top
=
-
1
*
paddle
.
ones
([
int
(
F
/
2
)])
ctrl_pts_y_bottom
=
paddle
.
ones
([
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
)]
,
dtype
=
'float64'
)
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_bottom
=
paddle
.
stack
([
ctrl_pts_x
,
ctrl_pts_y_bottom
],
axis
=
1
)
C
=
paddle
.
concat
([
ctrl_pts_top
,
ctrl_pts_bottom
],
axis
=
0
)
...
...
@@ -213,12 +213,16 @@ class GridGenerator(nn.Layer):
def
build_P_paddle
(
self
,
I_r_size
):
I_r_height
,
I_r_width
=
I_r_size
I_r_grid_x
=
(
paddle
.
arange
(
-
I_r_width
,
I_r_width
,
2
).
astype
(
'float32'
)
+
1.0
)
/
I_r_width
# self.I_r_width
I_r_grid_y
=
(
paddle
.
arange
(
-
I_r_height
,
I_r_height
,
2
).
astype
(
'float32'
)
+
1.0
)
/
I_r_height
# self.I_r_height
I_r_grid_x
=
paddle
.
divide
(
paddle
.
arange
(
-
I_r_width
,
I_r_width
,
2
,
dtype
=
'float64'
)
+
1.0
,
paddle
.
to_tensor
(
I_r_width
,
dtype
=
'float64'
))
# / 2.2128224363981985e-08
I_r_grid_y
=
paddle
.
divide
(
paddle
.
arange
(
-
I_r_height
,
I_r_height
,
2
,
dtype
=
'float64'
)
+
1.0
,
paddle
.
to_tensor
(
I_r_height
,
dtype
=
'float64'
))
# self.I_r_height
# 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
.
transpose
(
P
,
perm
=
[
1
,
0
,
2
])
...
...
@@ -228,7 +232,7 @@ class GridGenerator(nn.Layer):
def
build_inv_delta_C_paddle
(
self
,
C
):
""" Return inv_delta_C which is needed to calculate T """
F
=
self
.
F
hat_C
=
paddle
.
zeros
((
F
,
F
),
dtype
=
'float
32
'
)
# F x F
hat_C
=
paddle
.
zeros
((
F
,
F
),
dtype
=
'float
64
'
)
# F x F
for
i
in
range
(
0
,
F
):
for
j
in
range
(
i
,
F
):
if
i
==
j
:
...
...
@@ -241,13 +245,21 @@ class GridGenerator(nn.Layer):
delta_C
=
paddle
.
concat
(
# F+3 x F+3
[
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
.
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
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
=
0
)
...
...
@@ -268,7 +280,9 @@ class GridGenerator(nn.Layer):
# rbf: n x F
rbf
=
paddle
.
multiply
(
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
def
get_expand_tensor
(
self
,
batch_C_prime
):
...
...
@@ -296,3 +310,34 @@ class TPS(nn.Layer):
[
-
1
,
image
.
shape
[
2
],
image
.
shape
[
3
],
2
])
batch_I_r
=
F
.
grid_sample
(
x
=
image
,
grid
=
batch_P_prime
)
return
batch_I_r
if
__name__
==
'__main__'
:
import
paddle
from
ppocr.utils.save_load
import
load_dygraph_pretrain
from
ppocr.utils.logging
import
get_logger
np
.
random
.
seed
(
0
)
img
=
np
.
random
.
random
((
1
,
3
,
32
,
100
)).
astype
(
np
.
float32
)
x
=
paddle
.
to_tensor
(
img
)
batch_P_prime
=
np
.
load
(
'/Users/zhoujun20/Desktop/code/static/PaddleOCR/output/tps1.npy'
)
batch_P_prime
=
paddle
.
to_tensor
(
batch_P_prime
)
model
=
TPS
(
in_channels
=
3
,
num_fiducial
=
20
,
loc_lr
=
0.1
,
model_name
=
'small'
)
load_dygraph_pretrain
(
model
,
get_logger
(),
'/Users/zhoujun20/Desktop/code/static/PaddleOCR/output/tps'
,
load_static_weights
=
True
)
model
.
eval
()
y
=
model
(
x
)
print
(
y
.
shape
)
static
=
np
.
load
(
'/Users/zhoujun20/Desktop/code/static/PaddleOCR/output/tps.npy'
)
print
(
static
.
dtype
,
y
.
numpy
().
dtype
,
static
.
shape
,
y
.
numpy
().
shape
)
diff
=
y
.
numpy
()
-
static
print
(
diff
.
max
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录