AttributeError: 'MyDataSet' object has no attribute 'dev_examples'
Created by: txyugood
我在finetune 分类模型时,自定义了数据集。在训练过程中评估模型的时候会报错:
File "/Users/alex/baidu/paddlehubdog/train.py", line 71, in <module>
task.finetune_and_eval()
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 592, in finetune_and_eval
return self.finetune(do_eval=True)
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 604, in finetune
run_states = self._run(do_eval=do_eval)
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 648, in _run
return self._run_with_py_reader(do_eval=do_eval)
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 743, in _run_with_py_reader
self._eval_interval_event()
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 534, in _eval_interval_event
self.eval(phase="dev")
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 628, in eval
run_states = self._run()
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 648, in _run
return self._run_with_py_reader(do_eval=do_eval)
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 708, in _run_with_py_reader
self.py_reader.decorate_paddle_reader(self.reader)
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/finetune/task/basic_task.py", line 391, in reader
batch_size=self.config.batch_size, phase=self.phase, data=data)
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/reader/cv_reader.py", line 92, in data_generator
self.num_examples['dev'] = len(self.get_dev_examples())
File "/Users/alex/.conda/envs/paddle/lib/python3.6/site-packages/paddlehub/reader/cv_reader.py", line 136, in get_dev_examples
return self.dataset.dev_examples
AttributeError: 'MyDataSet' object has no attribute 'dev_examples'
我发现ImageClassificationDataset代码中有:
def test_data(self, shuffle=False):
test_data_path = os.path.join(self.base_path, self.test_list_file)
return self._parse_data(test_data_path, shuffle, phase='dev')
def validate_data(self, shuffle=False):
validate_data_path = os.path.join(self.base_path,
self.validate_list_file)
return self._parse_data(validate_data_path, shuffle, phase='test')
这两个方法的 phase 的值是不是设置错了? 我在自定义的 Dataset中,重写这个两个方法,同时将 phase 的值调换,程序可以正常运行。