用于tensorflow的图像增强库。所有操作都实现为纯tensorflow图操作。

tfAugmentor的Python项目详细描述


仍在建设中,即将推出

t增强器

用于tensorflow的图像增强库。所有操作都实现为纯tensorflow图操作。因此,tfaugmentor可以很容易地与任何tensorflow图(如tf.data)组合,用于实时数据增强。 对于cosurse,您还可以离线使用它来生成增强的数据集。

安装

tfaugment是用python编写的,可以通过以下方式轻松安装:

pipinstalltfAugmentor

要正确运行tfaugment,还应安装以下库:

  • Tensorflow(在TF 1.12下开发)
  • numpy(根据numpy 1.15开发)

快速启动

tfaugmentor的目标是将图像增强作为一个tensorflow图来实现,以便与其他tensorflow组件(如tf.data)无缝地结合使用。 但你也可以把它单独用作离线增强工具。

首先,实例化一个Augmentor对象并向其传递一个张量字典。这些张量应该具有相同的[batch, height, width, channels]的四维形状。

为了保持标签/分段映射的一致性,应该将相应的dict键作为列表传递给label

importtfAugmentorastfatensor_list={'images':image_tensor,'segmentation_mask':mask_tensor}aug1=tfa.Augmentor(tensor_list,label=['segmentation_mask'])

添加增强并获取输出张量:

aug1.flip_left_right(probability=0.5)# apply left right flip with probability 0.5out1=aug1.out

可以合并具有相同结构的多个增强函数,这意味着您可以并行多个管道

aug2=tfa.Augmentor(tensor_list,label=['segmentation_mask'])# another augmentor with the same input as aug1aug2.flip_up_down(probability=0.5)# apply up down flip this timeaug3=tfa.Augmentor(tensor_list,label=['segmentation_mask'])aug3.elastic_deform(probability=0.5,strength=1,scale=30)# elastic deformationout=aug1.merge([aug2,aug3])

tf.data

的示例

使用tf.data和tfaugment导入数据的示例:

ds=tf.data.TFRecordDataset([...])ds=ds.map(extract_fn)ds=ds.shuffle(buffer_size=500)ds=ds.batch(batch_size)iterator=dataset.make_one_shot_iterator()next_element=iterator.get_next()defextract_fn(sample):# parse the tfrecord example of your dataset....# assume the dataset contains three tensors: image, weight_map, seg_mask# instantiate an Augmentorinput_list={'img':image,'weight':weight_map,'mask':seg_mask}a=tfa.Augmentor(input_list,label=['segmentation_mask'])a.flip_left_right(probability=0.5)# apply left right flipa.random_rotate(probability=0.6)# apply random rotationa.elastic_deform(probability=0.2,strength=200,scale=20)# apply elastic deformation# dictionary of the augmented images, which has the same keys as input_listaugmented=a.out# return tensors in a form you needreturnaugmented['img'],augmented['weight'],augmented['mask']

主要功能

镜像

a.flip_left_right(probability)# flip the image left right  a.flip_up_down(probability)# flip the image up down

旋转

a.rotate90(probability)# rotate by 90 degree clockwisea.rotate180(probability)# rotate by 180 degree clockwisea.rotate270(probability)# rotate by 270 degree clockwisea.rotate(probability,angle)# rotate by *angel* degree clockwisea.random_rotate(probability)# randomly rotate the image

裁剪并调整大小

a.random_crop_resize(probability,scale_range=(0.5,0.8))# randomly crop a sub-image and resize to the same size of the original imagea.crop(probability,size)# randomly crop a sub-image of a certain size

弹性变形

a.elastic_deform(probability, strength, scale)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在数据库中插入行时自动发送电子邮件?   从进程输出读取的Java问题   java质疑StyledDocument和JTextPane之间的关系,以及接口的正确使用   java错误getPlayer(args[0]);   java如何使Spring引导在重新打包的WAR中包含清单文件?   Java中的除法与模   java使用2d数组和JfreeChart制作散点图   java扩展SonarQube FindBugs插件和自定义FindBugs插件   javaspring:hibernate+ehcache   具有不正确的equals和HashCode实现的java HashMap   java Jaspersoft报告网。旧金山。jasperreports。发动机例外:net。旧金山。jasperreports。发动机填满JRepressionEvalException:计算表达式时出错   java如果输入与其变量不匹配,如何添加错误   在java中使用简单数组[]实现队列   无法启动上下文路径/hsx上的java FAIL应用程序