提交 808206a4 编写于 作者: Z zhangxuefei

update autofinetune and run command

上级 1bc44e50
...@@ -136,7 +136,17 @@ class FullTrailEvaluator(BaseEvaluator): ...@@ -136,7 +136,17 @@ class FullTrailEvaluator(BaseEvaluator):
os.system(run_cmd) os.system(run_cmd)
with open(log_file, "r") as f: with open(log_file, "r") as f:
lines = f.readlines() lines = f.readlines()
eval_result = float(lines[-1]) eval_result = []
for line in lines:
line = line.strip()
if line.startswith("AutoFinetuneEval"):
data = line.split("\t")
eval_result = float(data[-1])
if eval_result == []:
print(
"WARNING: Program which was ran with hyperparameters as %s was crashed!"
% param_str.replace("--", ""))
eval_result = 0.0
except: except:
print( print(
"WARNING: Program which was ran with hyperparameters as %s was crashed!" "WARNING: Program which was ran with hyperparameters as %s was crashed!"
...@@ -190,7 +200,17 @@ class ModelBasedEvaluator(BaseEvaluator): ...@@ -190,7 +200,17 @@ class ModelBasedEvaluator(BaseEvaluator):
os.system(run_cmd) os.system(run_cmd)
with open(log_file, "r") as f: with open(log_file, "r") as f:
lines = f.readlines() lines = f.readlines()
eval_result = float(lines[-1]) eval_result = []
for line in lines:
line = line.strip()
if line.startswith("AutoFinetuneEval"):
data = line.split("\t")
eval_result = float(data[-1])
if eval_result == []:
print(
"WARNING: Program which was ran with hyperparameters as %s was crashed!"
% param_str.replace("--", ""))
eval_result = 0.0
except: except:
print( print(
"WARNING: Program which was ran with hyperparameters as %s was crashed!" "WARNING: Program which was ran with hyperparameters as %s was crashed!"
......
...@@ -108,6 +108,13 @@ class RunCommand(BaseCommand): ...@@ -108,6 +108,13 @@ class RunCommand(BaseCommand):
type=str, type=str,
default=None, default=None,
help="file contain input data") help="file contain input data")
self.arg_input_group.add_argument(
'--use_strip',
type=ast.literal_eval,
default=True,
help=
"whether need to strip whitespace characters from the beginning and the end of the line in the file or not."
)
if len(expect_data_format) == 1: if len(expect_data_format) == 1:
if module_type.startswith("cv"): if module_type.startswith("cv"):
self.arg_input_group.add_argument( self.arg_input_group.add_argument(
...@@ -147,7 +154,8 @@ class RunCommand(BaseCommand): ...@@ -147,7 +154,8 @@ class RunCommand(BaseCommand):
if len(expect_data_format) == 1: if len(expect_data_format) == 1:
key = list(expect_data_format.keys())[0] key = list(expect_data_format.keys())[0]
if self.args.input_file: if self.args.input_file:
input_data[key] = txt_parser.parse(self.args.input_file) input_data[key] = txt_parser.parse(self.args.input_file,
self.args.use_strip)
else: else:
if module_type.startswith("cv"): if module_type.startswith("cv"):
input_data[key] = [self.args.input_path] input_data[key] = [self.args.input_path]
......
...@@ -71,11 +71,12 @@ class TextFileParser(object): ...@@ -71,11 +71,12 @@ class TextFileParser(object):
def _check(self): def _check(self):
pass pass
def parse(self, txt_file): def parse(self, txt_file, use_strip=True):
with codecs.open(txt_file, "r", sys_stdin_encoding()) as file: with codecs.open(txt_file, "r", sys_stdin_encoding()) as file:
contents = [] contents = []
for line in file: for line in file:
line = line.strip() if use_strip:
line = line.strip()
if line: if line:
contents.append(line) contents.append(line)
return contents return contents
......
...@@ -163,7 +163,7 @@ if __name__ == '__main__': ...@@ -163,7 +163,7 @@ if __name__ == '__main__':
shutil.copytree(config.checkpoint_dir+"/best_model/", args.saved_params_dir) shutil.copytree(config.checkpoint_dir+"/best_model/", args.saved_params_dir)
shutil.rmtree(config.checkpoint_dir) shutil.rmtree(config.checkpoint_dir)
print(eval_avg_score["acc"], end="") print("AutoFinetuneEval"+"\t"+str(float(eval_avg_score["acc"])))
``` ```
**Note**:以上是finetunee.py的写法。 **Note**:以上是finetunee.py的写法。
> finetunee.py必须可以接收待优化超参数选项参数, 并且待搜素超参数选项名字和yaml文件中的超参数名字保持一致. > finetunee.py必须可以接收待优化超参数选项参数, 并且待搜素超参数选项名字和yaml文件中的超参数名字保持一致.
...@@ -174,7 +174,7 @@ if __name__ == '__main__': ...@@ -174,7 +174,7 @@ if __name__ == '__main__':
> PaddleHub Auto Fine-tune优化超参策略选择hazero时,必须提供两个以上的待优化超参。 > PaddleHub Auto Fine-tune优化超参策略选择hazero时,必须提供两个以上的待优化超参。
> finetunee.py的最后一个输出必须是模型在数据集dev上的评价效果,同时以“”结束,如print(eval_avg_score["acc"], end=""). > finetunee.py必须输出模型在数据集dev上的评价效果,同时以“AutoFinetuneEval"开始,和评价效果之间以“\t”分开,如print("AutoFinetuneEval"+"\t"+str(float(eval_avg_score["acc"]))).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册