Paddleocr数据增强调用逻辑

2024-06-19 09:04

本文主要是介绍Paddleocr数据增强调用逻辑,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

数据增强调用逻辑

以在ppocr/data/simple_dataset.py为例:

get_ext_data通过self.ops[:self.ext_op_transform_idx]获取配置文件中数据增强

 self.ops在def __init__(self, config, mode, logger, seed=None):中通过解析配置文件中'transforms'内容获取数据增强操作:

self.ops = create_operators(dataset_config['transforms'], global_config)

 然后调用 data = transform(data, load_data_ops)实现数据增强。

 def get_ext_data(self):ext_data_num = 0for op in self.ops:if hasattr(op, 'ext_data_num'):ext_data_num = getattr(op, 'ext_data_num')breakload_data_ops = self.ops[:self.ext_op_transform_idx]ext_data = []while len(ext_data) < ext_data_num:file_idx = self.data_idx_order_list[np.random.randint(self.__len__())]data_line = self.data_lines[file_idx]data_line = data_line.decode('utf-8')substr = data_line.strip("\n").split(self.delimiter)file_name = substr[0]file_name = self._try_parse_filename_list(file_name)label = substr[1]img_path = os.path.join(self.data_dir, file_name)data = {'img_path': img_path, 'label': label}if not os.path.exists(img_path):continuewith open(data['img_path'], 'rb') as f:img = f.read()data['image'] = imgdata = transform(data, load_data_ops)if data is None:continueif 'polys' in data.keys():if data['polys'].shape[1] != 4:continueext_data.append(data)return ext_data

 

数据增强实现的细节:

代码来自ppocr/data/imaug/__init__.py

1、trainsform函数将数据增强数组逐个对数据输出数据列表

def transform(data, ops=None):""" transform """if ops is None:ops = []for op in ops:data = op(data)if data is None:return Nonereturn data

op(data)为什么能进行数据增强:

 每一个op是eval(op_name)(**param),eval() 函数将字符串 expression 解析为 Python 表达式,并在指定的命名空间中执行它。

def create_operators(op_param_list, global_config=None):"""create operators based on the configArgs:params(list): a dict list, used to create some operators"""assert isinstance(op_param_list, list), ('operator config should be a list')ops = []for operator in op_param_list:assert isinstance(operator,dict) and len(operator) == 1, "yaml format error"op_name = list(operator)[0]param = {} if operator[op_name] is None else operator[op_name]if global_config is not None:param.update(global_config)op = eval(op_name)(**param)ops.append(op)return ops

例如配置文件中的:

CopyPaste: null

通过ppocr/data/imaug/__init__.py,eval()可以调用CopyPaste实现数据增强

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literalsfrom .iaa_augment import IaaAugment
from .make_border_map import MakeBorderMap
from .make_shrink_map import MakeShrinkMap
from .random_crop_data import EastRandomCropData, RandomCropImgMask
from .make_pse_gt import MakePseGtfrom .rec_img_aug import BaseDataAugmentation, RecAug, RecConAug, RecResizeImg, ClsResizeImg, \SRNRecResizeImg, GrayRecResizeImg, SARRecResizeImg, PRENResizeImg, \ABINetRecResizeImg, SVTRRecResizeImg, ABINetRecAug, VLRecResizeImg, SPINRecResizeImg, RobustScannerRecResizeImg, \RFLRecResizeImg, SVTRRecAug, ParseQRecAug
from .ssl_img_aug import SSLRotateResize
from .randaugment import RandAugment
from .copy_paste import CopyPaste
from .ColorJitter import ColorJitter
from .operators import *
from .label_ops import *from .east_process import *
from .sast_process import *
from .pg_process import *
from .table_ops import *from .vqa import *from .fce_aug import *
from .fce_targets import FCENetTargets
from .ct_process import *
from .drrg_targets import DRRGTargets

这篇关于Paddleocr数据增强调用逻辑的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1074590

相关文章

【服务器运维】MySQL数据存储至数据盘

查看磁盘及分区 [root@MySQL tmp]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical)

