Browse Source

Merge pull request #842 from tae-jun/patch-1

im2txt: make python3 compatible adding lt and eq
Chris Shallue 8 năm trước cách đây
mục cha
commit
2cd62f6c6d
1 tập tin đã thay đổi với 10 bổ sung0 xóa
  1. 10 0
      im2txt/im2txt/inference_utils/caption_generator.py

+ 10 - 0
im2txt/im2txt/inference_utils/caption_generator.py

@@ -54,6 +54,16 @@ class Caption(object):
       return -1
     else:
       return 1
+  
+  # For Python 3 compatibility (__cmp__ is deprecated).
+  def __lt__(self, other):
+    assert isinstance(other, Caption)
+    return self.score < other.score
+  
+  # Also for Python 3 compatibility.
+  def __eq__(self, other):
+    assert isinstance(other, Caption)
+    return self.score == other.score
 
 
 class TopN(object):