Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Some Python 3 fixes in ./example#11671

Merged
zhreshold merged 2 commits intoapache:masterfrom
cclauss:fix-examples-for-Python3
Jul 16, 2018
Merged

Some Python 3 fixes in ./example#11671
zhreshold merged 2 commits intoapache:masterfrom
cclauss:fix-examples-for-Python3

Conversation

@cclauss
Copy link
Copy Markdown
Contributor

@cclauss cclauss commented Jul 12, 2018

Description

Fix undefined names found be flake8 F821 that are mostly (but not exclusively) related to Python 3. Each undefined name has the potential to raise NameError at runtime. Used the six module as discussed at #10833 (comment) Also see #11669

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@cclauss cclauss requested a review from szha as a code owner July 12, 2018 17:58
@szha
Copy link
Copy Markdown
Member

szha commented Jul 12, 2018

Pinging @antinucleon @precedenceguo @WellyZhang @zhreshold, respective example contributors, in case there are concerns.

Comment thread example/ssd/dataset/pycocotools/coco.py Outdated
if PYTHON_VERSION == 2:
from urllib import urlretrieve
elif PYTHON_VERSION == 3:
from six.moves import string_types
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think six is existing dependency of mxnet. For sring_types you can use mxnet.base.string_types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file does not import mxnet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to follow the advise in #10833 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with #10833, since mxnet is always a dependency, so I guess import it and use mxnet.base.string_types is better, otherwise users will complain it six is not installed.

@ijkguo
Copy link
Copy Markdown
Contributor

ijkguo commented Jul 12, 2018

I see 2 pycocotools files changed. I would suggest removing copied version of pycocotools from both ssd and rcnn examples. The pip version works just fine in gluon-cv.

I did update the rcnn example at #11373. Seems like a huge diff but the core logic did not change at all although duplicate codes are gone.

@cclauss cclauss mentioned this pull request Jul 13, 2018
7 tasks
@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Jul 15, 2018

@zhreshold @ijkguo Did you want to see further changes made?

@ijkguo
Copy link
Copy Markdown
Contributor

ijkguo commented Jul 15, 2018

No change necessary on rcnn example. I tested with Python 3.

@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Jul 15, 2018

Agreed. I had removed the rcnn example from this PR as you suggested.

Comment thread example/kaggle-ndsb1/gen_img_list.py Outdated
import random
import numpy as np
import argparse
from six.moves import xrange
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just replace xrange with range for python3 compatibility, since there's no performance issue here.

import pyprind
import mxnet as mx
import numpy as np
from mxnet.base import xrange
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here for the xrange

Comment thread example/ssd/dataset/pycocotools/coco.py Outdated
if PYTHON_VERSION == 2:
from urllib import urlretrieve
elif PYTHON_VERSION == 3:
from six.moves import string_types
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with #10833, since mxnet is always a dependency, so I guess import it and use mxnet.base.string_types is better, otherwise users will complain it six is not installed.

@zhreshold
Copy link
Copy Markdown
Member

@cclauss Thanks for catching these compatibility issues, we can merge once these comments are addressed!

@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Jul 16, 2018

@szha
Copy link
Copy Markdown
Member

szha commented Jul 16, 2018

This should have been fixed by #11633. Could you do a rebase, @cclauss?

@cclauss
Copy link
Copy Markdown
Contributor Author

cclauss commented Jul 16, 2018

Yes... It succeeded after rebasing.

@zhreshold zhreshold merged commit bcf4245 into apache:master Jul 16, 2018
@cclauss cclauss deleted the fix-examples-for-Python3 branch July 16, 2018 21:41
aaronmarkham pushed a commit to aaronmarkham/incubator-mxnet that referenced this pull request Jul 17, 2018
* Some Python 3 fixes in ./example

* mxnet.base.string_types and xrange() --> range()
KellenSunderland pushed a commit to KellenSunderland/incubator-mxnet that referenced this pull request Jul 19, 2018
* Some Python 3 fixes in ./example

* mxnet.base.string_types and xrange() --> range()
KellenSunderland pushed a commit to KellenSunderland/incubator-mxnet that referenced this pull request Jul 21, 2018
* Some Python 3 fixes in ./example

* mxnet.base.string_types and xrange() --> range()
XinYao1994 pushed a commit to XinYao1994/incubator-mxnet that referenced this pull request Aug 29, 2018
* Some Python 3 fixes in ./example

* mxnet.base.string_types and xrange() --> range()
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants