imgaug数据增强实例

2024-03-05 21:32
文章标签 数据 实例 增强 imgaug

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

 这里给出一个数据增强包imgaug的应用实例


可以简单修改数据路径即可运行程序,对数据进行增强,可以加上对文件夹下的dataset遍历,批处理数据增强。程序来源于Imgaug的github issues便通过做修改,运行于ubuntu,win10下数据写出有问题:

'see' command line parameter default in ubuntu

import imgaug as ia
from imgaug import augmenters as iaa
import numpy as np
import cv2im = cv2.imread('C:/Users/admin/Desktop/20130201_m007.jpg')
im = cv2.resize(im, (224,224)).astype(np.int8)
images = np.zeros([2,224,224,3])
images[0] = im# Sometimes(0.5, ...) applies the given augmenter in 50% of all cases,
# e.g. Sometimes(0.5, GaussianBlur(0.3)) would blur roughly every second image.
st = lambda aug: iaa.Sometimes(0.3, aug)# Define our sequence of augmentation steps that will be applied to every image
# All augmenters with per_channel=0.5 will sample one value _per image_
# in 50% of all cases. In all other cases they will sample new values
# _per channel_.
seq = iaa.Sequential([iaa.Fliplr(0.5), # horizontally flip 50% of all imagesiaa.Flipud(0.5), # vertically flip 50% of all imagesst(iaa.Superpixels(p_replace=(0, 1.0), n_segments=(20, 200))), # convert images into their superpixel representationst(iaa.Crop(percent=(0, 0.1))), # crop images by 0-10% of their height/widthst(iaa.GaussianBlur((0, 3.0))), # blur images with a sigma between 0 and 3.0st(iaa.Sharpen(alpha=(0, 1.0), )), # sharpen imagesst(iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0))), # emboss images# search either for all edges or for directed edgesst(iaa.Sometimes(0.5,iaa.EdgeDetect(alpha=(0, 0.7)),iaa.DirectedEdgeDetect(alpha=(0, 0.7), direction=(0.0, 1.0)),)),st(iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.2), per_channel=0.5)), # add gaussian noise to imagesst(iaa.Dropout((0.0, 0.1), per_channel=0.5)), # randomly remove up to 10% of the pixelsst(iaa.Invert(0.25, per_channel=True)), # invert color channelsst(iaa.Add((-10, 10), per_channel=0.5)), # change brightness of images (by -10 to 10 of original value)st(iaa.Multiply((0.5, 1.5), per_channel=0.5)), # change brightness of images (50-150% of original value)st(iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5)), # improve or worsen the contrastst(iaa.Affine(scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axistranslate_px={"x": (-16, 16), "y": (-16, 16)}, # translate by -16 to +16 pixels (per axis)rotate=(-45, 45), # rotate by -45 to +45 degreesshear=(-16, 16), # shear by -16 to +16 degreesorder=ia.ALL, # use any of scikit-image's interpolation methodscval=(0, 255), # if mode is constant, use a cval between 0 and 255mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples))),st(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)) # apply elastic transformations with random strengths],random_order=True # do all of the above in random order
)images_aug = seq.augment_images(images)
seq.show_grid(images[0], rows=8, cols=8)

 

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



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

相关文章

使用Python开发一个Ditto剪贴板数据导出工具

《使用Python开发一个Ditto剪贴板数据导出工具》在日常工作中,我们经常需要处理大量的剪贴板数据,下面将介绍如何使用Python的wxPython库开发一个图形化工具,实现从Ditto数据库中读... 目录前言运行结果项目需求分析技术选型核心功能实现1. Ditto数据库结构分析2. 数据库自动定位3

pandas数据的合并concat()和merge()方式

《pandas数据的合并concat()和merge()方式》Pandas中concat沿轴合并数据框(行或列),merge基于键连接(内/外/左/右),concat用于纵向或横向拼接,merge用于... 目录concat() 轴向连接合并(1) join='outer',axis=0(2)join='o

批量导入txt数据到的redis过程

《批量导入txt数据到的redis过程》用户通过将Redis命令逐行写入txt文件,利用管道模式运行客户端,成功执行批量删除以Product*匹配的Key操作,提高了数据清理效率... 目录批量导入txt数据到Redisjs把redis命令按一条 一行写到txt中管道命令运行redis客户端成功了批量删除k

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

解决pandas无法读取csv文件数据的问题

《解决pandas无法读取csv文件数据的问题》本文讲述作者用Pandas读取CSV文件时因参数设置不当导致数据错位,通过调整delimiter和on_bad_lines参数最终解决问题,并强调正确参... 目录一、前言二、问题复现1. 问题2. 通过 on_bad_lines=‘warn’ 跳过异常数据3

MySQL多实例管理如何在一台主机上运行多个mysql

《MySQL多实例管理如何在一台主机上运行多个mysql》文章详解了在Linux主机上通过二进制方式安装MySQL多实例的步骤,涵盖端口配置、数据目录准备、初始化与启动流程,以及排错方法,适用于构建读... 目录一、什么是mysql多实例二、二进制方式安装MySQL1.获取二进制代码包2.安装基础依赖3.清

C#监听txt文档获取新数据方式

《C#监听txt文档获取新数据方式》文章介绍通过监听txt文件获取最新数据,并实现开机自启动、禁用窗口关闭按钮、阻止Ctrl+C中断及防止程序退出等功能,代码整合于主函数中,供参考学习... 目录前言一、监听txt文档增加数据二、其他功能1. 设置开机自启动2. 禁止控制台窗口关闭按钮3. 阻止Ctrl +

java如何实现高并发场景下三级缓存的数据一致性

《java如何实现高并发场景下三级缓存的数据一致性》这篇文章主要为大家详细介绍了java如何实现高并发场景下三级缓存的数据一致性,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 下面代码是一个使用Java和Redisson实现的三级缓存服务,主要功能包括:1.缓存结构:本地缓存:使

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

Apache Ignite缓存基本操作实例详解

《ApacheIgnite缓存基本操作实例详解》文章介绍了ApacheIgnite中IgniteCache的基本操作,涵盖缓存获取、动态创建、销毁、原子及条件更新、异步执行,强调线程池注意事项,避免... 目录一、获取缓存实例(Getting an Instance of a Cache)示例代码:二、动态