欢迎您对PaddleHub提出建议,非常感谢您对PaddleHub的贡献!
目前PaddleHub已实现您提出的需求,请安装PaddleHub>=1.7.0, PaddlePaddle>=1.8.0快速体验。请您在定义task任务时增加metrics_choices=[‘f1’]选项,即可实现多分类F1 Score评估指标,示例如下:
task = hub.ImageClassifierTask
data_reader=data_reader,
feed_list=feed_list,
feature=feature_map,
num_classes=dataset.num_labels,
metrics_choices=[‘f1’], #PaddleHub同时支持’f1’和’acc’评价标准,可使用metrics_choices=[‘f1’, ‘acc’]快速实现
config=config)
发现一个新的问题,ImageClassifierTask设定f1作为metrics时,多分类任务会报错,
metrics_choices = [‘f1’]
错误信息:
[2020-08-07 11:13:35,971] [ INFO] – PaddleHub finetune start
—————————————————————————TypeError Traceback most recent call last) in
—-> 1 run_states = task.finetune_and_eval)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in finetune_and_evalself)
943
944 def finetune_and_evalself):
–> 945 return self.finetunedo_eval=True)
946
947 def finetuneself, do_eval=False):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in finetuneself, do_eval)
964 while self.current_epoch <= self.config.num_epoch:
965 self.config.strategy.step)
–> 966 run_states = self._rundo_eval=do_eval)
967 self.env.current_epoch += 1
968
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in _runself, do_eval)
1222 if self.is_train_phase:
1223 if self.current_step % self.config.log_interval == 0:
-> 1224 self._log_interval_eventperiod_run_states)
1225 global_run_states += period_run_states
1226 period_run_states = []
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in hook_functionself, *args)
706 for name, func in self._hooks[hook_type].items):
707 if inspect.ismethodfunc):
–> 708 func*args)
709 else:
710 partialfunc, self)*args)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in default_log_interval_eventself, run_states)
849 tag=”{}{}”.formatmetric, self.phase),
850 value=scores[metric],
–> 851 step=self._envs[‘train’].current_step)
852 log_scores += “%s=%.5f ” % metric, scores[metric])
853 logger.train“step %d / %d: loss=%.5f %s[step/sec: %.2f]” %
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/visualdl/writer/writer.py in add_scalarself, tag, value, step, walltime)
133 walltime = roundtime.time)) if walltime is None else walltime
134 self._get_file_writer).add_record
–> 135 scalartag=tag, value=value, step=step, walltime=walltime))
136
137 def add_imageself, tag, img, step, walltime=None):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/visualdl/component/base_component.py in scalartag, value, step, walltime)
31 Package with format of record_pb2.Record
32 “””
—> 33 value = floatvalue)
34 return Recordvalues=[
35 Record.Valueid=step, tag=tag, timestamp=walltime, value=value)
TypeError: float) argument must be a string or a number, not ‘tuple’
查看了代码,问题可能出在PaddleHub/paddlehub/finetune/task/classifier_task.py
calculate_metrics)调用的calculate_f1_np)函数应该是只能对2分类任务计算f1、precision和recall。