NotImplementedError: Cannot convert a symbolic Tensor (lstm/strided_slice:0) to a numpy array.

 NotImplementedError: Cannot convert a symbolic Tensor (lstm/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
numpy                   1.21.6

 

 

https://blog.csdn.net/FL1768317420/article/details/136431685

有几个方法:
1.降低numpy的版本到1.19.5

pip install numpy==1.19.2  【可行


2.降低Python的版本到3.6


3.修改array_ops.py

 

找到array_ops.py,我的在
E:\Anaconda3\envs\tensorflow\Lib\site-packages\tensorflow\python\ops\array_ops.py
根据错误提示,可以找到这个文件位置。
在文件中,增加

from tensorflow.python.ops.math_ops import reduce_prod 

 然后找到

def _constant_if_small(value, shape, dtype, name) 

定义,
原代码是这样的: 

图片

 

 把它修改为: 

图片

 

 

 

 

def creatModel():
model.add(LSTM(train_features.shape, input_shape=(train_features.shape, n_features)))

 

NotImplementedError: Cannot convert a symbolic Tensor (lstm/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


 

posted @ 2025-10-05 22:53  emanlee  阅读(4)  评论(0)    收藏  举报