The import OS
The import sys
The import subprocess
The import threading
# Assumes meteor - 1.5. The jar is in the same directory as meteor. Py. Change as men.
METEOR_JAR='meteor - 1.5. Jar'
# print METEOR_JAR
The class Meteor:
Def __init__ (self) :
Self. Meteor_cmd=[' Java ', '- jar', '- Xmx2G, METEOR_JAR, \
'-', '-', '-' stdio ', 'l', 'en', '- norm']
Self. Meteor_p=subprocess. Popen (self. Meteor_cmd \
CWD=OS. The path. The dirname (OS) path) abspath (__file__), \
Stdin=subprocess. PIPE \
Stdout=subprocess. PIPE \
Stderr=subprocess. PIPE)
# 2 to guarantee thread safety
The self. The lock=threading. The lock ()
Def compute_score (self, GTS, res) :
Assert (list (GTS. Keys ())==list (res) keys ()))
ImgIds=list (GTS. Keys ())
Scores=[]
Eval_line='EVAL'
Self. Lock. Acquire ()
For I in imgIds:
[I] assert (len (res)==1)
The stat=self. _stat (res [I] [0], GTS [I])
Eval_line +='| | | {}'. The format (stat)
Self. Meteor_p. Stdin. Write (' {} \ n '. The format (eval_line))
For I in range (0, len (imgIds) :
Scores. Append (float (self. Meteor_p. Stdout. Readline (). The strip ()))
Score=float (self meteor_p. Stdout. Readline (). The strip ())
The self. The lock. The release ()
Return the score, the scores
Def method (self) :
Return "METEOR"
Def _stat (self, hypothesis_str reference_list) :
1 # SCORE | | | the reference words | | | reference n words | | | content words
Hypothesis_str=hypothesis_str. Replace (' | | | ', '). The replace (', ')
Score_line='| | |'. Join ((' SCORE ', '| | |'. Join (reference_list), hypothesis_str))
Self. Meteor_p. Stdin. Write (' {} \ n '. The format (score_line))
Return self. Meteor_p. Stdout. Readline (). The strip ()
Def _score (self, hypothesis_str reference_list) :
Self. Lock. Acquire ()
1 # SCORE | | | the reference words | | | reference n words | | | content words
Hypothesis_str=hypothesis_str. Replace (' | | | ', '). The replace (', ')
Score_line='| | |'. Join ((' SCORE ', '| | |'. Join (reference_list), hypothesis_str))
Self. Meteor_p. Stdin. Write (' {} \ n '. The format (score_line))
Stats=self. Meteor_p. Stdout. Readline (). The strip ()
='EVAL eval_line | | | {}'. The format (stats)
# EVAL | | | stats
Self. Meteor_p. Stdin. Write (' {} \ n '. The format (eval_line))
Score=float (self meteor_p. Stdout. Readline (). The strip ())
# bug fix: there are two values returned by the jar file, one business, one and all, so do it twice
# thanks for Andrej for pointing this out
Score=float (self meteor_p. Stdout. Readline (). The strip ())
The self. The lock. The release ()
Return score
Def __del__ (self) :
Self. Lock. Acquire ()
Self. Meteor_p. Stdin. Close ()
Self. Meteor_p. Kill ()
Self. Meteor_p. Wait ()
The self. The lock. The release ()
The mistake is
CodePudding user response:
The type of the variable problem: you is a character type of the variables in the code, but the requirements is a byte type variableCodePudding user response:
Met the same problem, it is a project of 2.7 in 3.6 on the run, the environment of the building Lord solved excuse me? Thank you for