coco-caption
coco-caption copied to clipboard
Tokenizer: `OSError: [Errno 2] No such file or directory`
Like in https://github.com/tylin/coco-caption/issues/22#issue-231528122 , I got
OSError: [Errno 2] No such file or directory: 'java'
When running the evaluation, even with java definitely installed. This SO discusses it: https://stackoverflow.com/a/55675914/2332296. I was able to solve it by setting shell=True
and making cmd
in
p_tokenizer = subprocess.Popen(cmd, cwd=path_to_jar_dirname, stdout=subprocess.PIPE, shell=True)
from
cmd = ['java', '-cp', 'stanford-corenlp-3.4.1.jar', 'edu.stanford.nlp.process.PTBTokenizer', '-preserveLines', '-lowerCase', 'tmpWS5p0Z']
(where 'tmpWS5p0Z' is the name of the tempfile.NamedTemporaryFile
that is added), into:
cmd = ['/abs/path/to/java -cp /abs/path/to/stanford-corenlp-3.4.1.jar edu.stanford.nlp.process.PTBTokenizer -preserveLines -lowerCase /abs/path/to/temporary_file']
I solved this error, by using absolute path in sys.path.append() to include the coco-caption file . I still get this error running in Pycharm,but it works well by using terminal command
@rubencart hi, how can I get the name of 'tmpWS5p0Z' according to your answer.
@ynuwm that is automatically added by the line cmd.append(os.path.join(path_to_jar_dirname, os.path.basename(tmp_file.name)))
. Just change that line into cmd[0] += os.path.join(path_to_jar_dirname, os.path.basename(tmp_file.name))
ok, I get it, thank you very much.