1. 程式人生 > >seq2seq_model.py AttributeError: 'NoneType' object has no attribute 'update'

seq2seq_model.py AttributeError: 'NoneType' object has no attribute 'update'

```
Traceback (most recent call last):
  File "/Users/mac/Desktop/wgz/python/tensorflow/TensorFlow_seq2seq_tutorial-master/translate/translate.py", line 300, in <module>
    tf.app.run()
  File "/anaconda/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "/Users/mac/Desktop/wgz/python/tensorflow/TensorFlow_seq2seq_tutorial-master/translate/translate.py", line 293, in main
    self_test()
  File "/Users/mac/Desktop/wgz/python/tensorflow/TensorFlow_seq2seq_tutorial-master/translate/translate.py", line 277, in self_test
    5.0, 32, 0.3, 0.99, num_samples=8)
  File "/Users/mac/Desktop/wgz/python/tensorflow/TensorFlow_seq2seq_tutorial-master/translate/seq2seq_model.py", line 165, in __init__
    softmax_loss_function=softmax_loss_function)
  File "/anaconda/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1209, in model_with_buckets
    decoder_inputs[:bucket[1]])
  File "/Users/mac/Desktop/wgz/python/tensorflow/TensorFlow_seq2seq_tutorial-master/translate/seq2seq_model.py", line 164, in <lambda>
    lambda x, y: seq2seq_f(x, y, False),
  File "/Users/mac/Desktop/wgz/python/tensorflow/TensorFlow_seq2seq_tutorial-master/translate/seq2seq_model.py", line 144, in seq2seq_f
    dtype=dtype)
  File "/anaconda/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 851, in embedding_attention_seq2seq
    encoder_cell = copy.deepcopy(cell)
  File "/anaconda/lib/python2.7/copy.py", line 174, in deepcopy
    y = copier(memo)
  File "/anaconda/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 655, in __deepcopy__
    setattr(result, k, copy.deepcopy(v, memo))
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/anaconda/lib/python2.7/copy.py", line 174, in deepcopy
    y = copier(memo)
  File "/anaconda/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 655, in __deepcopy__
    setattr(result, k, copy.deepcopy(v, memo))
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 237, in _deepcopy_tuple
    y.append(deepcopy(a, memo))
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/anaconda/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/anaconda/lib/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/anaconda/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/anaconda/lib/python2.7/copy.py", line 343, in _reconstruct
    y.__dict__.update(state)
AttributeError: 'NoneType' object has no attribute 'update'
```






解決這個問題的方法是:將tensro升級到最新的tendorflow的1.4版本,但是還會出現


```
AttributeError: 'NoneType' object has no attribute 'update'
```
解決辦法請參考:

``` #
將seq2seq_model.py中134行的
 def seq2seq_f(encoder_inputs, decoder_inputs, do_decode):
            return tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
                encoder_inputs,
                decoder_inputs,
                cell,
                num_encoder_symbols=source_vocab_size,
                num_decoder_symbols=target_vocab_size,
                embedding_size=size,
                output_projection=output_projection,
                feed_previous=do_decode,
                dtype=dtype)


改變為:
def seq2seq_f(encoder_inputs,decoder_inputs,do_decode):
tmp_cell = copy.deepcopy(cell)
return tf.contrib.legacy_seq2seq.embedding_attention_seq2seq(
encoder_inputs,
decoder_inputs,tmp_cell,
num_encoder_symbols = source_vocab_size,
num_decoder_symbols = target_vocab_size,
embedding_size = size,
output_projection = output_projection,
feed_previous = do_decode,dtype = dtype 

```