我试图使以下程序起作用: https://github.com/mattdangerw/keras-text-generation
在CMD(Windows 10)中,我输入:
python train.py
我遇到以下错误:
Using TensorFlow backend.
Loading data...
corpus length: 1223047
vocab size: 41
x.shape: (44608, 50)
y.shape: (44608, 50, 1)
x_val.shape: (4288, 50)
y_val.shape: (4288, 50, 1)
Data load time 0.958162784576416
Building model...
Traceback (most recent call last):
File "train.py", line 42, in <module>
main()
File "train.py", line 37, in main
model.train(**vars(args))
File "D:\IoT\Aufgabe4\task3\keras-text-generation\model.py", line 135, in train
self._build_models(batch_size, embedding_size, rnn_size, num_layers)
File "D:\IoT\Aufgabe4\task3\keras-text-generation\model.py", line 92, in _build_models
model = Sequential()
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\engine\sequential.py", line 87, in __init__
super(Sequential, self).__init__(name=name)
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\engine\network.py", line 96, in __init__
self._init_subclassed_network(**kwargs)
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\engine\network.py", line 294, in _init_subclassed_network
self._base_init(name=name)
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\engine\network.py", line 109, in _base_init
name = prefix + '_' + str(K.get_uid(prefix))
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 74, in get_uid
graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
Python版本:
python --version
Python 3.7.3
Keras版本:
python -c "import keras; print(keras.__version__)"
Using TensorFlow backend.
2.2.4
Tensorflow版本:
python -c "import tensorflow as tf; print(tf.__version__)"
2.0.0-alpha0
我还安装了pip,并且使用pip我还安装了colorama,这是必需的。
如何解决?一个朋友测试了相同的程序并执行了相同的安装和配置,但是没有任何错误消息。我认为这是张量流的问题。我说的对吗?
答案 0 :(得分:1)
Keras当前不支持TensorFlow 2.0,因为它仍然是Alpha版本。您需要使用Generic
或将TensorFlow降级到1.13才能使用官方的System.Collections.Specialized.StringCollection specialized = new System.Collections.Specialized.StringCollection() { "s123", "s321" };
System.Collections.Generic.List<string> generic = new System.Collections.Generic.List<string>() { "g123", "g321" };
软件包。
答案 1 :(得分:0)
这是一个已知的Tensorflow / Keras错误,请在此处阅读更多信息:
https://github.com/keras-team/keras/issues/12379
每个链接的解决方案(与@Vishal的评论相同):
我将导入从keras.something.something
更改为tensorflow.keras.something
,问题似乎已经消失。把它放在这里让其他人受益。