update for tox testing and some docs 16/1116/6
authorEric Z <ezavesky@research.att.com>
Tue, 27 Feb 2018 20:55:26 +0000 (14:55 -0600)
committerEric Z <ezavesky@research.att.com>
Tue, 27 Feb 2018 20:55:26 +0000 (14:55 -0600)
- add testing requirments, add tox.ini
- add some test images for detect test procedure
- add some images for catalog image examples

Change-Id: I84599a3b51f50cf3710261fb1a11f531d5b08782
Signed-off-by: Eric Z <ezavesky@research.att.com>
12 files changed:
docs/catalog_image_blur.png [new file with mode: 0644]
docs/catalog_image_detect.png [new file with mode: 0644]
docs/commercial_pixelate.png [new file with mode: 0644]
docs/tutorials/lesson2.md
face_privacy_filter/tests/test_detect.py [new file with mode: 0644]
face_privacy_filter/transform_detect.py
requirements.txt
testing/multi-face_pexels.jpg [new file with mode: 0644]
testing/requirements.txt [deleted file]
testing/single-face_pexels.jpg [new file with mode: 0644]
testing/tox-requirements.txt [new file with mode: 0644]
tox.ini [new file with mode: 0644]

diff --git a/docs/catalog_image_blur.png b/docs/catalog_image_blur.png
new file mode 100644 (file)
index 0000000..d7e4df6
Binary files /dev/null and b/docs/catalog_image_blur.png differ
diff --git a/docs/catalog_image_detect.png b/docs/catalog_image_detect.png
new file mode 100644 (file)
index 0000000..1f88764
Binary files /dev/null and b/docs/catalog_image_detect.png differ
diff --git a/docs/commercial_pixelate.png b/docs/commercial_pixelate.png
new file mode 100644 (file)
index 0000000..b732d20
Binary files /dev/null and b/docs/commercial_pixelate.png differ
index 1ce2b27..60fe02b 100644 (file)
@@ -106,3 +106,11 @@ images from javascript can be [found on StackOverflow](https://stackoverflow.com
 ```
 curl -F base64_data=@../web_demo/images/face_renion.jpg -F mime_type="image/jpeg" "http://localhost:8884/transform"
 ```
+
+## Sample Inages
+Sample images are provided in the `testing` directory and were originally sourced
+from the URLs below.
+
+* [multi-face_pexels.jpg](https://www.pexels.com/photo/family-generation-father-mother-8509/)
+* [single-face_pexels.jpg](https://www.pexels.com/photo/adult-beard-boy-casual-220453/)
+
diff --git a/face_privacy_filter/tests/test_detect.py b/face_privacy_filter/tests/test_detect.py
new file mode 100644 (file)
index 0000000..e2c2e32
--- /dev/null
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+# ================================================================================
+# ACUMOS
+# ================================================================================
+# Copyright © 2017 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
+# ================================================================================
+# This Acumos software file is distributed by AT&T and Tech Mahindra
+# under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# This file is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ================================================================================
+
+from os import path
+import pytest
+
+
+def test_detect_single(monkeypatch):
+    pathRoot = env_update(monkeypatch)
+    from face_privacy_filter.transform_detect import FaceDetectTransform
+    transform = FaceDetectTransform(include_image=False)
+    inputDf = FaceDetectTransform.generate_in_df(path.join(pathRoot, 'testing', 'single-face_pexels.jpg'))
+    outputDf = transform.predict(inputDf)
+    assert len(outputDf) == 1                       # just one face, no image
+    assert outputDf['w'][0] == outputDf['h'][0]     # make sure width/height is equal
+    assert outputDf['w'][0] > 680                    # reasonable face size detection
+    assert len(outputDf['image_binary'][0]) == 0     # there should be no binary data on detect regions
+    print(outputDf)   # run `pytest -s` for more verbosity
+
+
+def test_detect_multi(monkeypatch):
+    pathRoot = env_update(monkeypatch)
+    from face_privacy_filter.transform_detect import FaceDetectTransform
+    transform = FaceDetectTransform(include_image=True)
+    inputDf = FaceDetectTransform.generate_in_df(path.join(pathRoot, 'testing', 'multi-face_pexels.jpg'))
+    outputDf = transform.predict(inputDf)
+    assert len(outputDf) == 5       # note ONE face will be missed, but we get the original image, too
+    imageDf = outputDf[outputDf['region']==-1]
+    assert len(imageDf) == 1       # note ONE face will be missed, but we get the original image, too
+    assert imageDf['w'][0] == 1280  # should be the original image size
+    assert len(imageDf['image_binary'][0]) > 1  # should be the original image size
+    assert len(outputDf[outputDf['image']==0]) == len(outputDf)  # all responses belong to image 0
+    print(outputDf)
+
+
+def env_update(monkeypatch):
+    import sys
+
+    pathRoot = path.dirname(path.dirname(path.dirname(path.abspath(__file__))))
+    print("Adding '{:}' to sys path".format(pathRoot))
+    if pathRoot not in sys.path:
+        monkeypatch.syspath_prepend(pathRoot)
+    return pathRoot
index a7a009d..e3c0d16 100644 (file)
@@ -150,7 +150,6 @@ class FaceDetectTransform(BaseEstimator, ClassifierMixin):
            where mime_type is an image-specifying mime type and binary_string is the raw image bytes
         """
         self.load_cascade()  # JIT load model
-        dfReturn = None
         listData = []
         for image_idx in range(len(X)):
             image_byte = X[FaceDetectTransform.COL_IMAGE_DATA][image_idx]
index f351110..8d22856 100644 (file)
@@ -3,11 +3,8 @@
 # core deployment packages
 acumos
 numpy
+scipy
 sklearn
 pandas
 opencv-python
 
-# testing packages
-# pytest
-# pexpect
-connexion
diff --git a/testing/multi-face_pexels.jpg b/testing/multi-face_pexels.jpg
new file mode 100644 (file)
index 0000000..1c9b02a
Binary files /dev/null and b/testing/multi-face_pexels.jpg differ
diff --git a/testing/requirements.txt b/testing/requirements.txt
deleted file mode 100644 (file)
index 9151191..0000000
+++ /dev/null
@@ -1 +0,0 @@
-connexion
\ No newline at end of file
diff --git a/testing/single-face_pexels.jpg b/testing/single-face_pexels.jpg
new file mode 100644 (file)
index 0000000..40a6925
Binary files /dev/null and b/testing/single-face_pexels.jpg differ
diff --git a/testing/tox-requirements.txt b/testing/tox-requirements.txt
new file mode 100644 (file)
index 0000000..12b4373
--- /dev/null
@@ -0,0 +1,12 @@
+# testing packages
+connexion
+pytest
+
+# core deployment packages
+numpy
+scipy
+sklearn
+pandas
+opencv-python
+# acumos -- disabled until exposed as public library
+
diff --git a/tox.ini b/tox.ini
new file mode 100644 (file)
index 0000000..ebceacd
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,8 @@
+[tox]
+skipsdist = True
+envlist = py35,py36
+
+[testenv]
+deps = -r{toxinidir}/testing/tox-requirements.txt
+#install_command = pip install {opts} {packages}
+commands = pytest -s