您好,欢迎来到游6网!

当前位置:首页 > AI > 基于单字符纹理特征的打印文档溯源认证

基于单字符纹理特征的打印文档溯源认证

发布时间:2025-07-17    编辑:游乐网

该项目为飞桨黑客松武汉科技大学会场的“基于单字符纹理特征的打印文档溯源认证”。背景是打印文档仍广泛使用,存在篡改问题,可通过扫描转化为图像识别问题溯源。数据集经处理划分,用ResNet50模型,经数据增强、加载、训练(250轮等参数),单图和批量预测显示测试集准确率达0.948458221462859。

基于单字符纹理特征的打印文档溯源认证 - 游乐网

【PaddleX - 飞桨黑客松-武汉科技大学会场 】「基于单字符纹理特征的打印文档溯源认证 (¬‿¬)」

一、项目背景

       在过去几十年里,数字文档得到人们的大量使用。然而,安全问题、过渡成本等限制了打印文档到数字文档的完全过渡。这些限制使得许多财务和行政交易中继续使用印刷文件,如协议、契约、商业通信和记录保存。因此,数字文件和印刷文件得以共存。根据lian合国粮食及农业组织提供的2018年全球林产品事实和数据,2018年的印刷和书写纸的产量为9600万吨,自2014年以来一直保持稳定。大量的印刷文件需要快速和准确的数字系统来预测它们的起源和完整性。

        随着印刷设备的大量普及,一种新的违法行为也出现了:使用打印机进行篡改文档。以前不存在的合同条款,儿童色情和nue待动物的照片、威胁生命的信件、非法信件、恐怖主义阴谋、假货币等都随之而来,对社会造成了危害。

       由于印刷文档的特性,其可以被进行溯源调查。用于打印文档的打印机不仅可以帮助刑事调查,还可以保障在法律、行政和其他最新记录中的纸张的安全使用。近年来,使用数字技术对印刷文件的来源归因变得非常重要。传统的方法使用化学或显微镜技术,耗时,昂贵,甚至可能会损坏待测纸张,需要专家审查员。然而,如果对打印文档进行扫描工作,将其转化为涉及特征提取和分类的经典图像识别问题,那么在数字时代里,人们进行源打印机识溯源只需要一个扫描仪和计算机。

二、数据集简介

1. 数据集查看

In [ ]
# 数据集展示import matplotlib.pyplot as pltfrom PIL import Imagefrom random import shuffle%matplotlib inlinepath='work/real_dataset/train_list.txt'sample=dict()i=0label_set=set()with open(path,'r') as f:    line=f.readlines()    shuffle(line)    for l in line:         fpath, label = l.strip().split()[0],l.strip().split()[1]        # print(fpath,label)        if label not in label_set:            sample[fpath]=label            label_set.add(label)            i+=1            if i >=10:                breakplt.figure(figsize=(10,10))i=0for k,v in sample.items():    sample[k]=int(v)for k,v in sample.items():    plt.subplot(4,3,i+1)    i+=1    plt.imshow(Image.open(os.path.join('work/real_dataset',k)))    plt.title(v)    plt.axis('off')
登录后复制
登录后复制

基于单字符纹理特征的打印文档溯源认证 - 游乐网

图片显示,字母间的主要差异是在字母的边界和内部的一些区域(具有低梯度)。该图像通过卷积梯度纹理过滤器[1]获得。

2. 数据集加载

2.1 解压数据集

In [1]
!unzip -oq data/data122275/real_dataset.zip -d work/
登录后复制

2.2 数据集划分

In [ ]
# 验证集占0.2,测试集占0.1!paddlex --split_dataset --format ImageNet --dataset_dir work/real_dataset --val_value 0.2 --test_value 0.1
登录后复制

三、模型选择与开发

1. ResNet50简介

ResNet50 Backbone部分网络结构

基于单字符纹理特征的打印文档溯源认证 - 游乐网

