1.报错 问题:(来自《Python深度学习》P164-165)
在运行以下代码的时候,报错:Cannot convert a symbolic Tensor (simple_rnn/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported.
# 只返回最后一个时间步的输出
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, SimpleRNN
model = Sequential()
model.add(Embedding(10000, 32))
model.add(SimpleRNN(32))
model.summary()
2. 解决方法:
查了一下,当时用的numpy版本:
疑问:会不会是 numpy版本 太高了导致的?
于是,正好有个低版本的虚拟环境,其numpy版本为:
重新运行了上述代码,发现有Warning,但无伤大雅,可以运行:
WARNING:tensorflow:From D:\QLDownload\AnacondaDon\envs\python37\lib\site-packages\tensorflow\python\keras\initializers.py:119: calling RandomUniform.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
WARNING:tensorflow:From D:\QLDownload\AnacondaDon\envs\python37\lib\site-packages\tensorflow\python\ops\init_ops.py:1251: calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding (Embedding) (None, None, 32) 320000
_________________________________________________________________
simple_rnn (SimpleRNN) (None, 32) 2080
=================================================================
Total params: 322,080
Trainable params: 322,080
Non-trainable params: 0
_________________________________________________________________
BTW,虚拟环境的其他配置为:
scipy==1.3.0
Keras==2.2.4
numpy==1.16.4
networkx==2.1
tensorflow_gpu==1.14.0
scikit_learn==0.21.2
tensorflow==1.14.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)