Cannot convert a symbolic Tensor (simple_rnn/strided_slice:0) to a numpy array. 报错 (解决方法)
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, SimpleRNNmodel = 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
Cannot convert a symbolic Tensor (simple_rnn/strided_slice:0) to a numpy array. 报错 (解决方法)相关推荐
- 解决Cannot convert a symbolic Tensor (lstm/strided_slice:0) to a numpy array.
pip install numpy==1.18.1
- NotImplementedError: Cannot convert a symbolic Tensor (lstm/strided_slice:0) to a numpy array.
这是numpy版本与tensorflow版本不兼容导致的 tensorflow2.2 + numpy1.19.2表示没问题.
- NotImplementedError: Cannot convert a symbolic Tensor (while/add_8:0) to a numpy array.
代码: 报错如下: 将np.power()改成**就解决了,猜测是numpy包的原因
- Redis 5.0.3默认配置启动报错解决方法
Redis 5.0.3默认配置启动报错解决方法 参考文章: (1)Redis 5.0.3默认配置启动报错解决方法 (2)https://www.cnblogs.com/miclesvic/p/1031 ...
- 【工具】更新arduino最新esp8266库离线安装包3.0.1、ESP32库离线安装包1.0.6,库编译报错解决方法...
公众号关注 "DLGG创客DIY" 设为"星标",重磅干货,第一时间送达. 210806更新ESP32和ESP8266最新离线安装包下载地址. 因为各种 ...
- mysql8.0设置用户权限_mysql8.0建立用户授予权限报错解决方法
我遇到错误一:Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to ...
- mysql8.0.11创建用户报错_mysql8.0创建用户授予权限报错解决方法
我遇到错误一:Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to ...
- mysql8.0创建用户授予权限报错解决方法
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your My ...
- Android Studio support 26.0.0-alpha1 Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法
Android Studio support 26.0.0-alpha1 Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法 ...
- Mysql8.0.16 连接包报错解决方法
Mysql8.0.16 连接包报错解决方法 Mysql8.0 .16连接包报错: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized o ...
最新文章
- www服务器提供的第一个信息页面,第14章WWW服务
- javascript函数上的prototype属性的理解
- Go中的函数也是一种数据类型,可以赋值给一个变量
- 基于HTML5技术的电力3D监控应用(二)
- java中局部变量和成员变量
- Java 输出指定目录下的所有文件
- read 和write
- Java 获取昨天、当前、明天的时间
- python简单GUI(模拟记事本)
- eclipse的workspace和working set
- Golang 须知知识点
- 深度LINUX不喜欢
- 复变函数(第五版)课后答案 余家荣 版 课后习题答案 高等教育出版社 第一章 课后题答案与解析
- SQL SERVER 不允许保存更改
- sudo chmod 755 ....指令分析
- 用计算机画图教案,电脑绘画美术教案设计
- 扫地机器人单扫和双扫_扫地机器人初体验 懒人神器还是逗猫的塑料玩具
- python做测试小工具_自制快速冒烟测试小工具--基于python多线程(2)
- WVGA与HVGA、QVGA详细解答
- Java中的新生代和老生代