web-dev-qa-db-fra.com

TypeError: Tensor est indéchirable. À la place, utilisez tensor.ref () comme clé. dans Keras Surgeon

J'utilise le module Kerassurgeon pour l'élagage.J'ai rencontré cette erreur pendant que je travaille avec VGG-16 dans google colab.Cela fonctionne bien pour d'autres modèles.Quelqu'un peut-il m'aider à résoudre ce problème.

---> 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.**
3
Nikhil Munna

J'ai résolu cette erreur. ceci est dû au changement de version. Utilisez Kerassurgeon au lieu de tfkerassurgeon.

Utilisez les versions suivantes

tf 1.x , keras > 2.2 , kerassurgeon 
1
Nikhil Munna