通用手写文字擦除A榜2,B榜第3方案

一、赛题背景

随着技术发展,OCR扫描在学习、办公等众多场景中被使用,通过技术和算法,对扫描获得的纸张文档上的手写笔迹还原修复,恢复文件本身的样子,使得人们的使用体验越来越便捷。上一期比赛,我们举办了试卷场景下的手写文字擦除,帮助学生党们擦除试卷上的笔迹。本次比赛,我们诚邀各位选手并拓宽场景:不限于试卷,对通用文件上的手写笔迹进行擦除后还原文件,帮助更多人解决扫描上的问题。

二、数据分析

本次比赛的数据集分别为两类,第一类是上期比赛使用的试卷类型图片1081张,第二类是包含手写字迹的类似PDF文档图片12万张左右。

缩减二类数据
首先考虑到二类图片的数量巨大,在有限显存下过大的训练数据集对精度的提高是有限的,其次观测到测试数据集的试卷类型图片所占比重是0.4,所以为了平衡两类型的数据,因此二类图片只选取了二十分之一(6346张)用作训练。

扩增一类数据
接着考虑到一类试卷类型图片的特征基本上都为边缘纹理信息(不管是印刷体,手写体还是批改符号),并且此类图片梯度计算对颜色的依赖性不强,而颜色本身,非常容易受到光照等因素的影响,同类的物体颜色有很多变化,所以颜色本身可能难以提供关键信息。所以将此类图片灰度化后加入原始数据集进行数据增强。最终训练集中此类图片总共是2162张图片(1081张原图+1081张灰度图)。也进一步的平衡了两类型的数据。一类图片的mask采用比赛baseline中mask.

三、模型设计

网络模型,是基于本次比赛的baseline进行了改进。

Refinement
首先参考了上一期手写文字擦除第一名的方案,将Refinement部分替换成了基于Non-Local的深度编解码网络。

Coarse-erasure
然后考虑到本次比赛有把推理时间算作指标,为了轻量化网络模型,所以在Coarse-erasure不再使用swin-T(经过对比swin-T的优化效果较小),而在最深层网络引入ASPP+CBAM,在skip connection处引入了SE attention,通过扩大感受野和注意力来增强特征提取。

模型:

扫描试卷怎么去噪点 opencv_深度学习

四、调参优化策略

损失函数:L1 loss function + BCE loss function;

学习率调度:StepDecay

训练大致分为三阶段:

第一阶段先从512x512的patch_size开始训练500Epoch,batch_size=4,lr=1e-4;

第二阶段再从256x256的patch_size开始训练500Epoch,batch_size=16,lr=5e-5;

第三阶段再从512x512的patch_size开始训练500Epoch,batch_size=2,lr=1e-5;

由于网络较深,为了模型真正收敛,后期模型改进后又多次进行多阶段的训练,没有最好只有更好,就是练!

五、测试细节

测试trick:
分块测试,为了减少预测的时间,把图像切分为768x768的小块进行预测。

六、文件

loss:定义损失函数
model:定义网络模型
dataloader.py: 加载数据脚本
predict.py: 测试脚本
train.py: 训练脚本

七、代码运行:

# 解压数据集文件
import os

!ls /home/aistudio/data/
!unzip -qo /home/aistudio/data/data167667/train_final.zip -d /home/aistudio/data/  #解压训练集
!unzip -qo /home/aistudio/data/data167820/test_dataset.zip -d /home/aistudio/data/  #解压测试集
!ls /home/aistudio/data/
print("load down")
data167667  data167820

训练模型

# step 1,
%cd ~
!python work/train.py \
    --modelsSavePath /home/aistudio/work/savepath1 \
    --batchSize 4 \
    --loadSize 512 \
    --lr 1e-4 \
    --num_epochs 500 \
    --lr_decay_iters 10 \
    --logPath /home/aistudio/work/log1
