Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
328 commits
Select commit Hold shift + click to select a range
89c3f0a
experiment logs added
Feb 4, 2019
aa29f32
latest experiment analyzed, overfitting augmentation results are inte…
barisozmen Feb 4, 2019
804a6d4
portion vs accuracy figure added
barisozmen Feb 4, 2019
0607904
notebook.py refactoring
barisozmen Feb 4, 2019
2581249
augmenter now behaves deterministic if portion of augmented data is 1
barisozmen Feb 4, 2019
ec86e08
experiments recent results
Feb 4, 2019
95ac8b7
recent experiments
Feb 4, 2019
3592f00
validation set now refreshed for each child model training
barisozmen Feb 4, 2019
bb6b292
Merge branch 'triple-aug' of https://github.com/barisozmen/deepaugmen…
Feb 4, 2019
414794f
new experiments
Feb 4, 2019
be48a82
Merge pull request #17 from barisozmen/bayesian-opt
barisozmen Feb 5, 2019
ea23085
Update README.md
barisozmen Feb 5, 2019
1044f3f
Update README.md
barisozmen Feb 5, 2019
e9034e0
Update README.md
barisozmen Feb 5, 2019
3d90716
Update README.md
barisozmen Feb 5, 2019
eed5e3d
Update README.md
barisozmen Feb 5, 2019
758a0d2
Update README.md
barisozmen Feb 5, 2019
044cc91
Update README.md
barisozmen Feb 5, 2019
85ebc8b
experiment
Feb 5, 2019
7267fe3
new experiment
Feb 5, 2019
f57c6e4
5 new augmentation types added
barisozmen Feb 5, 2019
cab7461
new augmentations added to main script
barisozmen Feb 5, 2019
cee0ce1
image-generator special to deepaugment implemented
barisozmen Feb 5, 2019
6776b77
notebooks changes
barisozmen Feb 5, 2019
b7b48b0
Merge branch 'triple-aug' into bayesian-opt
barisozmen Feb 5, 2019
07997a5
augmentation-chain lenght decreased to two from three
barisozmen Feb 5, 2019
498df3c
Merge branch 'twice-out' into bayesian-opt
barisozmen Feb 5, 2019
8529902
recent experiment
Feb 5, 2019
4f94e41
experiment added
Feb 5, 2019
50df9b2
refactoring
barisozmen Feb 6, 2019
32a2924
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 6, 2019
843b8bc
GammaContrast normalization bug fixed
barisozmen Feb 6, 2019
37f5bb0
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 6, 2019
d6cc08d
deepaugment can now run the grownup model
barisozmen Feb 6, 2019
66c3a06
grownup model
barisozmen Feb 6, 2019
4ccf80d
new experiment
Feb 6, 2019
b489ae0
experiment added
Feb 6, 2019
3257d67
Merge branch 'experiment' of https://github.com/barisozmen/aerial-aut…
barisozmen Feb 6, 2019
82ed3d0
top10 policy getter implemented
barisozmen Feb 6, 2019
079eb3d
name-change
barisozmen Feb 6, 2019
4f46333
Merge branch 'name-change' into bayesian-opt
barisozmen Feb 6, 2019
b27d634
experiments cleaned
barisozmen Feb 6, 2019
110af5c
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugment
Feb 6, 2019
9ba403d
library added
barisozmen Feb 6, 2019
5f46565
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 6, 2019
3ffdc22
typo fixed
barisozmen Feb 6, 2019
6f87b64
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 6, 2019
8b8910d
elastic-transform deprecated
barisozmen Feb 6, 2019
f776e6c
assertions added to catch invalid transformations
barisozmen Feb 6, 2019
a550f78
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 6, 2019
dd31938
small bug fixed
barisozmen Feb 6, 2019
49a23d5
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 6, 2019
d50a916
after transform assertions now tolerate slight float numerical overflows
barisozmen Feb 6, 2019
cd12391
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 6, 2019
edcbb49
clip vals for perspective transform
barisozmen Feb 7, 2019
2af9d3e
perspective transform deprecated
barisozmen Feb 7, 2019
5a0b829
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 7, 2019
a108d34
grownup model is now runnable with augmented data
barisozmen Feb 7, 2019
12ac17b
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 7, 2019
303d5d5
top10 policies
barisozmen Feb 7, 2019
7627cda
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugm…
Feb 7, 2019
dcd28db
transform parameters tuned
barisozmen Feb 7, 2019
4d7e672
new experiment
Feb 7, 2019
47224cd
Merge branch 'bayesian-opt' of https://github.com/barisozmen/aerial-a…
barisozmen Feb 7, 2019
b3a4fcf
refactoring
barisozmen Feb 7, 2019
57ce06e
typo fixed
barisozmen Feb 7, 2019
63fb868
cutout script
barisozmen Feb 7, 2019
c6ace6b
bug fixed
barisozmen Feb 7, 2019
f63bcdf
full model training experiment added
Feb 7, 2019
f37f3fc
debug
barisozmen Feb 7, 2019
8e0ec1e
run_grownup_model.py renamed
barisozmen Feb 7, 2019
f9d7909
Merge branch 'bayesian-opt' of https://github.com/barisozmen/aerial-a…
barisozmen Feb 7, 2019
23b690d
Merge branch 'debug' into bayesian-opt
barisozmen Feb 7, 2019
861bcd6
get_top_policies() func refactored
barisozmen Feb 8, 2019
a30d597
grayscale augmentation added
barisozmen Feb 8, 2019
0802db5
refactoring
barisozmen Feb 8, 2019
b04c5cc
deletions
barisozmen Feb 8, 2019
de1f442
Merge pull request #19 from barisozmen/bayesian-opt
barisozmen Feb 8, 2019
445e440
Merge branch 'master' of https://github.com/barisozmen/aerial-autoaug…
barisozmen Feb 8, 2019
27b59e6
make pip installable
barisozmen Feb 8, 2019
09486d9
refactoring
barisozmen Feb 8, 2019
bae5fa0
refactir
barisozmen Feb 8, 2019
f711dfe
Merge branch 'bayesian-opt' of https://github.com/barisozmen/deepaugment
barisozmen Feb 8, 2019
968658a
Merge branch 'make-pip-installable' of https://github.com/barisozmen/…
barisozmen Feb 8, 2019
e17f31e
requirements update
barisozmen Feb 8, 2019
f001006
requirements updated
barisozmen Feb 8, 2019
970a89c
Update README.md
barisozmen Feb 10, 2019
cd7ac84
notebook added
barisozmen Feb 10, 2019
aa363e8
code formatted by black
barisozmen Feb 10, 2019
6738fdd
Update README.md
barisozmen Feb 10, 2019
6d89dd6
code re-designed
barisozmen Feb 10, 2019
7ca8fec
three figures added
barisozmen Feb 10, 2019
66d2a08
figure update
barisozmen Feb 10, 2019
0acd773
Update README.md
barisozmen Feb 10, 2019
b237091
Update README.md
barisozmen Feb 10, 2019
ddf6d5d
Update README.md
barisozmen Feb 10, 2019
79f995e
bugs sourced by new design are fixed
barisozmen Feb 11, 2019
e4981c8
new figures added
barisozmen Feb 11, 2019
0734ddf
child-CNN figure
barisozmen Feb 11, 2019
d4e7c2f
Merge branch 'refactoring' of https://github.com/barisozmen/deepaugme…
barisozmen Feb 11, 2019
6101d0a
documentations added
barisozmen Feb 11, 2019
ab034c8
Merge branch 'refactoring'
barisozmen Feb 11, 2019
d7f5ad1
new modules for running and objective function
barisozmen Feb 11, 2019
91b69c6
Merge branch 'refactoring'
barisozmen Feb 11, 2019
c3cc5a6
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 11, 2019
e8c12d4
concise workflow figure added
barisozmen Feb 11, 2019
38c1531
figure name typo fixed
barisozmen Feb 11, 2019
cfd236e
Update README.md
barisozmen Feb 11, 2019
1a854bf
Update README.md
barisozmen Feb 11, 2019
9664c5e
Update README.md
barisozmen Feb 11, 2019
1ed8f91
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 11, 2019
b0983fc
notebook modified
barisozmen Feb 11, 2019
b65b316
Update README.md
barisozmen Feb 11, 2019
14469c3
Update README.md
barisozmen Feb 11, 2019
f578eb8
Update README.md
barisozmen Feb 11, 2019
c54461e
Update README.md
barisozmen Feb 11, 2019
966bb06
Update README.md
barisozmen Feb 11, 2019
bc90efd
Update README.md
barisozmen Feb 11, 2019
62bfdbd
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 11, 2019
b61b655
figure updates
barisozmen Feb 11, 2019
24a6495
new experiments added
barisozmen Feb 11, 2019
bfc2a2e
changes on comparison notebook
barisozmen Feb 11, 2019
7222b0e
best policies put under reports
barisozmen Feb 11, 2019
1298299
Update README.md
barisozmen Feb 11, 2019
c16ae7b
Update README.md
barisozmen Feb 11, 2019
b37ea24
Update README.md
barisozmen Feb 11, 2019
62184c7
Update README.md
barisozmen Feb 11, 2019
d632929
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 11, 2019
57e8ba8
docs changes
barisozmen Feb 11, 2019
991ca09
docs added
barisozmen Feb 11, 2019
14d9525
conf import links changed
barisozmen Feb 11, 2019
ccf3189
some libs mocked in docs
barisozmen Feb 11, 2019
0a3aecf
html docs added
barisozmen Feb 11, 2019
8a8ac35
reports folder deleted
barisozmen Feb 11, 2019
45c7707
import method changes. Now modules first insert /deepaugment path to …
barisozmen Feb 11, 2019
7ffa16d
requirements only for development are spinned-off as requirements-dev
barisozmen Feb 11, 2019
291d5b6
version incremented
barisozmen Feb 11, 2019
adb6173
refactoring
barisozmen Feb 11, 2019
8d8e97d
numpy version not given anymore
barisozmen Feb 11, 2019
1c0b819
version in setup.py bumped
barisozmen Feb 11, 2019
a16d3a7
__init__.py added inside /lib folder in order to be found by setuptoo…
barisozmen Feb 11, 2019
02ac2a7
Update README.md
barisozmen Feb 11, 2019
e83007c
Update README.md
barisozmen Feb 11, 2019
a681347
conf.py paths are now relative
barisozmen Feb 11, 2019
6835c4f
readme modified
barisozmen Feb 11, 2019
1ca5007
Update README.md
barisozmen Feb 11, 2019
b0bf41c
requirements.txt file imgaug version improved
barisozmen Feb 12, 2019
4b07ae1
README update
barisozmen Feb 12, 2019
a429f27
setup version bumped
barisozmen Feb 12, 2019
d821434
code formatted by black
barisozmen Feb 12, 2019
5fd821f
documentation
barisozmen Feb 12, 2019
fdd34b5
code refactored following codacy suggestions
barisozmen Feb 12, 2019
728c30a
tensorflow and keras added to requirements.txt
barisozmen Feb 12, 2019
32667cf
Update README.md
barisozmen Feb 12, 2019
2f94d4e
Update README.md
barisozmen Feb 12, 2019
13bfaf1
Update README.md
barisozmen Feb 12, 2019
d95f69b
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 12, 2019
ce314e5
.h5 file deleted
barisozmen Feb 12, 2019
c9503d4
Update README.md
barisozmen Feb 13, 2019
d594dc7
requirements.txt renewed by pipreq
barisozmen Feb 13, 2019
c15e85b
unsued script deleted
barisozmen Feb 13, 2019
3fe1420
private functions prefixed with _
barisozmen Feb 13, 2019
6e0341a
image generator getter implemented
barisozmen Feb 13, 2019
2cfe46c
Update README.md
barisozmen Feb 13, 2019
77d3cfe
Update README.md
barisozmen Feb 13, 2019
6d24b46
Update README.md
barisozmen Feb 13, 2019
d945343
Update README.md
barisozmen Feb 14, 2019
38d93e1
X_val_seed length problem fixed for special inputs
barisozmen Feb 14, 2019
b096ff5
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 14, 2019
65e8e91
Merge branch 'apply-learned-policy'
barisozmen Feb 14, 2019
ed17a1d
version bumped
barisozmen Feb 14, 2019
5d094c0
identation fixed
barisozmen Feb 14, 2019
889eb98
indentation fixed
barisozmen Feb 14, 2019
e4bd2e8
Update README.md
barisozmen Feb 16, 2019
e750afb
Update README.md
barisozmen Feb 16, 2019
5ee0368
Update README.md
barisozmen Feb 16, 2019
e209ae7
new example added
Feb 17, 2019
726313c
file deleted
Feb 17, 2019
2947427
new example added
barisozmen Feb 17, 2019
ac1a661
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 17, 2019
eed9be1
full_model refactored
barisozmen Feb 17, 2019
24bfdfd
bug fixed
barisozmen Feb 17, 2019
5570085
InceptionV3 added as option
barisozmen Feb 17, 2019
73c5a65
run with inceptionv3
barisozmen Feb 17, 2019
8521a50
random policies option added
barisozmen Feb 18, 2019
5fd1552
train_test_split improved with shuffle
barisozmen Feb 18, 2019
cbd491e
bug fixed
barisozmen Feb 18, 2019
58a933d
bug fixed
barisozmen Feb 18, 2019
bffa434
requirements made lower cased
barisozmen Feb 18, 2019
6876f12
version increased
barisozmen Feb 18, 2019
3619858
bug fixed
barisozmen Feb 18, 2019
0734d8a
pawprints best policies added
barisozmen Feb 18, 2019
7254328
cifar10 best policies added
barisozmen Feb 18, 2019
8673d35
Update README.md
barisozmen Feb 20, 2019
d07581f
Update README.md
barisozmen Feb 20, 2019
855c353
Update README.md
barisozmen Feb 20, 2019
df8a496
Update README.md
barisozmen Feb 20, 2019
ccfc09e
project description type specified on setup.py
barisozmen Feb 20, 2019
905bc5a
README update
barisozmen Feb 20, 2019
531c429
Update README.md
barisozmen Feb 22, 2019
d50a252
Update README.md
barisozmen Feb 22, 2019
61d0cc4
Update README.md
barisozmen Feb 22, 2019
60d8511
opencv added to requirements.txt
barisozmen Feb 23, 2019
e306cf7
GPU not available warning downgraded to info-level, and will no be pr…
barisozmen Feb 23, 2019
1adc803
GPU not available warning downgraded to info-level, and will no be pr…
barisozmen Feb 23, 2019
f62b83c
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 23, 2019
a53a6a9
examples renamed to experiments
barisozmen Feb 23, 2019
64cc08b
run_full_model() user interface improved
barisozmen Feb 23, 2019
b82fd04
Update README.md
barisozmen Feb 24, 2019
6b93173
Update README.md
barisozmen Feb 24, 2019
a073924
Update README.md
barisozmen Feb 24, 2019
e98f698
Update README.md
barisozmen Feb 24, 2019
fb1436f
Update README.md
barisozmen Feb 24, 2019
da40ef7
redundant notebooks removed
barisozmen Feb 24, 2019
806c943
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Feb 24, 2019
907223e
bug fixed
barisozmen Feb 24, 2019
cfb12a0
cifar10 run with full model and random augmentation
barisozmen Feb 24, 2019
c85e5c2
Update README.md
barisozmen Feb 25, 2019
122130c
Update README.md
barisozmen Feb 25, 2019
ebb65cb
Update README.md
barisozmen Feb 25, 2019
0489ab7
Update README.md
barisozmen Feb 25, 2019
d857ee5
Update README.md
barisozmen Feb 25, 2019
eab25d0
Update README.md
barisozmen Feb 25, 2019
735948e
Update README.md
barisozmen Feb 25, 2019
df45acd
Update README.md
barisozmen Feb 25, 2019
84ec04a
Update README.md
barisozmen Feb 25, 2019
dfe2e03
Update README.md
barisozmen Feb 25, 2019
8ee30bf
Update README.md
barisozmen Feb 25, 2019
60074ef
Update README.md
barisozmen Feb 25, 2019
c95883e
Update README.md
barisozmen Feb 25, 2019
1ad642f
Update README.md
barisozmen Feb 25, 2019
510a860
Update README.md
barisozmen Feb 26, 2019
10b35ff
Update README.md
barisozmen Feb 26, 2019
6f00aee
Update README.md
barisozmen Mar 1, 2019
70483b1
Update README.md
barisozmen Mar 1, 2019
9eec25b
models folder deleted
barisozmen Mar 1, 2019
2d54828
Merge branch 'master' of https://github.com/barisozmen/deepaugment
barisozmen Mar 1, 2019
25d7c11
now deepaugment optimizes for 5-policies
barisozmen Mar 4, 2019
41488a8
Merge branch '5-policy'
barisozmen Mar 4, 2019
44bf62d
Update README.md
barisozmen Mar 4, 2019
f5d91a7
Update README.md
barisozmen Mar 4, 2019
febf55f
Update README.md
barisozmen Mar 4, 2019
c0d33dc
Update README.md
barisozmen Mar 4, 2019
2120abc
bugs fixed
barisozmen Mar 5, 2019
59c2039
README update
barisozmen Mar 5, 2019
f62f589
bug fixed
barisozmen Mar 6, 2019
9b05440
Update README.md
barisozmen Mar 8, 2019
e3f145c
Update README.md
barisozmen Mar 8, 2019
818fb95
Update README.md
barisozmen Mar 8, 2019
6b7848d
Update README.md
Rvbens Apr 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md
include requirements.txt
286 changes: 233 additions & 53 deletions README.md

