Bladeren bron

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 jaren geleden
bovenliggende
commit
306fad2c3a
1 gewijzigde bestanden met toevoegingen van 10 en 0 verwijderingen
  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):