From 09f967889c3da353bced934dbd3dde6b479aebf2 Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Tue, 19 Dec 2017 10:23:46 -0500 Subject: [PATCH 1/7] add code source reference --- keras_contrib/preprocessing/image_segmentation.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/keras_contrib/preprocessing/image_segmentation.py b/keras_contrib/preprocessing/image_segmentation.py index b2de3d5..11be928 100644 --- a/keras_contrib/preprocessing/image_segmentation.py +++ b/keras_contrib/preprocessing/image_segmentation.py @@ -1,3 +1,7 @@ +""" Preprocessing for semantic image segmentation + + adapted from: https://github.com/aurora95/Keras-FCN +""" from keras.preprocessing.image import * from keras.applications.imagenet_utils import preprocess_input from keras import backend as K From 7bc0d8288fd38473fbd56548c33c23436a4d3442 Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Tue, 19 Dec 2017 11:58:34 -0500 Subject: [PATCH 2/7] test_image_segmentation.py init SegDataGenerator() --- .../keras_contrib/preprocessing/test_image_segmentation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/keras_contrib/preprocessing/test_image_segmentation.py b/tests/keras_contrib/preprocessing/test_image_segmentation.py index 0c5fe0e..b85d899 100644 --- a/tests/keras_contrib/preprocessing/test_image_segmentation.py +++ b/tests/keras_contrib/preprocessing/test_image_segmentation.py @@ -1,5 +1,5 @@ from keras.preprocessing.image import img_to_array, array_to_img -from utils import SegDataGenerator +from keras_contrib.utils import SegDataGenerator from PIL import Image as PILImage import numpy as np @@ -46,3 +46,7 @@ test_random_crop = lambda: test_crop(SegDataGenerator.random_crop) test_pair_center_crop = lambda: test_pair_crop(SegDataGenerator.pair_center_crop) test_pair_random_crop = lambda: test_pair_crop(SegDataGenerator.pair_random_crop) + + +def test_seg_data_generator(): + datagen = SegDataGenerator() From 0957603edd1ba9aee7490ff72ddce61307835557 Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Tue, 19 Dec 2017 12:04:23 -0500 Subject: [PATCH 3/7] test_image_segmentation.py correct import --- tests/keras_contrib/preprocessing/test_image_segmentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/keras_contrib/preprocessing/test_image_segmentation.py b/tests/keras_contrib/preprocessing/test_image_segmentation.py index b85d899..5a0bb13 100644 --- a/tests/keras_contrib/preprocessing/test_image_segmentation.py +++ b/tests/keras_contrib/preprocessing/test_image_segmentation.py @@ -1,5 +1,5 @@ from keras.preprocessing.image import img_to_array, array_to_img -from keras_contrib.utils import SegDataGenerator +from keras_contrib.preprocessing.image_segmentation import SegDataGenerator from PIL import Image as PILImage import numpy as np From 3db35ef1305ff5f8d8cab5a0731a5d3903850fae Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Tue, 19 Dec 2017 13:09:22 -0500 Subject: [PATCH 4/7] preprocessing __init__.py updated --- keras_contrib/preprocessing/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/keras_contrib/preprocessing/__init__.py b/keras_contrib/preprocessing/__init__.py index e69de29..ca58033 100644 --- a/keras_contrib/preprocessing/__init__.py +++ b/keras_contrib/preprocessing/__init__.py @@ -0,0 +1,6 @@ +from __future__ import absolute_import +from . import image_segmentation + +# Globally-importable preprocessing +from .image_segmentation import SegDirectoryIterator +from .image_segmentation import SegDataGenerator From d54f71a7d263245c2ae0710983366b850ae42b63 Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Tue, 19 Dec 2017 15:53:48 -0500 Subject: [PATCH 5/7] image_segmentation.py pep8 --- keras_contrib/preprocessing/image_segmentation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/keras_contrib/preprocessing/image_segmentation.py b/keras_contrib/preprocessing/image_segmentation.py index 11be928..d867ed1 100644 --- a/keras_contrib/preprocessing/image_segmentation.py +++ b/keras_contrib/preprocessing/image_segmentation.py @@ -37,11 +37,11 @@ def pair_center_crop(x, y, center_crop_size, data_format, **kwargs): h_start, h_end = centerh - lh, centerh + rh w_start, w_end = centerw - lw, centerw + rw if data_format == 'channels_first': - return x[:, h_start:h_end, w_start:w_end], \ - y[:, h_start:h_end, w_start:w_end] + return (x[:, h_start:h_end, w_start:w_end], + y[:, h_start:h_end, w_start:w_end]) elif data_format == 'channels_last': - return x[h_start:h_end, w_start:w_end, :], \ - y[h_start:h_end, w_start:w_end, :] + return (x[h_start:h_end, w_start:w_end, :], + y[h_start:h_end, w_start:w_end, :]) def random_crop(x, random_crop_size, data_format, sync_seed=None, **kwargs): From 5d09a9368d0b031a2929b316620145b69005ceaa Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Tue, 19 Dec 2017 16:09:19 -0500 Subject: [PATCH 6/7] image_segmentation.py change backend import --- keras_contrib/preprocessing/image_segmentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keras_contrib/preprocessing/image_segmentation.py b/keras_contrib/preprocessing/image_segmentation.py index d867ed1..ce8aa9d 100644 --- a/keras_contrib/preprocessing/image_segmentation.py +++ b/keras_contrib/preprocessing/image_segmentation.py @@ -4,7 +4,7 @@ """ from keras.preprocessing.image import * from keras.applications.imagenet_utils import preprocess_input -from keras import backend as K +from .. import backend as K from PIL import Image import numpy as np import os From 2a87279b848e2b358df13035bd6a7e730c005f66 Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Tue, 19 Dec 2017 16:59:59 -0500 Subject: [PATCH 7/7] test_image_segmentation.py pep8 --- .../preprocessing/test_image_segmentation.py | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/keras_contrib/preprocessing/test_image_segmentation.py b/tests/keras_contrib/preprocessing/test_image_segmentation.py index 5a0bb13..e1ad097 100644 --- a/tests/keras_contrib/preprocessing/test_image_segmentation.py +++ b/tests/keras_contrib/preprocessing/test_image_segmentation.py @@ -1,5 +1,6 @@ from keras.preprocessing.image import img_to_array, array_to_img from keras_contrib.preprocessing.image_segmentation import SegDataGenerator +from keras_contrib.preprocessing import image_segmentation from PIL import Image as PILImage import numpy as np @@ -30,22 +31,30 @@ def test_pair_crop(crop_function): crop_height = img1.height / 5 result1, result2 = crop_function(img_to_array(img1), - img_to_array(img2), - (crop_height, crop_width), - 'channels_last') + img_to_array(img2), + (crop_height, crop_width), + 'channels_last') result1 = array_to_img(result1) result2 = array_to_img(result2) assert result1.width == crop_width == result2.width assert result2.height == crop_height == result2.height -test_center_crop = lambda: test_crop(SegDataGenerator.center_crop) -test_random_crop = lambda: test_crop(SegDataGenerator.random_crop) +def test_center_crop(): + test_crop(image_segmentation.center_crop) -test_pair_center_crop = lambda: test_pair_crop(SegDataGenerator.pair_center_crop) -test_pair_random_crop = lambda: test_pair_crop(SegDataGenerator.pair_random_crop) +def test_random_crop(): + test_crop(image_segmentation.random_crop) + + +def test_pair_center_crop(): + test_pair_crop(image_segmentation.pair_center_crop) + + +def test_pair_random_crop(): + test_pair_crop(image_segmentation.pair_random_crop) def test_seg_data_generator():