tensorflow / models

Models and examples built with TensorFlow
Other
77.25k stars 45.75k forks source link

from six.moves import xrange #3103

Closed cclauss closed 6 years ago

cclauss commented 6 years ago

The following files are incompatible with Python 3 at least in part because they use xrange() yet they lack the import:

shivaniag commented 6 years ago

@nealwu mind taking a quick look?

nealwu commented 6 years ago

Hi @cclauss, we don't officially maintain the research/ folder; that is up to the individual researchers. However, if you're able to create a pull request to fix this issue en masse, I'm happy to take a look at it.

rickhg12hs commented 6 years ago

Or maybe something like this could be strategically placed?

import sys

if sys.version_info >= (3, 0):
    def xrange(*args, **kwargs):
        return iter(range(*args, **kwargs))
nealwu commented 6 years ago

@rickhg12hs we prefer to use six for this purpose. It also provides a number of other Python 2/3 compatibility fixes; you can see https://pythonhosted.org/six/for a full list.

rickhg12hs commented 6 years ago

@nealwu Yeah, six should be a better solution. Is there a magical place to import it smartly?

nealwu commented 6 years ago

Closing thanks to the above fix from @cclauss.

adnananjum commented 6 years ago

hello sir

adnananjum commented 6 years ago

import numpy as np import random from six.moves import cPickle as pickle from TwitterElection.Embedding import MeanEmbeddingVectorizer from TwitterElection.TopicModel import TopicModel from gensim.models.word2vec import Word2Vec

Python 3.5 environment

Last updated: Feb 19, 2017

Written by Melissa K

INPUT_DIR = '/path/to/data/en/' # subfolder with all english tweets only OUTPUT_DIR = '/path/to/data/'

def save_pickle(fname, tweets): with open(fname + '.pickle', 'wb') as f: pickle.dump(tweets, f, pickle.HIGHEST_PROTOCOL)

def load_pickle(fname): with open(fname + '.pickle', 'rb') as f: tweets = pickle.load(f) return tweets error is invaild path plz help us

renewang commented 6 years ago

FYI, I was trying to run model_builder_test.py and found another xrange without six.moves.xrange import statement in models/research/object_detection/anchor_generators/multiscale_grid_anchor_generator.py

rickhg12hs commented 6 years ago

@renewang Looking at models/research/object_detection/anchor_generators/multiscale_grid_anchor_generator.py in the master branch, I don't see an xrange.

cclauss commented 6 years ago

flake8 running on Python 3.7 found 21 instances of xrange() as an undefined name...

./research/differential_privacy/pate/ICLR2018/rdp_bucketized.py:79:12: F821 undefined name 'xrange'
./research/differential_privacy/pate/ICLR2018/rdp_bucketized.py:106:12: F821 undefined name 'xrange'
./research/differential_privacy/pate/ICLR2018/rdp_bucketized.py:139:12: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/graph_builder_test.py:428:20: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/network_units.py:2334:14: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/network_units.py:2413:24: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/spec_builder.py:251:16: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/spec_builder.py:255:14: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/runtime_support.py:306:54: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/trainer_lib.py:40:16: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/trainer_lib.py:100:21: F821 undefined name 'xrange'
./research/syntaxnet/dragnn/python/trainer_lib.py:106:23: F821 undefined name 'xrange'
./research/learning_unsupervised_learning/utils.py:123:12: F821 undefined name 'xrange'
./research/learning_unsupervised_learning/utils.py:176:16: F821 undefined name 'xrange'
./research/learning_unsupervised_learning/summary_utils.py:136:12: F821 undefined name 'xrange'
./research/learning_unsupervised_learning/summary_utils.py:159:12: F821 undefined name 'xrange'
./research/learning_unsupervised_learning/meta_objective/utils.py:53:14: F821 undefined name 'xrange'
./research/learning_unsupervised_learning/meta_objective/linear_regression.py:105:14: F821 undefined name 'xrange'
./research/seq2species/test_utils.py:70:14: F821 undefined name 'xrange'
./research/seq2species/test_utils.py:101:46: F821 undefined name 'xrange'
./research/seq2species/build_model.py:382:14: F821 undefined name 'xrange'
cclauss commented 6 years ago

__./research/object_detection has at least three Python 3 incompatibilities but not an xrange() issue... (Unless of course it is hidden behind one of the legacy print__ statements).

./research/object_detection/utils/object_detection_evaluation.py:307:27: F821 undefined name 'unicode'
          category_name = unicode(category_name, 'utf-8')
                          ^
./research/object_detection/meta_architectures/ssd_meta_arch_test.py:684:21: E999 SyntaxError: invalid syntax
    print num_classes, num_anchors
                    ^
./research/object_detection/dataset_tools/oid_hierarchical_labels_expansion.py:157:55: E999 SyntaxError: invalid syntax
    print '--annotation_type expected value is 1 or 2.'
                                                      ^