Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Tensorflow 2.2.0-rc4属性错误:模块';tensorflow.compat.v1';没有属性';contrib&x27;在斯派德?_Python 3.x_Tensorflow_Jupyter Notebook_Anaconda_Spyder - Fatal编程技术网

Python 3.x Tensorflow 2.2.0-rc4属性错误:模块';tensorflow.compat.v1';没有属性';contrib&x27;在斯派德?

Python 3.x Tensorflow 2.2.0-rc4属性错误:模块';tensorflow.compat.v1';没有属性';contrib&x27;在斯派德?,python-3.x,tensorflow,jupyter-notebook,anaconda,spyder,Python 3.x,Tensorflow,Jupyter Notebook,Anaconda,Spyder,这是我在Spyder中的代码 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() # Building the seq2seq model def seq2seq_model(inputs, targets, keep_prob, batch_size, sequence_length, answers_num_words, questions_num_words, encoder_embedding_size, deco

这是我在Spyder中的代码

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 



# Building the seq2seq model
def seq2seq_model(inputs, targets, keep_prob, batch_size, sequence_length, answers_num_words, questions_num_words, encoder_embedding_size, decoder_embedding_size, rnn_size, num_layers, questionswords2int):
    encoder_embedded_input = tf.contrib.layers.embed_sequence(inputs,
                                                              answers_num_words + 1,
                                                              encoder_embedding_size,
                                                              initializer = tf.random_uniform_initializer(0, 1))
    encoder_state = encoder_rnn(encoder_embedded_input, rnn_size, num_layers, keep_prob, sequence_length)
    preprocessed_targets = preprocess_targets(targets, questionswords2int, batch_size)
    decoder_embeddings_matrix = tf.Variable(tf.random_uniform([questions_num_words + 1, decoder_embedding_size], 0, 1))
    decoder_embedded_input = tf.nn.embedding_lookup(decoder_embeddings_matrix, preprocessed_targets)
    training_predictions, test_predictions = decoder_rnn(decoder_embedded_input,
                                                         decoder_embeddings_matrix,
                                                         encoder_state,
                                                         questions_num_words,
                                                         sequence_length,
                                                         rnn_size,
                                                         num_layers,
                                                         questionswords2int,
                                                         keep_prob,
                                                         batch_size)
    return training_predictions, test_predictions
我正在使用Ubuntu 18.04

    $ python3
 Python 3.8.3 (default, Jul  2 2020, 16:21:59)  [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    >>> tf.__version__ '
    >>> 2.2.0-rc4'
我知道
tf.contrib
已从TensorFlow中删除


我在中找到了一些解决方案,但无法解决问题

最后我明白了在tensorflow 2python 3.8中无法继续使用contrib。 在这里,我将python版本降级为pythone3.5tensorflow1.0

以下是我遵循的步骤

第一步:我已经用python版本3.5创建了一个新环境

conda create --name env1 pip python=3.5 parso=0.7
第二步:激活我的环境

conda activate env1
最后安装tensorflow 1.0

这是为我工作

pip install tensorflow==1.0