/home/aistudio
[09/06 15:46:24] idr INFO: Namespace(batchSize=10, dataRoot='/home/aistudio/data/', gamma=0.92, loadSize=512, logPath='/home/aistudio/work/log1', lr=0.0001, lr_decay_iters=1, mask_dir='mask', modelsSavePath='/home/aistudio/work/savepath1', net='idr', numOfWorkers=4, num_epochs=500, pretrained='/home/aistudio/work/STE_best.pdparams', seed=9421)
[09/06 15:46:24] idr INFO: ========> Random Seed: 9421
============== 200
==============>net use:  idr
W0906 15:46:24.349529  3894 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0906 15:46:24.353334  3894 device_context.cc:465] device: 0, cuDNN Version: 7.6.
loaded 
OK!
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/norm.py:653: UserWarning: When training, we now always track global mean and variance.
  "When training, we now always track global mean and variance.")
[09/06 15:48:04] idr INFO: [100/425500] Generator Loss of epoch1 is 0.34888, idr, mask,  Lr:0.0001
[09/06 15:49:40] idr INFO: [200/425500] Generator Loss of epoch1 is 0.34814, idr, mask,  Lr:0.0001
[09/06 15:51:16] idr INFO: [300/425500] Generator Loss of epoch1 is 0.34094, idr, mask,  Lr:0.0001
[09/06 15:52:52] idr INFO: [400/425500] Generator Loss of epoch1 is 0.33687, idr, mask,  Lr:0.0001
[09/06 15:54:29] idr INFO: [500/425500] Generator Loss of epoch1 is 0.34525, idr, mask,  Lr:0.0001
[09/06 15:56:06] idr INFO: [600/425500] Generator Loss of epoch1 is 0.34353, idr, mask,  Lr:0.0001
[09/06 15:57:42] idr INFO: [700/425500] Generator Loss of epoch1 is 0.33961, idr, mask,  Lr:0.0001
[09/06 15:59:19] idr INFO: [800/425500] Generator Loss of epoch1 is 0.34725, idr, mask,  Lr:0.0001
0 [1, 3, 4060, 2828] [1, 3, 4060, 2828]
[09/06 16:00:12] idr INFO: index:0 psnr: 39.12316740874206
1 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:12] idr INFO: index:1 psnr: 39.73780665177327
2 [1, 3, 759, 759] [1, 3, 759, 759]
[09/06 16:00:12] idr INFO: index:2 psnr: 56.21873531296796
3 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:12] idr INFO: index:3 psnr: 40.52212885557168
4 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:12] idr INFO: index:4 psnr: 41.56430428800155
5 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:13] idr INFO: index:5 psnr: 46.31855806228171
6 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:13] idr INFO: index:6 psnr: 49.45672306086962
7 [1, 3, 1106, 1106] [1, 3, 1106, 1106]
[09/06 16:00:13] idr INFO: index:7 psnr: 41.85389424028928
8 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:14] idr INFO: index:8 psnr: 45.59890998206253
9 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:14] idr INFO: index:9 psnr: 42.56992218052834
10 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:14] idr INFO: index:10 psnr: 39.46905200806042
11 [1, 3, 3968, 2992] [1, 3, 3968, 2992]
[09/06 16:00:17] idr INFO: index:11 psnr: 30.676958035124073
12 [1, 3, 1303, 1303] [1, 3, 1303, 1303]
[09/06 16:00:17] idr INFO: index:12 psnr: 36.596694232523916
13 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:17] idr INFO: index:13 psnr: 40.5513939328022
14 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:18] idr INFO: index:14 psnr: 44.06369456299479
15 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:18] idr INFO: index:15 psnr: 40.17776212768399
16 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:18] idr INFO: index:16 psnr: 42.24566474161308
17 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:18] idr INFO: index:17 psnr: 42.778629586488385
18 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:18] idr INFO: index:18 psnr: 41.28397635046352
19 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:19] idr INFO: index:19 psnr: 43.08305073768209
20 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:19] idr INFO: index:20 psnr: 37.99953224917441
21 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:19] idr INFO: index:21 psnr: 39.60650681925876
22 [1, 3, 881, 881] [1, 3, 881, 881]
[09/06 16:00:19] idr INFO: index:22 psnr: 34.69429418625743
23 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:19] idr INFO: index:23 psnr: 39.50363914077295
24 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:20] idr INFO: index:24 psnr: 40.751659676909014
25 [1, 3, 2004, 2700] [1, 3, 2004, 2700]
[09/06 16:00:21] idr INFO: index:25 psnr: 34.54854208486414
26 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:21] idr INFO: index:26 psnr: 39.04385596051836
27 [1, 3, 657, 657] [1, 3, 657, 657]
[09/06 16:00:21] idr INFO: index:27 psnr: 44.9736077587509
28 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:22] idr INFO: index:28 psnr: 41.68218015408904
29 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:22] idr INFO: index:29 psnr: 40.61206697167343
30 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:22] idr INFO: index:30 psnr: 43.60846574056669
31 [1, 3, 4096, 2824] [1, 3, 4096, 2824]
[09/06 16:00:25] idr INFO: index:31 psnr: 41.14815375047886
32 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:25] idr INFO: index:32 psnr: 41.69333354872684
33 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:25] idr INFO: index:33 psnr: 45.31000107783842
34 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:26] idr INFO: index:34 psnr: 42.63911867022572
35 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:26] idr INFO: index:35 psnr: 44.300953983979035
36 [1, 3, 871, 871] [1, 3, 871, 871]
[09/06 16:00:26] idr INFO: index:36 psnr: 35.43800884564381
37 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:26] idr INFO: index:37 psnr: 37.88577444252964
38 [1, 3, 3040, 3708] [1, 3, 3040, 3708]
[09/06 16:00:29] idr INFO: index:38 psnr: 32.40660057218592
39 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:29] idr INFO: index:39 psnr: 42.843663734081986
40 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:30] idr INFO: index:40 psnr: 41.9398567107216
41 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:30] idr INFO: index:41 psnr: 38.97470231198536
42 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:30] idr INFO: index:42 psnr: 40.06239614276901
43 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:30] idr INFO: index:43 psnr: 40.1852866514605
44 [1, 3, 1174, 1174] [1, 3, 1174, 1174]
[09/06 16:00:31] idr INFO: index:44 psnr: 31.746765780116974
45 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:31] idr INFO: index:45 psnr: 38.4916242456792
46 [1, 3, 3984, 2976] [1, 3, 3984, 2976]
[09/06 16:00:34] idr INFO: index:46 psnr: 30.50431826386677
47 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:34] idr INFO: index:47 psnr: 42.32445776242155
48 [1, 3, 3968, 3020] [1, 3, 3968, 3020]
[09/06 16:00:37] idr INFO: index:48 psnr: 32.18790341359288
49 [1, 3, 3984, 2988] [1, 3, 3984, 2988]
[09/06 16:00:40] idr INFO: index:49 psnr: 34.09978893579476
50 [1, 3, 767, 767] [1, 3, 767, 767]
[09/06 16:00:40] idr INFO: index:50 psnr: 35.762771639293945
51 [1, 3, 1288, 1288] [1, 3, 1288, 1288]
[09/06 16:00:41] idr INFO: index:51 psnr: 39.604834580712364
52 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:41] idr INFO: index:52 psnr: 41.10868693041454
53 [1, 3, 2988, 3856] [1, 3, 2988, 3856]
[09/06 16:00:43] idr INFO: index:53 psnr: 35.395368505099775
54 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:44] idr INFO: index:54 psnr: 37.855353239840426
55 [1, 3, 1114, 1114] [1, 3, 1114, 1114]
[09/06 16:00:44] idr INFO: index:55 psnr: 35.93459644732544
56 [1, 3, 794, 596] [1, 3, 794, 596]
[09/06 16:00:44] idr INFO: index:56 psnr: 41.36502948885183
57 [1, 3, 794, 596] [1, 3, 794, 596]
[09/06 16:00:45] idr INFO: index:57 psnr: 41.22497181496591
58 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:45] idr INFO: index:58 psnr: 41.1771169375382
59 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:45] idr INFO: index:59 psnr: 53.723152871972395
60 [1, 3, 1230, 1230] [1, 3, 1230, 1230]
[09/06 16:00:45] idr INFO: index:60 psnr: 39.797982964887396
61 [1, 3, 1015, 1015] [1, 3, 1015, 1015]
[09/06 16:00:46] idr INFO: index:61 psnr: 32.74303529740838
62 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:46] idr INFO: index:62 psnr: 47.082211241055745
63 [1, 3, 3984, 2896] [1, 3, 3984, 2896]
[09/06 16:00:49] idr INFO: index:63 psnr: 30.78206695277144
64 [1, 3, 556, 556] [1, 3, 556, 556]
[09/06 16:00:49] idr INFO: index:64 psnr: 36.01234149376034
65 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:49] idr INFO: index:65 psnr: 45.05396181166462
66 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:49] idr INFO: index:66 psnr: 43.88535125975919
67 [1, 3, 708, 708] [1, 3, 708, 708]
[09/06 16:00:49] idr INFO: index:67 psnr: 32.04842861330942
68 [1, 3, 1070, 1070] [1, 3, 1070, 1070]
[09/06 16:00:50] idr INFO: index:68 psnr: 36.048236069223904
69 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:50] idr INFO: index:69 psnr: 39.869729913710245
70 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:50] idr INFO: index:70 psnr: 37.56142861798856
71 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:50] idr INFO: index:71 psnr: 41.36228311035232
72 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:50] idr INFO: index:72 psnr: 42.49214643067096
73 [1, 3, 5172, 3816] [1, 3, 5172, 3816]
[09/06 16:00:56] idr INFO: index:73 psnr: 30.596045759070094
74 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:56] idr INFO: index:74 psnr: 41.7324371813889
75 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:56] idr INFO: index:75 psnr: 52.805572454555964
76 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:00:57] idr INFO: index:76 psnr: 39.46628623782252
77 [1, 3, 842, 596] [1, 3, 842, 596]
[09/06 16:00:57] idr INFO: index:77 psnr: 38.33035209573889
78 [1, 3, 1297, 1297] [1, 3, 1297, 1297]
[09/06 16:00:57] idr INFO: index:78 psnr: 35.88476210267104
79 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:57] idr INFO: index:79 psnr: 38.29374392004137
80 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:58] idr INFO: index:80 psnr: 45.68249357483042
81 [1, 3, 986, 986] [1, 3, 986, 986]
[09/06 16:00:58] idr INFO: index:81 psnr: 39.783151984843066
82 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:58] idr INFO: index:82 psnr: 48.663501304092414
83 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:00:58] idr INFO: index:83 psnr: 41.09503870588482
84 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:00:58] idr INFO: index:84 psnr: 37.15763933495202
85 [1, 3, 729, 729] [1, 3, 729, 729]
[09/06 16:00:59] idr INFO: index:85 psnr: 41.55915586645804
86 [1, 3, 2744, 2032] [1, 3, 2744, 2032]
[09/06 16:01:00] idr INFO: index:86 psnr: 32.34431039550687
87 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:00] idr INFO: index:87 psnr: 42.47196995301565
88 [1, 3, 842, 596] [1, 3, 842, 596]
[09/06 16:01:00] idr INFO: index:88 psnr: 49.6145290774711
89 [1, 3, 794, 596] [1, 3, 794, 596]
[09/06 16:01:01] idr INFO: index:89 psnr: 43.141009872204265
90 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:01] idr INFO: index:90 psnr: 37.390873354796014
91 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:01] idr INFO: index:91 psnr: 39.54044012165299
92 [1, 3, 1103, 1103] [1, 3, 1103, 1103]
[09/06 16:01:02] idr INFO: index:92 psnr: 41.862371551942715
93 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:02] idr INFO: index:93 psnr: 52.102838855435635
94 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:02] idr INFO: index:94 psnr: 47.947415960456865
95 [1, 3, 888, 888] [1, 3, 888, 888]
[09/06 16:01:02] idr INFO: index:95 psnr: 32.30235564065919
96 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:02] idr INFO: index:96 psnr: 43.114830882730715
97 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:03] idr INFO: index:97 psnr: 42.7166127286562
98 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:03] idr INFO: index:98 psnr: 46.46320665056153
99 [1, 3, 4060, 2876] [1, 3, 4060, 2876]
[09/06 16:01:06] idr INFO: index:99 psnr: 29.57304560646285
100 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:06] idr INFO: index:100 psnr: 40.9006170014121
101 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:06] idr INFO: index:101 psnr: 35.933039948188444
102 [1, 3, 842, 596] [1, 3, 842, 596]
[09/06 16:01:06] idr INFO: index:102 psnr: 48.118100559263574
103 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:06] idr INFO: index:103 psnr: 38.52994407389617
104 [1, 3, 1051, 1051] [1, 3, 1051, 1051]
[09/06 16:01:07] idr INFO: index:104 psnr: 36.15358207699672
105 [1, 3, 675, 477] [1, 3, 675, 477]
[09/06 16:01:07] idr INFO: index:105 psnr: 43.97884856102121
106 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:07] idr INFO: index:106 psnr: 41.46122604835584
107 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:07] idr INFO: index:107 psnr: 43.76644925586869
108 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:08] idr INFO: index:108 psnr: 44.04272538946916
109 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:08] idr INFO: index:109 psnr: 57.74405818291561
110 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:08] idr INFO: index:110 psnr: 40.54736091147766
111 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:08] idr INFO: index:111 psnr: 43.87633974230975
112 [1, 3, 997, 997] [1, 3, 997, 997]
[09/06 16:01:09] idr INFO: index:112 psnr: 41.87660798224179
113 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:09] idr INFO: index:113 psnr: 45.57233236770402
114 [1, 3, 893, 893] [1, 3, 893, 893]
[09/06 16:01:09] idr INFO: index:114 psnr: 38.268195997344975
115 [1, 3, 1272, 1272] [1, 3, 1272, 1272]
[09/06 16:01:10] idr INFO: index:115 psnr: 41.189364768434174
116 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:10] idr INFO: index:116 psnr: 45.51766327214424
117 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:10] idr INFO: index:117 psnr: 41.86261196900041
118 [1, 3, 556, 556] [1, 3, 556, 556]
[09/06 16:01:10] idr INFO: index:118 psnr: 35.21906446439075
119 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:10] idr INFO: index:119 psnr: 42.081887378002506
120 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:11] idr INFO: index:120 psnr: 41.00318055454181
121 [1, 3, 1291, 1291] [1, 3, 1291, 1291]
[09/06 16:01:11] idr INFO: index:121 psnr: 40.26645506694709
122 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:11] idr INFO: index:122 psnr: 39.22401343230594
123 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:11] idr INFO: index:123 psnr: 43.526822679170024
124 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:12] idr INFO: index:124 psnr: 39.39210577736621
125 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:12] idr INFO: index:125 psnr: 40.8342808479894
126 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:12] idr INFO: index:126 psnr: 41.69506456296408
127 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:12] idr INFO: index:127 psnr: 46.328708085948435
128 [1, 3, 573, 573] [1, 3, 573, 573]
[09/06 16:01:12] idr INFO: index:128 psnr: 46.49451696613617
129 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:13] idr INFO: index:129 psnr: 43.70494629119541
130 [1, 3, 1398, 1398] [1, 3, 1398, 1398]
[09/06 16:01:13] idr INFO: index:130 psnr: 35.7519672044886
131 [1, 3, 1430, 1430] [1, 3, 1430, 1430]
[09/06 16:01:14] idr INFO: index:131 psnr: 32.97227559190779
132 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:14] idr INFO: index:132 psnr: 40.06976637524395
133 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:14] idr INFO: index:133 psnr: 55.323322934504446
134 [1, 3, 645, 645] [1, 3, 645, 645]
[09/06 16:01:14] idr INFO: index:134 psnr: 25.79354731905834
135 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:14] idr INFO: index:135 psnr: 47.13832803156224
136 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:14] idr INFO: index:136 psnr: 41.90350763620758
137 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:15] idr INFO: index:137 psnr: 38.53646061887436
138 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:15] idr INFO: index:138 psnr: 46.87382033446596
139 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:15] idr INFO: index:139 psnr: 39.40803050861555
140 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:15] idr INFO: index:140 psnr: 39.35252124612021
141 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:16] idr INFO: index:141 psnr: 36.14028926758908
142 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:16] idr INFO: index:142 psnr: 41.951665193630426
143 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:16] idr INFO: index:143 psnr: 37.39161529561546
144 [1, 3, 2648, 1864] [1, 3, 2648, 1864]
[09/06 16:01:17] idr INFO: index:144 psnr: 34.20447256234717
145 [1, 3, 567, 567] [1, 3, 567, 567]
[09/06 16:01:17] idr INFO: index:145 psnr: 42.81732154939804
146 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:18] idr INFO: index:146 psnr: 45.21678359564274
147 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:18] idr INFO: index:147 psnr: 37.68631330864981
148 [1, 3, 1256, 1256] [1, 3, 1256, 1256]
[09/06 16:01:18] idr INFO: index:148 psnr: 35.85025882096241
149 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:19] idr INFO: index:149 psnr: 41.549630063394105
150 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:19] idr INFO: index:150 psnr: 47.78546367787346
151 [1, 3, 842, 596] [1, 3, 842, 596]
[09/06 16:01:19] idr INFO: index:151 psnr: 41.64881613368902
152 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:19] idr INFO: index:152 psnr: 48.38299151653686
153 [1, 3, 794, 596] [1, 3, 794, 596]
[09/06 16:01:19] idr INFO: index:153 psnr: 41.885842608582415
154 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:20] idr INFO: index:154 psnr: 37.82806651211091
155 [1, 3, 794, 596] [1, 3, 794, 596]
[09/06 16:01:20] idr INFO: index:155 psnr: 45.294859445416044
156 [1, 3, 864, 864] [1, 3, 864, 864]
[09/06 16:01:20] idr INFO: index:156 psnr: 44.53128074695094
157 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:20] idr INFO: index:157 psnr: 39.002173224562945
158 [1, 3, 2716, 2144] [1, 3, 2716, 2144]
[09/06 16:01:22] idr INFO: index:158 psnr: 35.62795253724735
159 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:22] idr INFO: index:159 psnr: 37.65165394181859
160 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:22] idr INFO: index:160 psnr: 39.706496077057785
161 [1, 3, 971, 971] [1, 3, 971, 971]
[09/06 16:01:23] idr INFO: index:161 psnr: 35.87918022707337
162 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:23] idr INFO: index:162 psnr: 43.69144896315276
163 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:23] idr INFO: index:163 psnr: 45.225624012249824
164 [1, 3, 2804, 2068] [1, 3, 2804, 2068]
[09/06 16:01:24] idr INFO: index:164 psnr: 34.94615117635754
165 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:25] idr INFO: index:165 psnr: 41.602804018064006
166 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:25] idr INFO: index:166 psnr: 41.70000750355101
167 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:25] idr INFO: index:167 psnr: 45.29255309470665
168 [1, 3, 794, 596] [1, 3, 794, 596]
[09/06 16:01:25] idr INFO: index:168 psnr: 50.3242744449294
169 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:25] idr INFO: index:169 psnr: 39.34297172010958
170 [1, 3, 842, 596] [1, 3, 842, 596]
[09/06 16:01:26] idr INFO: index:170 psnr: 42.946787475491554
171 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:26] idr INFO: index:171 psnr: 46.38395107650487
172 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:26] idr INFO: index:172 psnr: 42.47766061738099
173 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:26] idr INFO: index:173 psnr: 42.864285135371375
174 [1, 3, 842, 596] [1, 3, 842, 596]
[09/06 16:01:26] idr INFO: index:174 psnr: 37.21174669572365
175 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:27] idr INFO: index:175 psnr: 41.95926349263687
176 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:27] idr INFO: index:176 psnr: 41.427449911107644
177 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:27] idr INFO: index:177 psnr: 41.59022515061159
178 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:27] idr INFO: index:178 psnr: 41.94891798564385
179 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:27] idr INFO: index:179 psnr: 51.01548609315576
180 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:28] idr INFO: index:180 psnr: 38.70061126114004
181 [1, 3, 682, 682] [1, 3, 682, 682]
[09/06 16:01:28] idr INFO: index:181 psnr: 38.31449591964016
182 [1, 3, 1176, 1176] [1, 3, 1176, 1176]
[09/06 16:01:28] idr INFO: index:182 psnr: 43.12236176195298
183 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:29] idr INFO: index:183 psnr: 46.03886002026955
184 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:29] idr INFO: index:184 psnr: 45.093547713052864
185 [1, 3, 2984, 3988] [1, 3, 2984, 3988]
[09/06 16:01:32] idr INFO: index:185 psnr: 43.89869313955099
186 [1, 3, 1175, 1175] [1, 3, 1175, 1175]
[09/06 16:01:32] idr INFO: index:186 psnr: 40.8526608674172
187 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:32] idr INFO: index:187 psnr: 44.01129608327339
188 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:32] idr INFO: index:188 psnr: 37.75595807366984
189 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:33] idr INFO: index:189 psnr: 38.955481824521925
190 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:33] idr INFO: index:190 psnr: 40.35141965759828
191 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:33] idr INFO: index:191 psnr: 39.05312076264889
192 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:33] idr INFO: index:192 psnr: 41.003768285265814
193 [1, 3, 842, 596] [1, 3, 842, 596]
[09/06 16:01:33] idr INFO: index:193 psnr: 45.34882866034956
194 [1, 3, 2972, 3904] [1, 3, 2972, 3904]
[09/06 16:01:36] idr INFO: index:194 psnr: 34.43213224343949
195 [1, 3, 1527, 1000] [1, 3, 1527, 1000]
[09/06 16:01:36] idr INFO: index:195 psnr: 37.7466193506124
196 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:37] idr INFO: index:196 psnr: 37.17387073609066
197 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:37] idr INFO: index:197 psnr: 39.89629717122425
198 [1, 3, 792, 612] [1, 3, 792, 612]
[09/06 16:01:37] idr INFO: index:198 psnr: 49.3846214619217
199 [1, 3, 684, 548] [1, 3, 684, 548]
[09/06 16:01:37] idr INFO: index:199 psnr: 43.90796185457609
epoch:1, psnr:40.9594308354455
[09/06 16:01:38] idr INFO: epoch: 1, ave_psnr: 40.9594308354455, best_psnr: 40.9594308354455
[09/06 16:02:27] idr INFO: [900/425500] Generator Loss of epoch2 is 0.33865, idr, mask,  Lr:9.200000000000001e-05
[09/06 16:04:03] idr INFO: [1000/425500] Generator Loss of epoch2 is 0.34459, idr, mask,  Lr:9.200000000000001e-05
^C
Traceback (most recent call last):
  File "work/train.py", line 103, in <module>
    G_loss = criterion(imgs, masks, x_o1, x_o2, x_o3, fake_images, mm, gt, count, epoch)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 917, in __call__
    return self._dygraph_call_func(*inputs, **kwargs)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 907, in _dygraph_call_func
    outputs = self.forward(*inputs, **kwargs)
  File "/home/aistudio/work/loss/Loss.py", line 57, in forward
    holeLoss =  self.l1((1 - mask) * output, (1 - mask) * gt)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py", line 215, in __impl__
    return scalar_method(self, other_var)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py", line 175, in _scalar_rsub_
    return _scalar_elementwise_op_(var, -1.0, value)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py", line 109, in _scalar_elementwise_op_
    return _C_ops.scale(var, 'scale', scale, 'bias', bias)
