Traceback (most recent call last):
File “/usr/ML/image-captioning-oscar-main/oscar/run_captioning.py”, line from oscar.utils.caption_evaluate import (evaluate_on_coco_caption,
File “/usr/ML/image-captioning-oscar-main/oscar/utils/caption_evaluate.py”, line from coco_caption.pycocoevalcap.eval import COCOEvalCap
File “/usr/ML/image-captioning-oscar-main/oscar/coco_caption/pycocoevalcap/tokenizer/ptbtokenizer.py”, line from tokenizer.ptbtokenizer import PTBTokenizer
ModuleNotFoundError: No module named ‘tokenizer’
I’ve provided my project’s directory structure for additional context. Here’s how the relevant directories look:
usr/
└── ML/
└── image-captioning-oscar-main/
└── oscar/
├── datasets/
│ ├── init.py
│ ├── build.py
│ └── caption_tsv.py
├── modeling/
│ ├── init.py
│ ├── modeling_bert.py
│ └── modeling_utils.py
├── utils/
│ ├── init.py
│ ├── infer_on_single.py
│ └── run_captioning.py
└── scripts/
├── README.md
└── requirements.txt
It appears the tokenizer module, which is needed by the run_captioning.py script, is not present in this directory structure. Could this be an issue of the module being located elsewhere, or should I install this module separately?
Please verify if tokenizer is supposed to be part of another installed package or if it should be included in your project directory. If it’s supposed to be part of your project, ensure that the directory exists where Python expects it, and that it’s included in your project files. If tokenizer is a third-party library, make sure it’s installed correctly in your Python environment. If it’s missing, you might need to install it via pip or conda, or ensure that your environment has the correct path settings.
What I tried:
Checked the directory structure: I verified that the directory structure of my project contains the tokenizer module and it includes an init.py file to be recognized as a Python package.
Checked the Python path: I added the directory containing the tokenizer module to the Python path to ensure it is detectable by Python.
Verified imports: I ensured that the import statements in other parts of the project were working correctly, which suggested the issue might be specific to how the tokenizer module was being imported or its location.
What I was expecting:
I expected Python to find and import the PTBTokenizer class from the tokenizer.ptbtokenizer module without any issues. The script should have been able to use this module to tokenize strings as part of the image captioning process. Instead, I encountered a ModuleNotFoundError, which indicates that Python could not locate the tokenizer module even though it appears to be correctly placed within the project’s directory structure and properly structured as a package.
sivala nandini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.