소스 검색

im2txt: make python3 compatible adding lt and eq

__cmp__ is deprecated on python3, so it fails to compare class Caption on python3
Jun Kim 9 년 전
부모
커밋
306fad2c3a
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  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 version 3 compatibility (__cmp__ is deprecated)
+  def __lt__(self, other):
+    assert isinstance(other, Caption)
+    return self.score < other.score
+  
+  # also for version 3 compatibility
+  def __eq__(self, other):
+    assert isinstance(other, Caption)
+    return self.score == other.score
 
 
 class TopN(object):