farizrahman4u / seq2seq

Sequence to Sequence Learning with Keras
GNU General Public License v2.0
3.17k stars 846 forks source link

when import seq2seq have an error:cannot import name '_collect_previous_mask' #250

Open njustzsm opened 6 years ago

njustzsm commented 6 years ago

can you tell me how to fix it? it occur in: from keras.engine.topology import Node, _collect_previous_mask, _collect_input_shape

chenjindong commented 6 years ago

I have the same problem. Who can help me?

ty5491003 commented 6 years ago

l just solved this problem: i repalced my keras version from 2.2.0 to 2.0.0 , use "pip install --upgrade keras==2.0.0" , you can try it! But now i have an new issue when i run the SimpleSeq2Seq: Traceback (most recent call last): File "C:/Users/ty/PycharmProjects/conala-baseline-master/preproc/seq2seq_model.py", line 4, in <module> model = SimpleSeq2Seq(input_dim=5, hidden_dim=10, output_length=8, output_dim=8) File "C:\Users\ty\AppData\Local\Programs\Python\Python35\lib\site-packages\seq2seq-1.0.0-py3.5.egg\seq2seq\models.py", line 81, in SimpleSeq2Seq File "C:\Users\ty\AppData\Local\Programs\Python\Python35\lib\site-packages\recurrentshop-1.0.0-py3.5.egg\recurrentshop\engine.py", line 476, in __call__ File "C:\Users\ty\AppData\Local\Programs\Python\Python35\lib\site-packages\recurrentshop-1.0.0-py3.5.egg\recurrentshop\engine.py", line 1022, in build File "C:\Users\ty\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\topology.py", line 545, in __call__ output = self.call(inputs, **kwargs) File "C:\Users\ty\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\layers\core.py", line 112, in call return output UnboundLocalError: local variable 'output' referenced before assignment

HelloWorld-9527 commented 6 years ago

I also meet this problem, and I try to find this two as the function of python from Internet. I am a fresh of keras and tensorflow, so I can't fully understand what it mean. Althought it worked, but I meet another problem: AttributeError: '_OptionalInputPlaceHolder' object has no attribute 'inbound_nodes'

def _collect_input_shape(input_tensors): """Collects the output shape(s) of a list of Keras tensors. Arguments: input_tensors: list of input tensors (or single input tensor). Returns: List of shape tuples (or single tuple), one tuple per input. """ input_tensors = _to_list(input_tensors) shapes = [] for x in input_tensors: shapes.append(K.int_shape(x)) if len(shapes) == 1: return shapes[0] return shapes

from tensorflow.python.util import nest def _collect_previous_mask(input_tensors): """Retrieves the output mask(s) of the previous node. Arguments: input_tensors: A tensor or list of tensors. Returns: A mask tensor or list of mask tensors. """ input_tensors = nest.flatten(input_tensors) masks = [] for x in input_tensors: if hasattr(x, '_keras_mask'): mask = x._keras_mask # pylint: disable=protected-access masks.append(mask) else: masks.append(None) if len(masks) == 1: return masks[0] return masks I don't know why :there is not line feeds when insert code