From 60e49614c284a00ecb546b35d3b6b59a1a36d978 Mon Sep 17 00:00:00 2001 From: "Xiaojian \"JJ\" Deng" Date: Wed, 23 May 2018 20:20:32 -0500 Subject: [PATCH] Fix error with oov_token I had gotten an error that your tokenizer object had no oov_token variable and found a solution via Stackoverflow. I had to insert that line (and also put an image at data/example.jpg) to get your code to work, in addition to following your instructions. --- test_images.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test_images.py b/test_images.py index e899bb5..30a51f9 100644 --- a/test_images.py +++ b/test_images.py @@ -33,6 +33,8 @@ def load_feature_model(self): def load_tokenizer(self): self.tokenizer = load(open("pkl/tokenizer.pkl", 'rb')) + #See: https://stackoverflow.com/questions/49861842/attributeerror-tokenizer-object-has-no-attribute-oov-token-in-keras + self.tokenizer.oov_token = None self.details = load(open("pkl/detail.pkl", 'rb')) self.max_length = self.details['max_length'] self.vocab_size = self.details['vocab_size'] @@ -89,4 +91,4 @@ def get_caption(self, image_file_path): cv2.putText(image, caption, (10, image.shape[0]-100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_4) cv2.imwrite("example_output.jpg", image) cv2.imshow("Image Captioning", image) - cv2.waitKey(2000) \ No newline at end of file + cv2.waitKey(2000)