raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: <BatchDataset shapes: {img: (?, 64, 64, 3), label: (?, 64, 64, 1)}, types: {img: tf.float32, label: tf.float32}> is not a callable object
raise TypeError('unsupported callable') from ex
TypeError: unsupported callable
问题 使用tensorflow.estimator.Estimator训练模型时,进行模型调用的时候验证是报错.
报错代码:
eval_metric= self.estimator.evaluate(
input_fn= self._evalute_input_fn(eval_set,eval_label_set))
其中_evalute_input_fn函数定义如下:
def _evalute_input_fn(self,eval_set,eval_label_set):
evalute_set= self.create_dataset(eval_set,eval_label_set)
evalute_set= evalute_set.batch(batch_size)
报错原因是在进行验证时,eval_input_fn要求无参数入,将验证的数据及代码变为类成员变量,调用函数时不传参,即可解决.更改如下:
调用:
eval_metric= self.estimator.evaluate(
input_fn=self._evalute_input_fn)
函数定义:
def _evalute_input_fn(self):
evalute_set= self.create_dataset(self.eval_set, self.eval_label_set)
evalute_set= evalute_set.batch(batch_size)