# ImageDataAugmentor
ImageDataAugmentor is a custom image data generator for Keras supporting the use of modern augmentation modules (e.g. imgaug and albumentations).
**NOTICE!**
The code is heavily adapted from: https://github.com/keras-team/keras-preprocessing/blob/master/keras_preprocessing/
The usage is analogous to Keras' `ImageDataGenerator` with the exception that the image transformations will be generated with an external augmentations module.
To learn more about:
* ImageDataGenerator, see: https://keras.io/preprocessing/image/
* albumentations, see: https://github.com/albu/albumentations
* imgaug, see: https://github.com/aleju/imgaug
For similar projects, see:
* https://github.com/davidfreire/Augmentation_project <- a generator that accepts both external and Keras internal augmentations
> Example of using `.flow_from_directory(directory)` with `albumentations`:
from ImageDataAugmentor.image_data_augmentor import *
import albumentations
...
AUGMENTATIONS = albumentations.Compose([
albumentations.Transpose(p=0.5),
albumentations.Flip(p=0.5),
albumentations.OneOf([
albumentations.RandomBrightnessContrast(brightness_limit=0.3, contrast_limit=0.3),
albumentations.RandomBrightnessContrast(brightness_limit=0.1, contrast_limit=0.1)
],p=1),
albumentations.GaussianBlur(p=0.05),
albumentations.HueSaturationValue(p=0.5),
albumentations.RGBShift(p=0.5),
])
train_datagen = ImageDataAugmentor(
rescale=1./255,
augment = AUGMENTATIONS,
preprocess_input=None)
test_datagen = ImageDataAugmentor(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
'data/train',
target_size=(224, 224),
batch_size=32,
class_mode='binary')
validation_generator = test_datagen.flow_from_directory(
'data/validation',
target_size=(224, 224),
batch_size=32,
class_mode='binary')
model.fit_generator(
train_generator,
steps_per_epoch=len(train_generator),
epochs=50,
validation_data=validation_generator,
validation_steps=len(validation_generator))
> Example of using `.flow(x, y)` with `imgaug`:
from ImageDataAugmentor.image_data_augmentor import *
from imgaug import augmenters as iaa
import imgaug as ia
...
sometimes = lambda aug: iaa.Sometimes(0.5, aug)
AUGMENTATIONS = iaa.Sequential([
iaa.Fliplr(0.5), # horizontally flip 50% of all images
iaa.Flipud(0.2), # vertically flip 20% of all images
sometimes(iaa.Affine(
scale={"x": (0.9, 1.1), "y": (0.9, 1.1)}, # scale images to 90-110% of their size, individually per axis
translate_percent={"x": (-0.1, 0.1), "y": (-0.1, 0.1)}, # translate by -10 to +10 percent (per axis)
rotate=(-45, 45), # rotate by -45 to +45 degrees
shear=(-5, 5), # shear by -5 to +5 degrees
mode=ia.ALL # use any of scikit-image's warping modes
)
)],
random_order=True)
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
y_train = np_utils.to_categorical(y_train, num_classes)
y_test = np_utils.to_categorical(y_test, num_classes)
datagen = ImageDataAugmentor(
featurewise_center=True,
featurewise_std_normalization=True,
augment = AUGMENTATIONS)
# compute quantities required for featurewise normalization
datagen.fit(x_train)
# fits the model on batches with real-time data augmentation:
model.fit_generator(datagen.flow(x_train, y_train, batch_size=32),
steps_per_epoch=len(x_train) / 32, epochs=epochs)
> Example of using `.flow_from_directory()` with masks for segmentation with `albumentations` (\*):
from ImageDataAugmentor.image_data_augmentor import *
import albumentations
...
AUGMENTATIONS = albumentations.Compose([
albumentations.HorizontalFlip(p=0.5),
albumentations.ElasticTransform(),
])
img_data_gen = ImageDataAugmentor(augment=AUGMENTATIONS, augment_seed=123)
img_gen = img_data_gen.flow_from_directory('../data/images/', class_mode=None, shuffle=True, seed=123)
mask_data_gen = ImageDataAugmentor(augment=AUGMENTATIONS, augment_seed=123, augment_mode='mask')
mask_gen = mask_data_gen.flow_from_directory('../data/masks/', class_mode=None, shuffle=True, seed=123)
train_gen = zip(img_gen, mask_gen)
# Visualize images
k = 3
image_batch, mask_batch = next(train_gen)
fix, ax = plt.subplots(k,2, figsize=(k*2,10))
for i in range(k):
ax[i,0].imshow(image_batch[i,:,:,0])
ax[i,1].imshow(mask_batch[i,:,:,0])
plt.show()
(\*) Currently the segmentation masks should be generated using `albumentations` rather than `imgaug`. If you'd still wish to use `imgaug`, make sure that all augmentations are meaningful for both image and mask generation (e.g. no noise augmentations for masks!) and remember to call `.to_deterministic()` to ensure that both the images and the mask are augmented with same transformations.
<br /><br /><br />
CITE (BibTex):<br />
@misc{mjkvaak_aug,<br />
author = {Tukiainen, M.},<br />
title = {ImageDataAugmentor},<br />
year = {2019},<br />
publisher = {GitHub},<br />
journal = {GitHub repository},<br />
howpublished = {https://github.com/mjkvaak/ImageDataAugmentor/} <br />
}
没有合适的资源?快使用搜索试试~ 我知道了~
ICIAR2018_BACH_challenge1:ICIAR2018乳房癌组织学图像分类挑战
共59个文件
py:25个
sh:20个
pyc:6个
5星 · 超过95%的资源 需积分: 50 13 下载量 63 浏览量
2021-02-20
14:05:07
上传
评论 2
收藏 156KB ZIP 举报
温馨提示
ICIAR2018_BACH_challenge1 ICIAR2018乳腺癌组织学图像分类挑战
资源详情
资源评论
资源推荐
收起资源包目录
ICIAR2018_BACH_challenge1-master.zip (59个子文件)
ICIAR2018_BACH_challenge1-master
README.md 93B
ICIAR2018classification
1_preprocessing
divide_image_into_p600_s200.sh 782B
train_val_images_labels_wholeImage_byCase_73split.sh 848B
train_val_images_labels_p1400s100_byCase_73split.py 7KB
divide_image_into_p600_s200.py 4KB
train_val_images_labels_p600s200_byCase_73split.py 6KB
divide_image_into_p300s300.sh 782B
train_val_images_labels_p300s300_byCase_73split.py 6KB
train_val_images_labels_wholeImage_byCase_73split.py 4KB
divide_image_into_p300s300.py 4KB
divide_image_into_p1400s100.py 4KB
train_val_images_labels_p1400s100_byCase_73split.sh 863B
train_val_images_labels_p300s300_byCase_73split.sh 860B
divide_image_into_p1400s100.sh 785B
train_val_images_labels_p600s200_byCase_73split.sh 839B
3_predict_testset
pred_v4_resnet_p300s300.csv 501B
predict_ICIAR_testset_p600s200_resnet50_155epochs.py 5KB
predict_ICIAR_testset_patches300.sh 794B
predict_ICIAR_testset_p600s200_resnet50_155epochs.sh 845B
predict_ICIAR_testset_patches300.py 4KB
pred.csv 501B
predict_ICIAR_testset_patches1400.py 5KB
predict_ICIAR_testset_p1400s100_resnet50_155epochs.py 5KB
predict_ICIAR_testset_p1400s100_resnet50_155epochs.sh 848B
pred_v5_resnet_p600s200.csv 501B
predict_ICIAR_testset_patches1400.sh 797B
pred_v6_resnet_p1400s100.csv 501B
ImageDataAugmentor
numpy_array_iterator.py 9KB
LICENSE 2KB
utils.py 10KB
dataframe_iterator.py 14KB
README.md 6KB
__pycache__
dataframe_iterator.cpython-36.pyc 11KB
numpy_array_iterator.cpython-36.pyc 7KB
iterator.cpython-36.pyc 10KB
image_data_augmentor.cpython-36.pyc 24KB
utils.cpython-36.pyc 9KB
directory_iterator.cpython-36.pyc 6KB
iterator.py 12KB
image_data_augmentor.py 31KB
directory_iterator.py 7KB
2_models
ResNet50_wDropout_p1400s100_73split_5plus150epochs.py 5KB
ResNet50_wDropout_p300s300_73split_es_mc_100moreEpochs.sh 869B
ResNet50_wDropout_p600s200_73split_GPU.sh 873B
9layersCNN_p300s300_73split.sh 868B
9layersCNN_p1400s100_73split.sh 994B
ResNet50_wDropout_p300s300_73split_CPU.sh 809B
9layersCNN_p300s300_73split.py 3KB
ResNet50_wDropout_p600s200_73split_es_mc_100moreEpochs_GPU.sh 933B
2020_04_13_2152-plot_accuracy_and_loss.ipynb 68KB
InceptionV3_p300s300_73split.sh 925B
ResNet50_wDropout_p300s300_73split.py 4KB
ResNet50_wDropout_p600s200_73split.py 5KB
ResNet50_wDropout_p300s300_73split_es_mc_100moreEpochs.py 4KB
ResNet50_wDropout_p600s200_73split_CPU.sh 817B
InceptionV3_p300s300_73split.py 6KB
9layersCNN_p1400s100_73split.py 3KB
ResNet50_wDropout_p1400s100_73split_5plus150epochs_GPU.sh 921B
ResNet50_wDropout_p600s200_73split_es_mc_100moreEpochs.py 4KB
共 59 条
- 1
观察社
- 粉丝: 21
- 资源: 4689
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1