NotImplementedError:无法将符号张量转换为numpy数组

NotImplementedError:无法将符号张量转换为numpy数组,numpy,tensorflow,Numpy,Tensorflow,下面的代码在去年曾经有效,但是keras/tensorflow/numpy中的更新破坏了它。它现在输出下面的异常。有人知道如何使它再次工作吗 我正在使用: Tensorflow 2.4.1 Keras 2.4.3 Numpy 1.20.1 Python 3.9.1 完成上述脚本的输出: 缩短产量: 2021-02-10 17:51:13.037468: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devic

下面的代码在去年曾经有效,但是keras/tensorflow/numpy中的更新破坏了它。它现在输出下面的异常。有人知道如何使它再次工作吗

我正在使用:

  • Tensorflow 2.4.1
  • Keras 2.4.3
  • Numpy 1.20.1
  • Python 3.9.1
完成上述脚本的输出:

缩短产量:

2021-02-10 17:51:13.037468: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-02-10 17:51:13.037899: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-02-10 17:51:13.038418: I tensorflow/core/common_runtime/process_util.cc:146] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
Traceback (most recent call last):
  File "/run/media/volker/DATA/configruns/load/./test.py", line 13, in <module>
    lstm = Bidirectional(lstm_nobi, name="layerC")(embedding_layer)
  ... omitted, see pastebin ...
  File "/usr/lib/python3.9/site-packages/tensorflow/python/framework/ops.py", line 852, in __array__
    raise NotImplementedError(
NotImplementedError: Cannot convert a symbolic Tensor (layerC/forward_layerB/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
<代码> 2021-02-1017:51:13.037468:I TysFult/Cys/JIT/XLAYCPUION.CAR:41)不创建XLA设备,TFXXLANEABLE LXLAX设备未设置 2021-02-10 17:51:13.037899:I tensorflow/core/platform/cpu_feature_guard.cc:142]此tensorflow二进制文件使用oneAPI深度神经网络库(oneDNN)进行优化,以便在性能关键型操作中使用以下cpu指令:SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA 要在其他操作中启用它们,请使用适当的编译器标志重新生成TensorFlow。 2021-02-10 17:51:13.038418:I tensorflow/core/common_runtime/process_util.cc:146]使用默认的操作间设置创建新线程池:2。使用inter_op_parallelism_线程进行优化,以获得最佳性能。 回溯(最近一次呼叫最后一次): 文件“/run/media/volker/DATA/configruns/load//test.py”,第13行,在 lstm=双向(lstm_nobi,name=“layerC”)(嵌入层) ... 省略,请参见pastebin。。。 文件“/usr/lib/python3.9/site packages/tensorflow/python/framework/ops.py”,第852行,在数组中__ 引发未实现的错误( NotImplementedError:无法将符号张量(layerC/forward\u layerB/Stread\u slice:0)转换为numpy数组。此错误可能表示您正试图将张量传递给numpy调用,这是不受支持的
解决方案:使用Python 3.8,因为Tensorflow不支持Python 3.9。

安装numpy 1.19.5对我来说很有用

pip install -U numpy==1.19.5

我的环境是Windows,因为我没有安装Visual C++编译器,所以我使用第三方WHL文件安装< /P>

pip install -U https://mirrors.aliyun.com/pypi/packages/bc/40/d6f7ba9ce5406b578e538325828ea43849a3dfd8db63d1147a257d19c8d1/numpy-1.19.5-cp39-cp39-win_amd64.whl#sha256=0eef32ca3132a48e43f6a0f5a82cb508f22ce5a3d6f67a8329c81c8e226d3f6e

仅供参考,我使用anaconda运行您的代码时没有任何问题。我的tf版本是2.3.0、python 3.7.0、numpy 1.19.2。我希望这对我的解决方案有帮助:使用python 3.8,因为Tensorflow不支持python 3.9。这个解决方案在Linux、python 3.8和Tensorflow 2.4.1中对我有效。我不得不降级numpy版本。
pip install -U https://mirrors.aliyun.com/pypi/packages/bc/40/d6f7ba9ce5406b578e538325828ea43849a3dfd8db63d1147a257d19c8d1/numpy-1.19.5-cp39-cp39-win_amd64.whl#sha256=0eef32ca3132a48e43f6a0f5a82cb508f22ce5a3d6f67a8329c81c8e226d3f6e