-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Data-iterator tutorial made python3 compatible. #9460
Conversation
string to bytes in python 3 environment | ||
|
||
```python | ||
def str_or_bytes(str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mxnet.base.py_str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand it correctly, the output of py_str is a string and input can be either a string or bytes. What we are looking for here is the other way around with input always a string but output can either be a string or bytes.
We can optionally add a similar function to the base.py to get this kind of job done. Let me know your thoughts.
docs/tutorials/basic/data.md
Outdated
|
||
@property | ||
def provide_label(self): | ||
return self._provide_label | ||
return zip(self._label_names, self._label_shapes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you be more specific about your comment here ? :-)
The zip function in python2 used to provide a list of tuples which are not exhausted if you have traversed through them once. In python3 zip returns an iterator which gets "exhausted" if we have traversed through once. We, therefore, are trying to create a new iterator (via zip) for every batch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this already done in __init__
?
self._provide_data = zip(data_names, data_shapes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a guarantee that the functions provide_data and provide_label will be called only once by the caller? If yes, then we don't need to make the change to the function. If no, then we'll have to explicitly call zip every time.
In Python2, zip returns a list. So, the second time you call provide_data fn, the list is used again.
However, in Python 3, zip it returns an iterator. The second time you call provide_data fn, the iterator throws an error since we already exhausted the iterator the first time we called provide_data fn. We, therefore, need to re-initialize via zip everytime we call provide_data.
Faced 2 main issues while executing this http://mxnet.incubator.apache.org/tutorials/basic/data.html tutorial on python3: 1. Zip function has changed in python3. It returns an iterator which gets exhausted after it is iterated over. More info: https://stackoverflow.com/questions/31683959/the-zip-function-in-python-3/31684038#31684038 2. Some of the methods in MXNet assume the parameter to be of type string in python2 but as bytes in python3.
* Data-iterator tutorial made python3 compatible. Faced 2 main issues while executing this http://mxnet.incubator.apache.org/tutorials/basic/data.html tutorial on python3: 1. Zip function has changed in python3. It returns an iterator which gets exhausted after it is iterated over. More info: https://stackoverflow.com/questions/31683959/the-zip-function-in-python-3/31684038#31684038 2. Some of the methods in MXNet assume the parameter to be of type string in python2 but as bytes in python3. * Create list of zipped elements to simplify SimpleIter.
* Data-iterator tutorial made python3 compatible. Faced 2 main issues while executing this http://mxnet.incubator.apache.org/tutorials/basic/data.html tutorial on python3: 1. Zip function has changed in python3. It returns an iterator which gets exhausted after it is iterated over. More info: https://stackoverflow.com/questions/31683959/the-zip-function-in-python-3/31684038#31684038 2. Some of the methods in MXNet assume the parameter to be of type string in python2 but as bytes in python3. * Create list of zipped elements to simplify SimpleIter.
* Data-iterator tutorial made python3 compatible. Faced 2 main issues while executing this http://mxnet.incubator.apache.org/tutorials/basic/data.html tutorial on python3: 1. Zip function has changed in python3. It returns an iterator which gets exhausted after it is iterated over. More info: https://stackoverflow.com/questions/31683959/the-zip-function-in-python-3/31684038#31684038 2. Some of the methods in MXNet assume the parameter to be of type string in python2 but as bytes in python3. * Create list of zipped elements to simplify SimpleIter.
Description
Faced 2 main issues while executing this http://mxnet.incubator.apache.org/tutorials/basic/data.html tutorial on python3:
but as bytes in python3.
Checklist
Essentials
make lint
)Changes
Comments