-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project import generated by Copybara.
PiperOrigin-RevId: 221054954
- Loading branch information
Showing
39 changed files
with
5,782 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Support bazelrc through migration of location. | ||
# See https://github.com/bazelbuild/bazel/issues/6319 | ||
import %workspace%/tools/bazel.rc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# multidim_image_augmentation opensource project root BUILD file. | ||
|
||
# The action all happens in multidim_image_augmentation/BUILD below this, this | ||
# file is only needed to permit bazel to load the *.bzl extensions hosted | ||
# along side this file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# How to Contribute | ||
|
||
We are not yet actively solicity github pull requests at this time, but we | ||
warmly welcome you to create a [github | ||
issue](https://github.com/deepmind/multidim-image-augmentation/issues/new) with | ||
for any bugs or feature requests you may have. In order to contribute design | ||
ideas or code (via the issue tracker or otherwise) to this project you will need | ||
to complete the Contributor License Agreement as described below. | ||
|
||
## Contributor License Agreement | ||
|
||
Contributions to this project must be accompanied by a Contributor License | ||
Agreement. You (or your employer) retain the copyright to your contribution; | ||
this simply gives us permission to use and redistribute your contributions as | ||
part of the project. Head over to <https://cla.developers.google.com/> to see | ||
your current agreements on file or to sign a new one. | ||
|
||
You generally only need to submit a CLA once, so if you've already submitted one | ||
(even if it was for a different project), you probably don't need to do it | ||
again. | ||
|
||
## Code reviews | ||
|
||
This github project is a mirror of our internal master copy of the source. As | ||
such all changes must first be submitted internally, where we conduct code | ||
reviews and continuous integration testing, before publishing externally. In | ||
future we may open up submissions via the github pull request process. | ||
|
||
## Community Guidelines | ||
|
||
This project follows | ||
[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
Apache License | ||
Version 2.0, January 2004 | ||
http://www.apache.org/licenses/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Multidimensional (2D and 3D) Image Augmentation for TensorFlow | ||
|
||
This package provides TensorFlow Ops for multidimensional volumetric image | ||
augmentation. | ||
|
||
## Install prerequities | ||
|
||
This project usings the [bazel build | ||
system](https://docs.bazel.build/versions/master/install.html) | ||
|
||
## Build and test | ||
|
||
To fetch the code, build it, and run tests: | ||
|
||
```shell | ||
$ git clone https://github.com/deepmind/multidim-image-augmentation.git | ||
$ cd multidim-image-augmentation/ | ||
$ bazel test -c opt //... | ||
``` | ||
|
||
To learn more about image augmentation, see the [primer](doc/index.md) | ||
|
||
For simple API usage examples, see the python test code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
workspace(name = "multidim_image_augmentation") | ||
|
||
# TensorFlow depends on "io_bazel_rules_closure" so we need this here. | ||
# Needs to be kept in sync with the same target in TensorFlow's WORKSPACE file. | ||
http_archive( | ||
name = "io_bazel_rules_closure", | ||
sha256 = "a38539c5b5c358548e75b44141b4ab637bba7c4dc02b46b1f62a96d6433f56ae", | ||
strip_prefix = "rules_closure-dbb96841cc0a5fb2664c37822803b06dab20c7d1", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/dbb96841cc0a5fb2664c37822803b06dab20c7d1.tar.gz", | ||
"https://github.com/bazelbuild/rules_closure/archive/dbb96841cc0a5fb2664c37822803b06dab20c7d1.tar.gz", # 2018-04-13 | ||
], | ||
) | ||
|
||
# Tensorflow. If your project already builds Tensorflow source you should | ||
# replace this with an appropriate local_archice() call. | ||
# To update this to a newer TF version: | ||
# 1/ curl -L https://github.com/tensorflow/tensorflow/archive/vX.Y.Z.tar | sha256sum | ||
# 2/ Update `sha256`, `strip_prefix` and `urls` attributes appropriately. | ||
# 3/ Update io_bazel_rules_closure above to match the version used by TF. | ||
http_archive( | ||
name = "org_tensorflow", | ||
sha256 = "f49ce3f1d04cee854bc9f74fa9696991140b34a2e2447f35f01391b72c8bfa9f", | ||
strip_prefix = "tensorflow-1.11.0", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/tensorflow/tensorflow/archive/v1.11.0.tar.gz", | ||
"https://github.com/tensorflow/tensorflow/archive/v1.11.0.tar.gz", | ||
], | ||
) | ||
|
||
# Please add all new multidim_image_augmentation dependencies in workspace.bzl. | ||
load("//:workspace.bzl", "multidim_image_augmentation_workspace") | ||
|
||
multidim_image_augmentation_workspace() | ||
|
||
# Specify the minimum required bazel version. | ||
load("@org_tensorflow//tensorflow:version_check.bzl", "check_bazel_version_at_least") | ||
|
||
check_bazel_version_at_least("0.15.0") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Multidimensional (2D and 3D) Image Augmentation for TensorFlow | ||
|
||
**TL;DR: The code in this directory provides TensorFlow Ops for multidimensional | ||
volumetric image augmentation.** | ||
|
||
## Motivation | ||
|
||
Data augmentation during training helps a lot for generalization of the models | ||
and prevents (or reduces) overfitting to the training data set. It can be | ||
regarded as incorporation of prior knowledge about class-preserving | ||
transformations. For images these class-preserving transformations usually | ||
include spatial transformations (translation, rotation, scale, shear, and | ||
elastic) and intensity transformations (linear mappings like brightness, | ||
contrast, and non-linear mappings like gamma-corrections). All these variations | ||
can be imposed by the imaging process (imaging device position and orientation, | ||
device parameters, illumination, etc.) for an identical real world object. | ||
Additionally the real world object might undergo class-preserving | ||
transformations, like elastic deformations (e.g. a snail). Finally different | ||
instances of the same object class (e.g. leafs on a tree) might look like | ||
deformed versions of another instance. | ||
|
||
## Spatial Transformations | ||
|
||
![Elastic | ||
Deformation](elastic_deformation_figure.png) | ||
|
||
The key features of this implementation of spatial transformations are: | ||
|
||
* all types of spatial transformations (translation, rotation, scale, shear, | ||
and elastic) with a single convenient interface | ||
* very fast: all transformations get combined before they are applied to the | ||
image | ||
* same transformation can be efficiently applied to multiple images (e.g. raw | ||
image, segmentation map, loss weight map) | ||
* different interpolations (nearest, linear) and extrapolations (zero-padding, | ||
const-padding, mirroring) | ||
* on-the fly conversion of segmentation maps to one-hot-encoding with linear | ||
interpolation in each resulting channel | ||
* implementations for planar (2D) and volumetric (3D) images, single channel | ||
(e.g. gray images) or multi-channel (e.g. RGB images) | ||
|
||
For maximal flexibility the implementation consists of three main steps: | ||
|
||
1. Setup a grid of control points and apply all spatial transformations to the | ||
control points. This is very fast compared to operations on the full image | ||
(blue stars in the Figure) | ||
1. Compute a dense transformation field using cubic bspline interpolation | ||
(illustrated by the red grid in the Figure) | ||
1. Apply the dense transformation field to image, segmentation map, and loss | ||
weight map using appropriate interpolation and extrapolation strategies | ||
(output image in the Figure) | ||
|
||
|
||
## Intensity Transformations | ||
|
||
![Intensity Transformations](intensity_transformations_figure.png) | ||
|
||
Intensity or color augmentation helps to teach the network desired robustness | ||
and helps to reduce overfitting. Standard color augmentations (contrast, | ||
brightness) are often implemented as linear transforms, and so will most likely | ||
be directly compensated by the input normalization of a network. So we want to | ||
have non-linear augmentations (like gamma-correction and the S-curves in | ||
Photoshop). Trying to combine these two and find a reasonable parameterization | ||
ended in a nightmare, so here is a more straight-forward alternative. | ||
|
||
Instead of finding a parameterization, we just define the contraints to the | ||
mapping function -- which is much easier and intuitive (for the examples we | ||
assume float gray values between 0 and 1) | ||
|
||
* the new "black point" should be within a certain range (e.g., -0.1 to 0.1) | ||
* the new "white point" should be within a certain range (e.g., 0.9 to 1.1) | ||
* the function should be reasonable smooth | ||
* the slope of the function should be bounded (e.g., between 0.5 and 2.0) | ||
|
||
The algorithm first samples control points (here 5) and then computes the smooth | ||
function via cubic bspline interpolation | ||
|
||
1. sample a random value from the "black range" for the control point at 0, the | ||
new "black point" | ||
1. sample a random value from the "white range" for the control point at 1, the | ||
new "white point" | ||
1. recursively insert a new control point between the existing ones. Sample its | ||
value such that the slope constraints to both neighbours are fulfilled | ||
1. compute the smooth mapping function via cubic bspline interpolation | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.