gpt4 book ai didi

keras - TypeError : Tensor is unhashable. 相反,使用 tensor.ref() 作为键。在 Keras 外科医生

转载 作者:行者123 更新时间:2023-12-03 13:56:56 25 4
gpt4 key购买 nike

我正在使用 Kerassurgeon 模块进行修剪。我在谷歌 colab 中使用 VGG-16 时遇到了这个错误。它适用于其他模型。有人可以帮我解决这个问题。

---> 17   model_new = surgeon.operate()<br>
18 return model_new

>>/usr/local/lib/python3.6/dist-packages/kerassurgeon/surgeon.py in operate(self)
152 sub_output_nodes = utils.get_node_inbound_nodes(node)
153 outputs, output_masks = self._rebuild_graph(self.model.inputs,
--> 154 sub_output_nodes)
155
156 # Perform surgery at this node

>>/usr/local/lib/python3.6/dist-packages/kerassurgeon/surgeon.py in _rebuild_graph(self, graph_inputs, output_nodes, graph_input_masks)
264 # Call the recursive _rebuild_rec method to rebuild the submodel up to
265 # each output layer
--> 266 outputs, output_masks = zip(*[_rebuild_rec(n) for n in output_nodes])
267 return outputs, output_masks
268

>>/usr/local/lib/python3.6/dist-packages/kerassurgeon/surgeon.py in <listcomp>(.0)
264 # Call the recursive _rebuild_rec method to rebuild the submodel up to
265 # each output layer
--> 266 outputs, output_masks = zip(*[_rebuild_rec(n) for n in output_nodes])
267 return outputs, output_masks
268

>>/usr/local/lib/python3.6/dist-packages/kerassurgeon/surgeon.py in _rebuild_rec(node)
216 # Check for replaced tensors before any other checks:
217 # these are created by the surgery methods.
--> 218 if node_output in self._replace_tensors.keys():
219 logging.debug('bottomed out at replaced output: {0}'.format(
220 node_output))

>>/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in __hash__(self)
724 if (Tensor._USE_EQUALITY and executing_eagerly_outside_functions() and
725 (g is None or g.building_function)):
--> 726 raise TypeError("Tensor is unhashable. "
727 "Instead, use tensor.ref() as the key.")
728 else:

**TypeError: Tensor is unhashable. Instead, use tensor.ref() as the key.**

最佳答案

当我尝试 Deep learning example with GradientExplainer 时,我已经解决了类似的问题.这是版本不兼容造成的。
添加以下代码可能会有所帮助:

import tensorflow.compat.v1.keras.backend as K
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
tf 版本是 2.3.1
kerase 版本是 2.4.0
形状版本为 0.36

关于keras - TypeError : Tensor is unhashable. 相反,使用 tensor.ref() 作为键。在 Keras 外科医生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61056781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com