a-PyTorch-Tutorial-to-Image-Captioning icon indicating copy to clipboard operation
a-PyTorch-Tutorial-to-Image-Captioning copied to clipboard

Running on latest PyTorch 1.2.0

Open fikrisyad opened this issue 6 years ago • 16 comments

Hello, thank you for the tutorial! I tried to run your code on PyTorch 1.2.0 and it seems I couldn't produce your scores. The bleu-4 score is peaked at epoch 10 (without fine-tuning) and after that, I continued to train it with fine-tuning but it seems the bleu-4 score couldn't improve.

oh yes, obviously I made some changes to make it run on PyTorch 1.2.0: in train.py I changed scores, _ = pack_padded_sequence(scores, decode_lengths, batch_first=True) targets, _ = pack_padded_sequence(targets, decode_lengths, batch_first=True) to scores = pack_padded_sequence(scores, decode_lengths, batch_first=True) targets = pack_padded_sequence(targets, decode_lengths, batch_first=True)

and take the data using scores.data and targets.data

I thought that shouldn't be a problem, but I'm not sure now.

Any idea what's the problem? Thank you.

fikrisyad avatar Sep 18 '19 07:09 fikrisyad

@fikrisyad didn't you get error like below?

line 1316, in log_softmax ret = input.log_softmax(dim) AttributeError: 'PackedSequence' object has no attribute 'log_softmax'

if you fix it somehow, please let me know I'm using PyTorch1.20 on Ubuntu

RonenHong avatar Sep 25 '19 05:09 RonenHong

@RonenHong yes I did encounter that issue at first

as I mentioned above, I retrieved the data of PackedSequence using packed.data

so, when I used scores.data and targets.data as input for the loss function

fikrisyad avatar Sep 30 '19 07:09 fikrisyad

Instead of putting <>.data at other places as well, I did below replacement and that worked for me without any other errors:

in train.py I changed scores, _ = pack_padded_sequence(scores, decode_lengths, batch_first=True) targets, _ = pack_padded_sequence(targets, decode_lengths, batch_first=True) to scores = pack_padded_sequence(scores, decode_lengths, batch_first=True).data targets = pack_padded_sequence(targets, decode_lengths, batch_first=True).data

Other thing that might be helpful is to modify the save_checkpoint method for saving the trained models following this as current method breaks when changing the directory or code structure while loading saved models.

mayankkumar-srijan avatar Oct 08 '19 21:10 mayankkumar-srijan

@mayankatsrijan thank you, that's neat

Have you trained your model? could you reproduce the scores?

fikrisyad avatar Oct 09 '19 02:10 fikrisyad

@fikrisyad My training is still in its initial stage and currently I have trained it for only 2 epochs as each epoch is taking 3.5 Hrs to complete. I'm using coco train (13GB) and valid(6.2GB) dataset. * LOSS - 3.480, TOP-5 ACCURACY - 71.946, BLEU-4 - 0.1906105647424692 Above is the BLEU score I'm getting for now.

mayankkumar-srijan avatar Oct 09 '19 22:10 mayankkumar-srijan

@fikrisyad hi I use pytorch 1.2.0 too. Can I ask the score you achieve. Now I have trained it for 4 epochs, but the score just is 0.15, i wonder if its something wrong. thanks!

ZhangDaBen avatar Oct 15 '19 12:10 ZhangDaBen

@ZhangDaBen hi, it's about the same, I couldn't reach 0.2 even after following the instruction (training by stage) hopefully, someone can point out the problem.

fikrisyad avatar Oct 17 '19 04:10 fikrisyad

@fikrisyad Thanks very much for your reply! I have one more question.Have you run the eval.py? when I run that, it get the below error: max() arg is an empty sequence with the line i = complete_seqs_scores.index(max(complete_seqs_scores)) But i dont konw how to fix it.

ZhangDaBen avatar Oct 17 '19 08:10 ZhangDaBen

this issue help solve the bug about "pytorch AttributeError: 'PackedSequence' object has no attribute 'size'" thanks a lot

Archer-Fang avatar Dec 27 '19 13:12 Archer-Fang

AttributeError: 'PackedSequence' object has no attribute 'log_softmax' how did you fix it?

uuzgu avatar Apr 08 '20 19:04 uuzgu

@mayankatsrijan in https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Image-Captioning/issues/86#issuecomment-539709462

Other thing that might be helpful is to modify the save_checkpoint method for saving the trained models following this as current method breaks when changing the directory or code structure while loading saved models.

can you tell me how and where to modify the save_checkpoint method in detail? is it in train.py and utils.py?

nyj-ocean avatar May 02 '20 05:05 nyj-ocean

@fikrisyad @ZhangDaBen in https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Image-Captioning/issues/86#issuecomment-536429879

as I mentioned above, I retrieved the data of PackedSequence using packed.data so, when I used scores.data and targets.data as input for the loss function

how and where to modify to use scores.data and targets.data as input for the loss function?

nyj-ocean avatar May 02 '20 06:05 nyj-ocean

@Archer-Fang @uuzgu

AttributeError: 'PackedSequence' object has no attribute 'log_softmax'

have you fixed this error? how to fix it?

nyj-ocean avatar May 02 '20 06:05 nyj-ocean

@nyj-ocean You can change the save_checkpoint method in utils.py by replacing the current state dictionary with something like this one: state = { "epoch": epoch, "epochs_since_improvement": epochs_since_improvement, "bleu-4": bleu4, "encoder_state_dict": encoder.state_dict(), "decoder_state_dict": decoder.state_dict(), "encoder_optimizer_state_dict": encoder_optimizer.state_dict() if encoder_optimizer is not None else None, "decoder_optimizer_state_dict": decoder_optimizer.state_dict() if decoder_optimizer is not None else None, } Here instead of saving entire encoder model, we are just saving its weights values. Also, do modify the train.py accordingly to incorporate these changes.

mayankkumar-srijan avatar May 02 '20 07:05 mayankkumar-srijan

@mayankatsrijan I want to train with my own dataset , but I don't know how to create a json file of my own dataset like dataset_coco.json file ? can you help me ?

nyj-ocean avatar May 07 '20 06:05 nyj-ocean

Basically

@mayankatsrijan I want to train with my own dataset , but I don't know how to create a json file of my own dataset like dataset_coco.json file ? can you help me ?

Basically follow the steps given in def create_input_files. Its basically creating a word2ind dictionary and shouldnt be complicated

darthgera123 avatar Nov 20 '20 11:11 darthgera123