Large diffs are not rendered by default.

File renamed without changes.
183 changes: 183 additions & 0 deletions deepaugment/augmenter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# (C) 2019 Baris Ozmen <hbaristr@gmail.com>

import numpy as np
from imgaug import augmenters as iaa


def normalize(X):
return (X / 255.0).copy()


def denormalize(X):
X_dn = (X * 255).copy()
return X_dn


def transform(aug_type, magnitude, X):
if aug_type == "crop":
X_aug = iaa.Crop(px=(0, int(magnitude * 32))).augment_images(X)
elif aug_type == "gaussian-blur":
X_aug = iaa.GaussianBlur(sigma=(0, magnitude * 25.0)).augment_images(X)
elif aug_type == "rotate":
X_aug = iaa.Affine(rotate=(-180 * magnitude, 180 * magnitude)).augment_images(X)
elif aug_type == "shear":
X_aug = iaa.Affine(shear=(-90 * magnitude, 90 * magnitude)).augment_images(X)
elif aug_type == "translate-x":
X_aug = iaa.Affine(
translate_percent={"x": (-magnitude, magnitude), "y": (0, 0)}
).augment_images(X)
elif aug_type == "translate-y":
X_aug = iaa.Affine(
translate_percent={"x": (0, 0), "y": (-magnitude, magnitude)}
).augment_images(X)
elif aug_type == "horizontal-flip":
X_aug = iaa.Fliplr(magnitude).augment_images(X)
elif aug_type == "vertical-flip":
X_aug = iaa.Flipud(magnitude).augment_images(X)
elif aug_type == "sharpen":
X_aug = iaa.Sharpen(
alpha=(0, 1.0), lightness=(0.50, 5 * magnitude)
).augment_images(X)
elif aug_type == "emboss":
X_aug = iaa.Emboss(
alpha=(0, 1.0), strength=(0.0, 20.0 * magnitude)
).augment_images(X)
elif aug_type == "additive-gaussian-noise":
X_aug = iaa.AdditiveGaussianNoise(
loc=0, scale=(0.0, magnitude * 255), per_channel=0.5
).augment_images(X)
elif aug_type == "dropout":
X_aug = iaa.Dropout(
(0.01, max(0.011, magnitude)), per_channel=0.5
).augment_images(
X
) # Dropout first argument should be smaller than second one
elif aug_type == "coarse-dropout":
X_aug = iaa.CoarseDropout(
(0.03, 0.15), size_percent=(0.30, np.log10(magnitude * 3)), per_channel=0.2
).augment_images(X)
elif aug_type == "gamma-contrast":
X_norm = normalize(X)
X_aug_norm = iaa.GammaContrast(magnitude * 1.75).augment_images(
X_norm
) # needs 0-1 values
X_aug = denormalize(X_aug_norm)
elif aug_type == "brighten":
X_aug = iaa.Add(
(int(-40 * magnitude), int(40 * magnitude)), per_channel=0.5
).augment_images(
X
) # brighten
elif aug_type == "invert":
X_aug = iaa.Invert(1.0).augment_images(X) # magnitude not used
elif aug_type == "fog":
X_aug = iaa.Fog().augment_images(X) # magnitude not used
elif aug_type == "clouds":
X_aug = iaa.Clouds().augment_images(X) # magnitude not used
elif aug_type == "histogram-equalize":
X_aug = iaa.AllChannelsHistogramEqualization().augment_images(
X
) # magnitude not used
elif aug_type == "super-pixels": # deprecated
X_norm = normalize(X)
X_norm2 = (X_norm * 2) - 1
X_aug_norm2 = iaa.Superpixels(
p_replace=(0, magnitude), n_segments=(100, 100)
).augment_images(X_norm2)
X_aug_norm = (X_aug_norm2 + 1) / 2
X_aug = denormalize(X_aug_norm)
elif aug_type == "perspective-transform":
X_norm = normalize(X)
X_aug_norm = iaa.PerspectiveTransform(
scale=(0.01, max(0.02, magnitude))
).augment_images(
X_norm
) # first scale param must be larger
np.clip(X_aug_norm, 0.0, 1.0, out=X_aug_norm)
X_aug = denormalize(X_aug_norm)
elif aug_type == "elastic-transform": # deprecated
X_norm = normalize(X)
X_norm2 = (X_norm * 2) - 1
X_aug_norm2 = iaa.ElasticTransformation(
alpha=(0.0, max(0.5, magnitude * 300)), sigma=5.0
).augment_images(X_norm2)
X_aug_norm = (X_aug_norm2 + 1) / 2
X_aug = denormalize(X_aug_norm)
elif aug_type == "add-to-hue-and-saturation":
X_aug = iaa.AddToHueAndSaturation(
(int(-45 * magnitude), int(45 * magnitude))
).augment_images(X)
elif aug_type == "coarse-salt-pepper":
X_aug = iaa.CoarseSaltAndPepper(p=0.2, size_percent=magnitude).augment_images(X)
elif aug_type == "grayscale":
X_aug = iaa.Grayscale(alpha=(0.0, magnitude)).augment_images(X)
else:
raise ValueError
return X_aug


