ruotianluo / ImageCaptioning.pytorch

I decide to sync up this repo and self-critical.pytorch. (The old master is in old master branch for archive)
MIT License
1.44k stars 412 forks source link

ModuleNotFoundError: No module named 'captioning.modules' #110

Closed Tahiya31 closed 4 years ago

Tahiya31 commented 4 years ago

Hi @ruotianluo,

I am trying to use the pretrained model to perform evaluation on my own images.

when I run the command python tools/eval.py --model model.pth --infos_path infos.pkl --image_folder blah --num_images 10, I encounter this error:

Warning: coco-caption not available Traceback (most recent call last): File "tools/eval.py", line 19, in import captioning.modules.losses as losses ModuleNotFoundError: No module named 'captioning.modules'

I see that captioning has several other modules (models, data, utils) which are being imported fine. But modules are not. Can you please take a look? Thanks!

ruotianluo commented 4 years ago

you can run pip install -e . under the root directory.

Tahiya31 commented 4 years ago

Thanks, @ruotianluo! That resolved my issue.

But now when I run the command python tools/eval.py --model model.pth --infos_path infos.pkl --image_folder blah --num_images 10in ImageCaptioning.pytorch, I get this:

loading annotations into memory... 0:00:00.354726 creating index... index created! Traceback (most recent call last): File "tools/eval.py", line 74, in lang_stats = eval_utils.language_eval(opt.input_json, predictions, n_predictions, vars(opt), opt.split) File "/Users/Desktop/ImageCaptioning.pytorch/captioning/utils/eval_utils.py", line 82, in language_eval meanperplexity = sum([['perplexity'] for _ in preds_filt]) / len(preds_filt) ZeroDivisionError: division by zero

Any idea on what caused this? I basically just want to generate captions of some images that I have under blah using the pretrained model.

ruotianluo commented 4 years ago

add --force --language_eval 0 may solve it.

Tahiya31 commented 4 years ago

I added --force 1 --language_eval 0in the command, and it worked! Thanks a lot!

The only issue is the images are being processed at random order. I have 800+ images named frame0, frame3... and so on. When I run the command to generate captions, the images are processed in this order: frame597, frame 1188...like this.

DataLoaderRaw found 812 images cp "blah/frame597.jpg" vis/imgs/img1.jpg image 1: a man is standing on the side of a building with a clock tower cp "blah/frame1188.jpg" vis/imgs/img2.jpg image 2: a red double decker bus driving down a city street cp "blah/frame1836.jpg" vis/imgs/img3.jpg image 3: a building with a clock tower on top of it cp "blah/frame1605.jpg" vis/imgs/img4.jpg

So I am losing the order of my image in the result.

Is there any way to fix it so that frame0->img1, frame3->img2 ? Thanks again!

ruotianluo commented 4 years ago

You can try add sorting here https://github.com/ruotianluo/ImageCaptioning.pytorch/blob/master/captioning/data/dataloaderraw.py#L79

Tahiya31 commented 4 years ago

I added this below the line you pointed:

self.files.sort(key=lambda f: int(''.join(filter(str.isdigit, f))))

And it worked nicely! Thanks a lot for your help!