This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new 12cbcea  [MXNET-307] Add utility to get im2rec.py path (#10565)
12cbcea is described below

commit 12cbceaf37ee6d8d5361dceea4822cfd12236dfe
Author: ThomasDelteil <thomas.delte...@gmail.com>
AuthorDate: Mon Apr 16 14:11:57 2018 -0700

    [MXNET-307] Add utility to get im2rec.py path (#10565)
    
    * Update data.md
    
    Change strategy to get im2rec_path
    
    * Update test_utils.py
    
    * Update data.md
    
    * Update test_utils.py
    
    * Update test_utils.py
---
 docs/tutorials/basic/data.md |  3 +--
 python/mxnet/test_utils.py   | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/docs/tutorials/basic/data.md b/docs/tutorials/basic/data.md
index fdd5015..0a5dd59 100644
--- a/docs/tutorials/basic/data.md
+++ b/docs/tutorials/basic/data.md
@@ -391,8 +391,7 @@ Now let's convert them into record io format using the 
`im2rec.py` utility scrip
 First, we need to make a list that contains all the image files and their 
categories:
 
 ```python
-mxnet_path = os.path.dirname(mx.__file__)
-im2rec_path = os.path.join(mxnet_path, 'tools','im2rec.py')
+im2rec_path = mx.test_utils.get_im2rec_path()
 data_path = os.path.join('data','101_ObjectCategories')
 prefix_path = os.path.join('data','caltech')
 
diff --git a/python/mxnet/test_utils.py b/python/mxnet/test_utils.py
index d4d8ad2..aa388c1 100644
--- a/python/mxnet/test_utils.py
+++ b/python/mxnet/test_utils.py
@@ -1732,6 +1732,36 @@ def mean_check(generator, mu, sigma, nsamples=1000000):
           (sample_mean < mu + 3 * sigma / np.sqrt(nsamples))
     return ret
 
+def get_im2rec_path(home_env="MXNET_HOME"):
+    """Get path to the im2rec.py tool
+
+    Parameters
+    ----------
+
+    home_env : str
+        Env variable that holds the path to the MXNET folder
+
+    Returns
+    -------
+    str
+        The path to im2rec.py
+    """
+    # Check first if the path to MXNET is passed as an env variable
+    if home_env in os.environ:
+        mxnet_path = os.environ[home_env]
+    else:
+        # Else use currently imported mxnet as reference
+        mxnet_path = os.path.dirname(mx.__file__)
+    # If MXNet was installed through pip, the location of im2rec.py
+    im2rec_path = os.path.join(mxnet_path, 'tools', 'im2rec.py')
+    if os.path.isfile(im2rec_path):
+        return im2rec_path
+    # If MXNet has been built locally
+    im2rec_path = os.path.join(mxnet_path, '..', '..', 'tools', 'im2rec.py')
+    if os.path.isfile(im2rec_path):
+        return im2rec_path
+    raise IOError('Could not find path to tools/im2rec.py')
+
 def var_check(generator, sigma, nsamples=1000000):
     """Test the generator by matching the variance.
     It will need a large number of samples and is not recommended to use

-- 
To stop receiving notification emails like this one, please contact
j...@apache.org.

Reply via email to