Quellcode durchsuchen

im2txt: make python3 compatible adding lt and eq

__cmp__ is deprecated on python3, so it fails to compare class Caption on python3
Jun Kim vor 9 Jahren
Ursprung
Commit
306fad2c3a
1 geänderte Dateien mit 10 neuen und 0 gelöschten Zeilen
  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):