KeyboardInterrupt
# step 2
%cd ~
!python work/train.py \
    --modelsSavePath savepath2 \
    --batchSize 16 \
    --loadSize 256 \
    --pretrained /home/aistudio/work/savepath1/best.pdparams \
    --lr 5e-5 \
    --num_epochs 500 \
    --lr_decay_iters 10 \
    --logPath /home/aistudio/work/log2
# step 3
%cd ~
!python work/train.py \
    --modelsSavePath savepath3 \
    --batchSize 2 \
    --loadSize 512 \
    --pretrained /home/aistudio/work/savepath2/best.pdparams \
    --lr 1e-5 \
    --num_epochs 500 \
    --lr_decay_iters 10 \
    --logPath /home/aistudio/work/log3

生成测试结果

%cd ~
!python work/predict.py /home/aistudio/data/dehw_testA_dataset /home/aistudio/work/resultA
#!python work/predict.py /home/aistudio/data/dehw_testB_dataset /home/aistudio/work/resultB
/home/aistudio
W0906 17:14:56.139024  2109 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0906 17:14:56.143882  2109 device_context.cc:465] device: 0, cuDNN Version: 7.6.
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
^C
Traceback (most recent call last):
  File "work/predict.py", line 104, in <module>
    process(src_image_dir, save_dir)
  File "work/predict.py", line 75, in process
    g_images_clip = g_images_clip.cpu()
KeyboardInterrupt
.objectis a deprecated alias for the builtinobject. To silence this warning, use object` by itself. Doing this will not modify any behavior and is safe.
 Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
 if data.dtype == np.object:
 ^C
 Traceback (most recent call last):
 File “work/predict.py”, line 104, in 
 process(src_image_dir, save_dir)
 File “work/predict.py”, line 75, in process
 g_images_clip = g_images_clip.cpu()
 KeyboardInterrupt