随着网络深度增加,会出现一种退化问题,也就是当网络变得越来越深的时候,训练的准确率会趋于平缓,但是训练误差会变大,这明显不是过拟合造成的,因为过拟合是指网络的训练误差会不断变小,但是测试误差会变大。为了解决这种退化现象,ResNet被提出。

2. 安装依赖

In [ ]
!pip install paddlex==1.3.11
登录后复制
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleCollecting paddlex==1.3.11  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d6/a2/07435f4aa1e51fe22bdf06c95d03bf1b78b7bc6625adbb51e35dc0804cc7/paddlex-1.3.11-py3-none-any.whl (516kB)     |████████████████████████████████| 522kB 5.6MB/s eta 0:00:01Requirement already satisfied: psutil in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (5.7.2)Requirement already satisfied: shapely>=1.7.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (1.8.0)Requirement already satisfied: sklearn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (0.0)Requirement already satisfied: pycocotools; platform_system != "Windows" in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (2.0.3)Requirement already satisfied: visualdl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (2.2.2)Requirement already satisfied: opencv-python in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (4.1.1.26)Collecting xlwt (from paddlex==1.3.11)  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/44/48/def306413b25c3d01753603b1a222a011b8621aed27cd7f89cbc27e6b0f4/xlwt-1.3.0-py2.py3-none-any.whl (99kB)     |████████████████████████████████| 102kB 33.5MB/s ta 0:00:01Requirement already satisfied: colorama in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (0.4.4)Requirement already satisfied: pyyaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (5.1.2)Collecting paddleslim==1.1.1 (from paddlex==1.3.11)  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d1/77/e257227bed9a70ff0d35a4a3c4e70ac2d2362c803834c4c52018f7c4b762/paddleslim-1.1.1-py2.py3-none-any.whl (145kB)     |████████████████████████████████| 153kB 49.6MB/s eta 0:00:01Requirement already satisfied: flask-cors in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (3.0.8)Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex==1.3.11) (4.27.0)Collecting paddlehub==2.1.0 (from paddlex==1.3.11)  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7a/29/3bd0ca43c787181e9c22fe44b944b64d7fcb14ce66d3bf4602d9ad2ac76c/paddlehub-2.1.0-py3-none-any.whl (211kB)     |████████████████████████████████| 215kB 8.3MB/s eta 0:00:01Requirement already satisfied: scikit-learn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from sklearn->paddlex==1.3.11) (0.23.2)Requirement already satisfied: cython>=0.27.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools; platform_system != "Windows"->paddlex==1.3.11) (0.29)Requirement already satisfied: matplotlib>=2.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools; platform_system != "Windows"->paddlex==1.3.11) (2.2.3)Requirement already satisfied: setuptools>=18.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools; platform_system != "Windows"->paddlex==1.3.11) (41.4.0)Requirement already satisfied: numpy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (1.16.4)Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (1.1.1)Requirement already satisfied: shellcheck-py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (0.7.1.1)Requirement already satisfied: Pillow>=7.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (7.1.2)Requirement already satisfied: six>=1.14.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (1.15.0)Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (0.8.53)Requirement already satisfied: flake8>=3.7.9 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (3.8.2)Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (1.0.0)Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (3.14.0)Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (1.1.5)Requirement already satisfied: pre-commit in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (1.21.0)Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex==1.3.11) (2.22.0)Requirement already satisfied: pyzmq in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleslim==1.1.1->paddlex==1.3.11) (18.1.1)Requirement already satisfied: filelock in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlehub==2.1.0->paddlex==1.3.11) (3.0.12)Collecting paddle2onnx>=0.5.1 (from paddlehub==2.1.0->paddlex==1.3.11)  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/db/72/69812b9f56028f6ce46cf4d11540d40d75474b3ac861fcbf439b92877add/paddle2onnx-0.9.0-py3-none-any.whl (84kB)     |████████████████████████████████| 92kB 7.5MB/s eta 0:00:011Requirement already satisfied: packaging in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlehub==2.1.0->paddlex==1.3.11) (20.9)Requirement already satisfied: rarfile in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlehub==2.1.0->paddlex==1.3.11) (3.1)Requirement already satisfied: gitpython in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlehub==2.1.0->paddlex==1.3.11) (3.1.14)Requirement already satisfied: easydict in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlehub==2.1.0->paddlex==1.3.11) (1.9)Requirement already satisfied: gunicorn>=19.10.0; sys_platform != "win32" in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlehub==2.1.0->paddlex==1.3.11) (20.0.4)Requirement already satisfied: paddlenlp>=2.0.0rc5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlehub==2.1.0->paddlex==1.3.11) (2.1.1)Requirement already satisfied: colorlog in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlehub==2.1.0->paddlex==1.3.11) (4.1.0)Requirement already satisfied: scipy>=0.19.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->paddlex==1.3.11) (1.3.0)Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->paddlex==1.3.11) (0.14.1)Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->paddlex==1.3.11) (3.0.0)Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools; platform_system != "Windows"->paddlex==1.3.11) (1.1.0)Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools; platform_system != "Windows"->paddlex==1.3.11) (2.8.0)Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools; platform_system != "Windows"->paddlex==1.3.11) (2.4.2)Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools; platform_system != "Windows"->paddlex==1.3.11) (2019.3)Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools; platform_system != "Windows"->paddlex==1.3.11) (0.10.0)Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.0.0->paddlex==1.3.11) (2.11.0)Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.0.0->paddlex==1.3.11) (1.1.0)Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.0.0->paddlex==1.3.11) (0.16.0)Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.0.0->paddlex==1.3.11) (7.0)Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.0.0->paddlex==1.3.11) (3.9.9)Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.0.0->paddlex==1.3.11) (0.18.0)Requirement already satisfied: pycodestyle<2.7.0,>=2.6.0a1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.0.0->paddlex==1.3.11) (2.6.0)Requirement already satisfied: importlib-metadata; python_version < "3.8" in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.0.0->paddlex==1.3.11) (0.23)Requirement already satisfied: pyflakes<2.3.0,>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.0.0->paddlex==1.3.11) (2.2.0)Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.0.0->paddlex==1.3.11) (0.6.1)Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.0.0->paddlex==1.3.11) (2.8.0)Requirement already satisfied: cfgv>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.0.0->paddlex==1.3.11) (2.0.1)Requirement already satisfied: nodeenv>=0.11.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.0.0->paddlex==1.3.11) (1.3.4)Requirement already satisfied: toml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.0.0->paddlex==1.3.11) (0.10.0)Requirement already satisfied: aspy.yaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.0.0->paddlex==1.3.11) (1.3.0)Requirement already satisfied: virtualenv>=15.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.0.0->paddlex==1.3.11) (16.7.9)Requirement already satisfied: identify>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.0.0->paddlex==1.3.11) (1.4.10)Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.0.0->paddlex==1.3.11) (2.8)Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.0.0->paddlex==1.3.11) (1.25.6)Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.0.0->paddlex==1.3.11) (2019.9.11)Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.0.0->paddlex==1.3.11) (3.0.4)Collecting onnx<=1.9.0 (from paddle2onnx>=0.5.1->paddlehub==2.1.0->paddlex==1.3.11)  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/3f/9b/54c950d3256e27f970a83cd0504efb183a24312702deed0179453316dbd0/onnx-1.9.0-cp37-cp37m-manylinux2010_x86_64.whl (12.2MB)     |████████████████████████████████| 12.2MB 9.8MB/s eta 0:00:01Requirement already satisfied: gitdb<5,>=4.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from gitpython->paddlehub==2.1.0->paddlex==1.3.11) (4.0.5)Requirement already satisfied: h5py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp>=2.0.0rc5->paddlehub==2.1.0->paddlex==1.3.11) (2.9.0)Requirement already satisfied: jieba in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp>=2.0.0rc5->paddlehub==2.1.0->paddlex==1.3.11) (0.42.1)Requirement already satisfied: multiprocess in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp>=2.0.0rc5->paddlehub==2.1.0->paddlex==1.3.11) (0.70.11.1)Requirement already satisfied: seqeval in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp>=2.0.0rc5->paddlehub==2.1.0->paddlex==1.3.11) (1.2.2)Requirement already satisfied: paddlefsl==1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp>=2.0.0rc5->paddlehub==2.1.0->paddlex==1.3.11) (1.0.0)Requirement already satisfied: MarkupSafe>=0.23 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.0.0->paddlex==1.3.11) (1.1.1)Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->flake8>=3.7.9->visualdl>=2.0.0->paddlex==1.3.11) (3.6.0)Requirement already satisfied: typing-extensions>=3.6.2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from onnx<=1.9.0->paddle2onnx>=0.5.1->paddlehub==2.1.0->paddlex==1.3.11) (3.10.0.2)Requirement already satisfied: smmap<4,>=3.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from gitdb<5,>=4.0.1->gitpython->paddlehub==2.1.0->paddlex==1.3.11) (3.0.5)Requirement already satisfied: dill>=0.3.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from multiprocess->paddlenlp>=2.0.0rc5->paddlehub==2.1.0->paddlex==1.3.11) (0.3.3)ERROR: onnx 1.9.0 has requirement numpy>=1.16.6, but you'll have numpy 1.16.4 which is incompatible.Installing collected packages: xlwt, paddleslim, onnx, paddle2onnx, paddlehub, paddlex  Found existing installation: paddleslim 2.2.1    Uninstalling paddleslim-2.2.1:      Successfully uninstalled paddleslim-2.2.1  Found existing installation: paddlehub 2.0.4    Uninstalling paddlehub-2.0.4:      Successfully uninstalled paddlehub-2.0.4  Found existing installation: paddlex 2.1.0    Uninstalling paddlex-2.1.0:      Successfully uninstalled paddlex-2.1.0Successfully installed onnx-1.9.0 paddle2onnx-0.9.0 paddlehub-2.1.0 paddleslim-1.1.1 paddlex-1.3.11 xlwt-1.3.0
登录后复制