SQL Server中,查询数据库中有多少个表,以及数据库其余类型数据统计查询

sqlserver查询数据库中有多少个表 sql server 数表:select count(1) from sysobjects where xtype='U'数视图:select count(1) from sysobjects where xtype='V'数存储过程select count(1) from sysobjects where xtype='P' SE

数据时代的数字企业

1.写在前面 讨论数据治理在数字企业中的影响和必要性,并介绍数据治理的核心内容和实践方法。作者强调了数据质量、数据安全、数据隐私和数据合规等方面是数据治理的核心内容,并介绍了具体的实践措施和案例分析。企业需要重视这些方面以实现数字化转型和业务增长。 数字化转型行业小伙伴可以加入我的星球,初衷成为各位数字化转型参考库,星球内容每周更新 个人工作经验资料全部放在这里,包含数据治理、数据要

如何在Java中处理JSON数据?

如何在Java中处理JSON数据? 大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!今天我们将探讨在Java中如何处理JSON数据。JSON(JavaScript Object Notation)作为一种轻量级的数据交换格式,在现代应用程序中被广泛使用。Java通过多种库和API提供了处理JSON的能力,我们将深入了解其用法和最佳

两个基因相关性CPTAC蛋白组数据

目录 蛋白数据下载 ①蛋白数据下载 1,TCGA-选择泛癌数据  2,TCGA-TCPA 3,CPTAC(非TCGA) ②蛋白相关性分析 1,数据整理 2,蛋白相关性分析 PCAS在线分析 蛋白数据下载 CPTAC蛋白组学数据库介绍及数据下载分析 – 王进的个人网站 (jingege.wang) ①蛋白数据下载 可以下载泛癌蛋白数据:UCSC Xena (xena

中国341城市生态系统服务价值数据集(2000-2020年)

生态系统服务反映了人类直接或者间接从自然生态系统中获得的各种惠益,对支撑和维持人类生存和福祉起着重要基础作用。目前针对全国城市尺度的生态系统服务价值的长期评估还相对较少。我们在Xie等(2017)的静态生态系统服务当量因子表基础上,选取净初级生产力,降水量,生物迁移阻力,土壤侵蚀度和道路密度五个变量,对生态系统供给服务、调节服务、支持服务和文化服务共4大类和11小类的当量因子进行了时空调整,计算了

ScrollView 非手动调用的方法

1. /**  *  非人为的时候调用这个方法  *  *  @param scrollView <#scrollView description#>  */ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {           } 2.判断控制器的view是否加载过 [willShowVC

【计算机网络篇】数据链路层(12)交换机式以太网___以太网交换机

文章目录 🍔交换式以太网🛸以太网交换机 🍔交换式以太网 仅使用交换机(不使用集线器)的以太网就是交换式以太网 🛸以太网交换机 以太网交换机本质上就是一个多接口的网桥: 交换机的每个接口考研连接计算机,也可以理解集线器或另一个交换机 当交换机的接口与计算机或交换机连接时,可以工作在全双工方式,并能在自身内部同时连通多对接口,使每一对相互通信的计算机都能像

使用Jsoup抓取数据

问题 最近公司的市场部分布了一个问题,到一个网站截取一下医院的数据。刚好我也被安排做。后来,我发现为何不用脚本去抓取呢? 抓取的数据如下: Jsoup的使用实战代码 结构 Created with Raphaël 2.1.0 开始 创建线程池 jsoup读取网页 解析Element 写入sqlite 结束

Excel实用技巧——二级下拉菜单、数据验证

EXCEL系列文章目录   Excel系列文章是本人亲身经历职场之后萌发的想法,为什么Excel覆盖如此之广,几乎每个公司、学校、家庭都在使用,但是它深藏的宝藏功能却很少被人使用,PQ、BI这些功能同样适用于数据分析;并且在一些需要简单及时的数据分析项目前,Excel是完胜python、R、SPSS这些科学专业的软件的。因此决心开启Excel篇章。 数据分析为什么要学Excel Excel图表