当前位置:   article > 正文

Cannot convert a symbolic Tensor (simple_rnn/strided_slice:0) to a numpy array. 报错 (解决方法)_call initializer instance with the dtype argument

call initializer instance with the dtype argument instead of passing it to t

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.

  1. # 只返回最后一个时间步的输出
  2. from tensorflow.keras.models import Sequential
  3. from tensorflow.keras.layers import Embedding, SimpleRNN
  4. model = Sequential()
  5. model.add(Embedding(10000, 32))
  6. model.add(SimpleRNN(32))
  7. model.summary()

2. 解决方法:

查了一下,当时用的numpy版本:

疑问:会不会是 numpy版本 太高了导致的?

于是,正好有个低版本的虚拟环境,其numpy版本为:

重新运行了上述代码,发现有Warning,但无伤大雅,可以运行: 

  1. 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.
  2. Instructions for updating:
  3. Call initializer instance with the dtype argument instead of passing it to the constructor
  4. 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.
  5. Instructions for updating:
  6. Call initializer instance with the dtype argument instead of passing it to the constructor
  7. Model: "sequential"
  8. _________________________________________________________________
  9. Layer (type) Output Shape Param #
  10. =================================================================
  11. embedding (Embedding) (None, None, 32) 320000
  12. _________________________________________________________________
  13. simple_rnn (SimpleRNN) (None, 32) 2080
  14. =================================================================
  15. Total params: 322,080
  16. Trainable params: 322,080
  17. Non-trainable params: 0
  18. _________________________________________________________________

 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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/438711
推荐阅读
相关标签
  

闽ICP备14008679号