You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2016/10/07 03:54:38 UTC

incubator-singa git commit: update docs for image_tool.py and data.py

Repository: incubator-singa
Updated Branches:
  refs/heads/master 8cf18e5b0 -> 80555151a


update docs for image_tool.py and data.py


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/80555151
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/80555151
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/80555151

Branch: refs/heads/master
Commit: 80555151a272ea4b73a09901fa144590ec80f4da
Parents: 8cf18e5
Author: Wei Wang <wa...@comp.nus.edu.sg>
Authored: Fri Oct 7 11:53:26 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Fri Oct 7 11:53:26 2016 +0800

----------------------------------------------------------------------
 doc/en/docs/data.rst       | 25 +++++++++++++++++++++++++
 doc/en/docs/image_tool.rst | 23 +++++++++++++++++++++++
 doc/en/docs/index.rst      |  2 ++
 python/singa/data.py       | 33 ++++++++++++++++++++++++++++++++-
 python/singa/image_tool.py | 15 ++++++++++++++-
 5 files changed, 96 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/80555151/doc/en/docs/data.rst
----------------------------------------------------------------------
diff --git a/doc/en/docs/data.rst b/doc/en/docs/data.rst
new file mode 100644
index 0000000..d495dfd
--- /dev/null
+++ b/doc/en/docs/data.rst
@@ -0,0 +1,25 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you 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
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License 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.
+
+
+Data
+========
+
+
+
+.. automodule:: singa.data
+   :members:

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/80555151/doc/en/docs/image_tool.rst
----------------------------------------------------------------------
diff --git a/doc/en/docs/image_tool.rst b/doc/en/docs/image_tool.rst
new file mode 100644
index 0000000..764f036
--- /dev/null
+++ b/doc/en/docs/image_tool.rst
@@ -0,0 +1,23 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you 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
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License 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.
+
+
+Image Tool
+==========
+
+.. automodule:: singa.image_tool
+   :members:

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/80555151/doc/en/docs/index.rst
----------------------------------------------------------------------
diff --git a/doc/en/docs/index.rst b/doc/en/docs/index.rst
index d6d7516..29417d6 100644
--- a/doc/en/docs/index.rst
+++ b/doc/en/docs/index.rst
@@ -30,4 +30,6 @@ Documentation
    loss
    metric
    optimizer
+   data
+   image_tool
    examples/index

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/80555151/python/singa/data.py
----------------------------------------------------------------------
diff --git a/python/singa/data.py b/python/singa/data.py
index 725b175..f9f6c78 100644
--- a/python/singa/data.py
+++ b/python/singa/data.py
@@ -16,7 +16,38 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-'''Utilities for data loading and preprocessing'''
+'''
+This module includes classes for loading and prefetching data batches.
+
+Example usage::
+
+    import image_tool
+    from PIL import Image
+
+    tool = image_tool.ImageTool()
+
+    def image_transform(img_path):
+        global tool
+        return tool.load(img_path).resize_by_range(
+            (112, 128)).random_crop(
+            (96, 96)).flip().get()
+
+    data = ImageBatchIter('train.txt', 3,
+                          image_transform, shuffle=True, delimeter=',',
+                          image_folder='images/',
+                          capacity=10)
+    data.start()
+    # imgs is a numpy array for a batch of images,
+    # shape: batch_size, 3 (RGB), height, width
+    imgs, labels = data.next()
+
+    # convert numpy array back into images
+    for idx in range(imgs.shape[0]):
+        img = Image.fromarray(imgs[idx].astype(np.uint8).transpose(1, 2, 0),
+                              'RGB')
+        img.save('img%d.png' % idx)
+    data.end()
+'''
 
 import os
 import random

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/80555151/python/singa/image_tool.py
----------------------------------------------------------------------
diff --git a/python/singa/image_tool.py b/python/singa/image_tool.py
index 9c1741d..42fbf09 100644
--- a/python/singa/image_tool.py
+++ b/python/singa/image_tool.py
@@ -14,6 +14,20 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # =============================================================================
+'''
+An utility model for image augmentation.
+
+Example usage::
+
+    from singa import image_tool
+
+    tool = image_tool.ImageTool()
+    imgs = tool.load('input.png').\
+        resize_by_list([112]).crop5((96, 96), 5).enhance().flip().get()
+    for idx, img in enumerate(imgs):
+        img.save('%d.png' % idx)
+
+'''
 
 import random
 import numpy as np
@@ -246,7 +260,6 @@ class ImageTool():
         else:
             return new_imgs
 
-
     def rotate_by_range(self, rng, inplace=True):
         '''
         Args: