diff --git a/demo/elmo/predict.py b/demo/elmo/predict.py index be056b732c11cb42fd62d3e2a140a24b891c30b0..3fb9b7140a06e16437f022e1e91d844a35769e05 100644 --- a/demo/elmo/predict.py +++ b/demo/elmo/predict.py @@ -168,7 +168,8 @@ if __name__ == '__main__': ] index = 0 - results = elmo_task.predict(data=data) + run_states = elmo_task.predict(data=data) + results = [run_state.run_results for run_state in run_states] for batch_result in results: # get predict index batch_result = np.argmax(batch_result, axis=2)[0] diff --git a/demo/image-classification/predict.py b/demo/image-classification/predict.py index 532d813f8673781b14c1501f983723fc5bcbaa9f..ab7d34d94c2c542946a957ad65ede63f71606adf 100644 --- a/demo/image-classification/predict.py +++ b/demo/image-classification/predict.py @@ -76,7 +76,8 @@ def predict(args): label_map = dataset.label_dict() index = 0 # get classification result - results = task.predict(data=data) + run_states = task.predict(data=data) + results = [run_state.run_results for run_state in run_states] for batch_result in results: # get predict index batch_result = np.argmax(batch_result, axis=2)[0] diff --git a/demo/multi-label-classification/predict.py b/demo/multi-label-classification/predict.py index 5e7caa997b5edc89769dce0e0f530a7d0bbeb2d6..138c5ade3108e72faafeac5d1dfafe45eb2353ab 100644 --- a/demo/multi-label-classification/predict.py +++ b/demo/multi-label-classification/predict.py @@ -99,7 +99,8 @@ if __name__ == '__main__': ] index = 0 - results = multi_label_cls_task.predict(data=data) + run_states = multi_label_cls_task.predict(data=data) + results = [run_state.run_results for run_state in run_states] for result in results: # get predict index label_ids = [] diff --git a/demo/senta/predict.py b/demo/senta/predict.py index 4d22b7bb38e1105c9bc5462f000c5268991530df..1c258343a286d124a4fb70c551168fb1d4f0be22 100644 --- a/demo/senta/predict.py +++ b/demo/senta/predict.py @@ -60,7 +60,8 @@ if __name__ == '__main__': data = ["这家餐厅很好吃", "这部电影真的很差劲"] - results = cls_task.predict(data=data) + run_states = cls_task.predict(data=data) + results = [run_state.run_results for run_state in run_states] index = 0 for batch_result in results: batch_result = np.argmax(batch_result, axis=2)[0] diff --git a/demo/sequence-labeling/predict.py b/demo/sequence-labeling/predict.py index fb26b86a3035f2ec61f79e83a50f4bc14354f7e3..01fa42807d157d868ce1d0a8b3fe1fd597abe91a 100644 --- a/demo/sequence-labeling/predict.py +++ b/demo/sequence-labeling/predict.py @@ -96,7 +96,8 @@ if __name__ == '__main__': ["不过重在晋趣,略增明人气息,妙在集古有道、不露痕迹罢了。"], ] - results = seq_label_task.predict(data=data) + run_states = seq_label_task.predict(data=data) + results = [run_state.run_results for run_state in run_states] for num_batch, batch_results in enumerate(results): infers = batch_results[0].reshape([-1]).astype(np.int32).tolist() diff --git a/demo/text-classification/predict.py b/demo/text-classification/predict.py index 1465d0d62077d924086eb55fd2ed8b5a1f02ca64..e0088dba7d04dec3d338047178820d6c6e3450bd 100644 --- a/demo/text-classification/predict.py +++ b/demo/text-classification/predict.py @@ -97,7 +97,8 @@ if __name__ == '__main__': ] index = 0 - results = cls_task.predict(data=data) + run_states = cls_task.predict(data=data) + results = [run_state.run_results for run_state in run_states] for batch_result in results: # get predict index batch_result = np.argmax(batch_result, axis=2)[0] diff --git a/paddlehub/finetune/task.py b/paddlehub/finetune/task.py index 13c776d4dae9641fa57005fe895bb02405c2f094..d438eaf60e770188c3a78e14fb47116faeea4925 100644 --- a/paddlehub/finetune/task.py +++ b/paddlehub/finetune/task.py @@ -498,7 +498,7 @@ class BasicTask(object): self.exe, dirname=dirname, main_program=self.main_program) def finetune_and_eval(self): - self.finetune(do_eval=True) + return self.finetune(do_eval=True) def finetune(self, do_eval=False): # Start to finetune @@ -519,6 +519,7 @@ class BasicTask(object): self.eval(phase="test") self._finetune_end_event(run_states) + return run_states def eval(self, phase="dev"): with self.phase_guard(phase=phase): @@ -526,6 +527,7 @@ class BasicTask(object): self._eval_start_event() run_states = self._run() self._eval_end_event(run_states) + return run_states def predict(self, data, load_best_model=True): with self.phase_guard(phase="predict"): @@ -539,7 +541,7 @@ class BasicTask(object): run_states = self._run() self._predict_end_event(run_states) self._predict_data = None - return [run_state.run_results for run_state in run_states] + return run_states def _run(self, do_eval=False): with fluid.program_guard(self.main_program, self.startup_program):