debug Tensorflow: ‘_UserObject‘ object has no attribute ‘add_slot‘

平台

  • ubuntu
  • tensoflow

现象

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_39/883809998.py in <module>
----> 1 model0 = tf.saved_model.load('../input/ubiquant-dataset/nn0')

/opt/conda/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in load(export_dir, tags, options)
    862   """
    863   metrics.IncrementReadApi(_LOAD_V2_LABEL)
--> 864   result = load_internal(export_dir, tags, options)["root"]
    865   metrics.IncrementRead()
    866   return result

/opt/conda/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in load_internal(export_dir, tags, options, loader_cls, filters)
    901       try:
    902         loader = loader_cls(object_graph_proto, saved_model_proto, export_dir,
--> 903                             ckpt_options, options, filters)
    904       except errors.NotFoundError as err:
    905         raise FileNotFoundError(

/opt/conda/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in __init__(self, object_graph_proto, saved_model_proto, export_dir, ckpt_options, save_options, filters)
    160     self._filtered_nodes = self._retrieve_all_filtered_nodes()
    161 
--> 162     self._load_all()
    163 
    164     if not save_options.experimental_skip_checkpoint:

/opt/conda/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in _load_all(self)
    257   def _load_all(self):
    258     """Loads all nodes and functions from the SavedModel and their edges."""
--> 259     self._load_nodes()
    260     self._load_edges()
    261     # TODO(b/124045874): There are limitations with functions whose captures

/opt/conda/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in _load_nodes(self)
    446         optimized_variable = nodes[
    447             slot_variable_proto.original_variable_node_id]
--> 448         slot_variable = optimizer_object.add_slot(
    449             var=optimized_variable,
    450             slot_name=slot_variable_proto.slot_name)

AttributeError: '_UserObject' object has no attribute 'add_slot'

解决

  • 起初我猜测我训练用tensorflow2.3.1,加载模型用2.6.2。二者不一致导致,半天功夫升级cuda、cudnn和tf后,问题仍然存在
  • 加载pb模型时,采用了tf.keras.models.load_model,替换tf.saved_model.load。问题解决

参考

  • https://github.com/tensorflow/models/issues/8990
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YueTann

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值