def augment_by_policy(
X, y, *hyperparams
):
"""
"""
portion = 1

assert (
portion >= 0.0 and portion <= 1.0
), "portion argument value is out of accepted interval"

# convert data to 255 from normalized
_X = denormalize(X)

if portion == 1.0:
X_portion = _X
y_portion = y
else:
# get a portion of data
ix = np.random.choice(len(_X), int(len(_X) * portion), False)

X_portion = _X[ix].copy()
y_portion = y[ix].copy()

if X_portion.shape[0] == 0:
print("X_portion has zero size !!!")
nix = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
X_portion = _X[nix].copy()
y_portion = y[nix].copy()



all_X_portion_aug=None
all_y_portion = None
for i in range(0,len(hyperparams)-1,4):

# transform that portion
X_portion_aug = transform(hyperparams[i], hyperparams[i+1], X_portion) # first transform

assert (
X_portion_aug.min() >= -0.1 and X_portion_aug.max() <= 255.1
), "first transform is unvalid"
np.clip(X_portion_aug, 0, 255, out=X_portion_aug)

X_portion_aug = transform(
hyperparams[i+2], hyperparams[i+3], X_portion_aug
) # second transform
assert (
X_portion_aug.min() >= -0.1 and X_portion_aug.max() <= 255.1
), "second transform is unvalid"
np.clip(X_portion_aug, 0, 255, out=X_portion_aug)

