Models: im2txt Caption class comparison fails in Python 3.5

Created on 2 Jan 2017  路  2Comments  路  Source: tensorflow/models

models/im2txt

Caption class comparison fails in Python 3.5 because Python 2's __cmp__ is deprecated in 3+

@cshallue

I was trying to run #466 on Python 3.5 and I was getting the following error:

Traceback (most recent call last):
File "test.py", line 84, in
tf.app.run()
File "/data/venvs/tensorflow/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 43, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "test.py", line 74, in main
captions = generator.beam_search(sess, image)
File "/media/scott/BigHD/Code/tensorflow_ex/im2txt/inference_utils/caption_generator.py", line 193, in beam_search
partial_captions.push(beam)
File "/media/scott/BigHD/Code/tensorflow_ex/im2txt/inference_utils/caption_generator.py", line 77, in push
heapq.heappush(self._data, x)
TypeError: unorderable types: Caption() < Caption()

The Caption class only implements __cmp__, but needs __lt__ and __eq__ for Python 3. It's a simple addition that would help compatibility between the versions. I'm not sure if you're planning on supporting Python 3, but everything else worked out of the box except this when I ran the run_inference.py file from the repo.

bug

Most helpful comment

@tae-jun it looks good to me. I did a similar fix on my own local.

All 2 comments

Hi @srome, I made #842 for this. Please check!

Thanks 馃槃

@tae-jun it looks good to me. I did a similar fix on my own local.

Was this page helpful?
0 / 5 - 0 ratings