Skip to content

Commit ab5ac31

Browse files
committed
edit image captioning code
1 parent 286f7b7 commit ab5ac31

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

tutorials/03-advanced/image_captioning/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ $ python sample.py --image='png/example.png'
5656
<br>
5757

5858
## Pretrained model
59-
If you do not want to train the model from scratch, you can use a pretrained model. I have provided the pretrained model as a zip file. You can download the file [here](https://www.dropbox.com/s/bmo30z81a4v7m0r/pretrained_model.zip?dl=0) and extract it to `./models/` directory using `unzip pretrained_model.zip`.
59+
If you do not want to train the model from scratch, you can use a pretrained model. I have provided the pretrained model as a zip file. You can download the pretrained model [here](https://www.dropbox.com/s/ne0ixz5d58ccbbz/pretrained_model.zip?dl=0) and vocabulary file [here](https://www.dropbox.com/s/26adb7y9m98uisa/vocap.zip?dl=0). Note that you should extract pretrained_model.zip to `./models/` and vocab.pkl to `./data/`.

tutorials/03-advanced/image_captioning/build_vocab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def main(args):
5959
threshold=args.threshold)
6060
vocab_path = args.vocab_path
6161
with open(vocab_path, 'wb') as f:
62-
pickle.dump(vocab, f, pickle.HIGHEST_PROTOCOL)
62+
pickle.dump(vocab, f)
6363
print("Total vocabulary size: %d" %len(vocab))
6464
print("Saved the vocabulary wrapper to '%s'" %vocab_path)
6565

6666

6767
if __name__ == '__main__':
6868
parser = argparse.ArgumentParser()
6969
parser.add_argument('--caption_path', type=str,
70-
default='./data/annotations/captions_train2014.json',
70+
default='/usr/share/mscoco/annotations/captions_train2014.json',
7171
help='path for train annotation file')
7272
parser.add_argument('--vocab_path', type=str, default='./data/vocab.pkl',
7373
help='path for saving vocabulary wrapper')

tutorials/03-advanced/image_captioning/sample.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def main(args):
4747
encoder.load_state_dict(torch.load(args.encoder_path))
4848
decoder.load_state_dict(torch.load(args.decoder_path))
4949

50-
# Prepare Image
50+
# Prepare Image
5151
image = load_image(args.image, transform)
5252
image_tensor = to_var(image, volatile=True)
5353

@@ -72,6 +72,7 @@ def main(args):
7272

7373
# Print out image and generated caption.
7474
print (sentence)
75+
image = Image.open(args.image)
7576
plt.imshow(np.asarray(image))
7677

7778
if __name__ == '__main__':

0 commit comments

Comments
 (0)