[英]Keras Data Augmentation (BreakHis)
My problem is to amplify the BreakHis dataset ( https://www.kaggle.com/ambarish/breakhis ) using the following instructions:我的问题是使用以下说明放大 BreakHis 数据集 ( https://www.kaggle.com/ambarish/breakhis ):
We chose the DC subclass as the baselihne, and amplified each of the remaining sublclasses by turning images up and down, left and right, and using counterclowise rotatiotion of 90 ° and 180 °.我们选择 DC 子类作为 baselihne,并通过上下左右转动图像并使用 90° 和 180° 的逆光旋转来放大剩余的每个子类。
Which instructions should I write in Keras to perform the data augmentation?我应该在 Keras 中编写哪些指令来执行数据增强? Obviously, I would like to understand how to do those operations in general.
显然,我想了解一般如何进行这些操作。
This is the distribution of the original dataset:这是原始数据集的分布:
This is the distribution of the augmented dataset:这是增强数据集的分布:
The following function will apply wanted operations with equal probability, if you want to apply more than 1 operation for an array you can alter the code.以下函数将以相等的概率应用想要的操作,如果您想对数组应用 1 个以上的操作,您可以更改代码。 We provide the number of augmentations to the code as augmentation_number and the image array.
我们为代码提供了增强的数量作为增强_数字和图像数组。 Then this function applies transformations on it.
然后这个函数对其应用转换。
import random
import numpy as np
def generate_rotated(array,augmentation_number):
m=0
All=[]
while m!=augmentation_number:
rand=random.random()
if rand<=0.25:
Array=np.rot90(array)
elif 0.25<rand and rand<=0.5:
Array=np.rot90(array,2)
elif 0.5<rand and rand<=0.75:
Array=np.flipud(array)
else:
Array=np.fliplr(array)
All.append(Array)
m+=1
AugmentedArrays=np.array(All)
return AugmentedArrays
Edit function: -Also if you want to implement a function with %50 probability you can create it like this:编辑功能:-此外,如果您想以 %50 的概率实现一个功能,您可以像这样创建它:
def generate_rotated(array,augmentation_number):
m=0
All=[]
while m!=augmentation_number:
rand=random.random()
if rand<0.5:
Array=np.rot90(array)
rand=random.random()
if rand<0.5:
Array=np.rot90(array,2)
rand=random.random()
if rand<0.5:
Array=np.flipud(array)
rand=random.random()
if rand<0.5:
Array=np.fliplr(array)
All.append(Array)
m+=1
AugmentedArrays=np.array(All)
return AugmentedArrays
Example using:使用示例:
array=np.array([[12,323,2332],[2323,23452,5195],[95310,450,3]])
generate_rotated(array,5).shape=(5, 3, 3)
generate_rotated(array,5)
I hope this answers your question.我希望这回答了你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.