if all_X_portion_aug is None:
all_X_portion_aug = X_portion_aug
all_y_portion = y_portion
else:
all_X_portion_aug = np.concatenate([all_X_portion_aug, X_portion_aug])
all_y_portion = np.concatenate([all_y_portion, y_portion])

augmented_data = {
"X_train": all_X_portion_aug / 255.0,
"y_train": all_y_portion,
} # back to normalization

return augmented_data # augmenteed data is mostly smaller than whole data
120 changes: 120 additions & 0 deletions deepaugment/build_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# (C) 2019 Baris Ozmen <hbaristr@gmail.com>

import sys
import numpy as np
import keras


class DataOp:
@staticmethod
def load(dataset_name):
"""Loads dataset from keras and returns a sample out of it

Args:
dataset_name (str):
training_set_size (int):
validation_set_size (int):
Returns:
dict: data, with keys X_train, Y_train, X_val, Y_val
list: input shape
"""
if hasattr(keras.datasets, dataset_name):
(x_train, y_train), (x_val, y_val) = getattr(
keras.datasets, dataset_name
).load_data()
else:
sys.exit(f"Unknown dataset {dataset_name}")

X = np.concatenate([x_train, x_val])
y = np.concatenate([y_train, y_val])
input_shape = x_train.shape[1:]

