a-PyTorch-Tutorial-to-Image-Captioning
a-PyTorch-Tutorial-to-Image-Captioning copied to clipboard
Running on latest PyTorch 1.2.0
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 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 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
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.
@mayankatsrijan thank you, that's neat
Have you trained your model? could you reproduce the scores?
@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.
@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 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 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.
this issue help solve the bug about "pytorch AttributeError: 'PackedSequence' object has no attribute 'size'" thanks a lot
AttributeError: 'PackedSequence' object has no attribute 'log_softmax' how did you fix it?
@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?
@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?
@Archer-Fang @uuzgu
AttributeError: 'PackedSequence' object has no attribute 'log_softmax'
have you fixed this error? how to fix it?
@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.
@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
@mayankatsrijan I want to train with my own dataset , but I don't know how to create a
jsonfile of my own dataset likedataset_coco.jsonfile ? can you help me ?
Basically follow the steps given in def create_input_files. Its basically creating a word2ind dictionary and shouldnt be complicated