今天爱分享给大家带来tensorflow 报错:raise TypeError(‘{!r} is not a callable object‘.format(obj))【解决方法】,希望能够帮助到大家。
raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: 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)
原文链接:https://blog.itblood.com/848.html,转载请注明出处。

![我不得不破坏我朋友的后宫v0.62 AI版[PC+安卓/5.53G/更新]Due to My New Situation, I Have to Corrupt My Friend's Harem! [v0.62] [日系SLG/汉化/动态]](/wp-content/uploads/replace/2025/07/19/f07fe796a707828859b862ee4f62e5f7.webp)