Skip to content

Commit

Permalink
setup adjusted to version 1.0, README, package renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Hvitgar committed Jul 12, 2019
1 parent 0c0827c commit 568283e
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 14 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# add-common-image-corruptions
# imagecorruptions
This package provides a set of corruptions that can be applied to images in order to benchmark the robustness of neural networks. These corruptions are not meant to be used as training data augmentation but rather to test the networks against unseen perturbations. For more information have a look at the paper on the original corruption package by Hendrycks and Dietterich: [Benchmarking Neural Network Robustness to Common Corruptions and Surface Variations](https://arxiv.org/abs/1807.01697)

## Installation and Usage
This package is pip installable via `pip3 install imagecorruptions`. An example of how to use the corruption function is given below:
```python
from imagecorruptions import corrupt
...
corrupted_image = corrupt(image, corruption_name='gaussian_blur', severity=1)
...
```
Looping over all available corruptions can be done either by name or by index:
```python
# via name
from imagecorruptions import get_corruption_names
for corruption in get_corruption_names():
for severity in range(5):
corrupted = corrupt(image, corruption_name=corruption, severity=severity+1)
...

# via number:
for i in range(15):
for severity in range(5):
corrupted = corrupt(image, corruption_number=i, severity=severity+1)
...
```

Note that the first 15 image corruptions are the common corruptions (the ones you get via `get_corruption_names()`). If you really wish to use these as data augmentation, there exist four additional validation corruptions which can be accessed via `get_corruption_names('validation')` which should then be used to test the corruption robustness of the trained model.

## Credit
This package is an extension of the image corruption functions provided by Dan Hendrycks in the repository [corruptions](https://github.com/hendrycks/robustness). The image corruptions implemented by Hendrycks are generalized to work on images with arbitrary image dimensions and aspect ratios.
11 changes: 9 additions & 2 deletions corruptions/__init__.py → imagecorruptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ def corrupt(x, severity=1, corruption_name=None, corruption_number=-1):

return np.uint8(x_corrupted)

def get_corruption_names():
return [f.__name__ for f in corruption_tuple]
def get_corruption_names(subset='common'):
if subset == 'common':
return [f.__name__ for f in corruption_tuple[:15]]
elif subset == 'validation':
return [f.__name__ for f in corruption_tuple[15:]]
elif subset == 'all':
return [f.__name__ for f in corruption_tuple]
else:
raise ValueError("subset must be one of ['common', 'validation', 'all']")
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
22 changes: 11 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@


setuptools.setup(
name="corruptions",
version="0.0.1",
author="Benjamin Mitzkus",
author_email="benjamin.mitzkus@bethgelab.org",
name="imagecorruptions",
version="1.0.0",
author="Evgenia Rusak, Benjamin Mitzkus",
author_email="evgenia.rusak@bethgelab.org, benjamin.mitzkus@bethgelab.org",
description="This package provides a set of image corruptions.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/bethgelab/add-common-image-corruptions",
url="https://github.com/bethgelab/imagecorruptions",
packages=setuptools.find_packages(),
install_requires=[
'numpy',
'Pillow',
'scikit-image',
'opencv-python',
'scipy',
'numpy >= 1.16',
'Pillow >= 5.4.1',
'scikit-image >= 0.15',
'opencv-python >= 3.4.5',
'scipy >= 1.2.1',
],
include_package_data=True,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
)

0 comments on commit 568283e

Please sign in to comment.