return X, y, input_shape

@staticmethod
def preprocess_normal(data):
# normalize images
data["X_train"] = data["X_train"].astype("float32") / 255
data["X_val"] = data["X_val"].astype("float32") / 255

# convert labels to categorical
data["y_train"] = keras.utils.to_categorical(data["y_train"])
data["y_val"] = keras.utils.to_categorical(data["y_val"])
return data

@staticmethod
def split_train_val_sets(X, y, train_set_size, val_set_size):
"""Splits given images randomly into `train` and `val_seed` groups

val_seed -> is validation seed dataset, from where validation sets are sampled

Args:
X (numpy.array):
y (numpy.array):
train_set_size (int):
val_set_size (int):
return:
dict: dict with keys `X_train`, `y_train`, `X_val_seed`, `y_val_seed`
"""
if train_set_size == None:
print(f"Using all training images")
train_set_size = len(X) - val_set_size
else:
print(f"Using {train_set_size} training images")

# reduce training dataset
ix = np.random.choice(len(X), train_set_size, False)
X_train = X[ix]
y_train = y[ix]

other_ix = set(np.arange(len(X))).difference(set(ix))
other_ix = list(other_ix)
X_val_seed = X[other_ix]
y_val_seed = y[other_ix]

data = {
"X_train": X_train,
"y_train": y_train,
"X_val_seed": X_val_seed,
"y_val_seed": y_val_seed,
}
return data

@staticmethod
def preprocess(X, y, train_set_size, val_set_size=1000):
"""Preprocess images by:
1. normalize to 0-1 range (divide by 255)
2. convert labels to categorical)

Args:
X (numpy.array):
y (numpy.array):
train_set_size (int):
val_set_size (int):

Returns:
dict: preprocessed data
"""

data = DataOp.split_train_val_sets(X, y, train_set_size, val_set_size)

# normalize images
data["X_train"] = data["X_train"].astype("float32") / 255
data["X_val_seed"] = data["X_val_seed"].astype("float32") / 255

# convert labels to categorical
data["y_train"] = keras.utils.to_categorical(data["y_train"])
data["y_val_seed"] = keras.utils.to_categorical(data["y_val_seed"])
return data

@staticmethod
def sample_validation_set(data):
val_seed_size = len(data["X_val_seed"])
ix = np.random.choice(range(val_seed_size), min(val_seed_size, 1000), False)
X_val = data["X_val_seed"][ix].copy()
y_val = data["y_val_seed"][ix].copy()
return X_val, y_val

@staticmethod
def find_num_classes(data):
return data["y_train"].shape[1]
Loading