3. 模型训练

train.py主要代码

数据增强部分
train_transforms = transforms.Compose([    transforms.RandomCrop(crop_size=224, lower_scale=0.08, lower_ratio=3. / 4, upper_ratio=4. / 3),  # 随机剪裁    transforms.RandomHorizontalFlip(prob=0.5),# 随机水平翻转    transforms.RandomVerticalFlip(prob=0.5),# 随机垂直翻转    transforms.RandomRotate(rotate_range=30, prob=0.5), # 随机旋转    transforms.RandomDistort(brightness_range=0.9, brightness_prob=0.5, contrast_range=0.9, contrast_prob=0.5,                 saturation_range=0.9, saturation_prob=0.5, hue_range=18, hue_prob=0.5), # 以一定的概率对图像进行随机像素内容变换    transforms.Normalize() # 对图像进行标准化])eval_transforms = transforms.Compose([    transforms.ResizeByShort(short_size=256),    transforms.CenterCrop(crop_size=224),     transforms.Normalize()])
登录后复制装载数据集
train_dataset=pdx.datasets.ImageNet(    data_dir='work/real_dataset',     file_list='work/real_dataset/train_list.txt',    label_list='work/real_dataset/labels.txt',    transforms=train_transforms,    shuffle=True)eval_dataset = pdx.datasets.ImageNet(    data_dir='work/real_dataset',    file_list='work/real_dataset/val_list.txt',    label_list='work/real_dataset/labels.txt',    transforms=eval_transforms)test_dataset = pdx.datasets.ImageNet(    data_dir='work/real_dataset',    file_list='work/real_dataset/test_list.txt',    label_list='work/real_dataset/labels.txt',    transforms=eval_transforms)
登录后复制模型加载
model.train(num_epochs=250,    train_dataset=train_dataset,    train_batch_size=128,     lr_decay_epochs = [133,170,210], # 在133,170,210轮学习率衰减    eval_dataset=eval_dataset,    learning_rate=0.0025,    warmup_steps =9000, # 优化器的warmup步数,学习率将在设定的步数内,线性增长至设定的learning_rate    save_interval_epochs=20,    log_interval_steps=100,    save_dir='output/ResNet50',    #resume_checkpoint='output/ResNet50/epoch_150')
登录后复制In [ ]
# 进行训练!python train.py
登录后复制
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/setuptools/depends.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses  import imp2024-12-19 00:46:53 [INFO]Starting to read file list from dataset...2024-12-19 00:46:54 [INFO]172024 samples in file work/real_dataset/train_list.txt2024-12-19 00:46:54 [INFO]Starting to read file list from dataset...2024-12-19 00:46:55 [INFO]49142 samples in file work/real_dataset/val_list.txt2024-12-19 00:46:55 [INFO]Starting to read file list from dataset...2024-12-19 00:46:55 [INFO]24570 samples in file work/real_dataset/test_list.txt2024-12-19 00:46:57 [INFO]Downloading DarkNet53_ImageNet1k_pretrained.tar from https://paddle-imagenet-models-name.bj.bcebos.com/DarkNet53_ImageNet1k_pretrained.tar100%|████████████████████████████████| 162940/162940 [00:03<00:00, 53070.16KB/s]2024-12-19 00:47:00 [INFO]Decompressing output/DarkNet53/pretrain/DarkNet53_ImageNet1k_pretrained.tar...2024-12-19 00:47:02 [INFO]Load pretrain weights from output/DarkNet53/pretrain/DarkNet53_ImageNet1k_pretrained.2024-12-19 00:47:02 [WARNING][SKIP] Shape of pretrained weight output/DarkNet53/pretrain/DarkNet53_ImageNet1k_pretrained/fc_weights doesn't match.(Pretrained: (1024, 1000), Actual: (1024, 10))2024-12-19 00:47:02 [WARNING][SKIP] Shape of pretrained weight output/DarkNet53/pretrain/DarkNet53_ImageNet1k_pretrained/fc_offset doesn't match.(Pretrained: (1000,), Actual: (10,))2024-12-19 00:47:02 [INFO]There are 260 varaibles in output/DarkNet53/pretrain/DarkNet53_ImageNet1k_pretrained are loaded.
登录后复制

4.模型测试

4.1 单图预测

In [ ]
### 单图像预测import paddlex as pdxtest_jpg = 'work/real_dataset/B4070/class10110.png'model = pdx.load_model('output/ResNet50_vd_ssld/best_model')result = model.predict(test_jpg)print("Predict Result: ", result)
登录后复制

预测字符

基于单字符纹理特征的打印文档溯源认证 - 游乐网

真实标签ID:0
预测标签ID:0

4.2 批量预测

In [ ]
path='work/real_dataset'txt=path+'/'+'test_list.txt'file=open(txt)line=file.readline()right=0all=0while line:    png=line.strip().split()[0]    ans=line.strip().split()[1]    png_path=path+'/'+png    result = model.predict(png_path)    all+=1    if ans==str(result[0]['category_id']):        right+=1    line=file.readline()file.close()print(right/all)
登录后复制代码解释

测试集批量预测准确率:0.948458221462859

热门合集

MORE

+

MORE

+

变态游戏推荐

MORE

+

最新专题

MORE

+

热门游戏推荐

MORE

+

关于我们  |  游戏下载排行榜  |  专题合集  |  端游游戏  |  手机游戏  |  联系方式: youleyoucom@outlook.com

Copyright 2013-2019 www.youleyou.com    湘公网安备 43070202000716号

声明:游6网为非赢利性网站 不接受任何赞助和广告 湘ICP备2023003002号-9