NotImplementedError: numpy() 仅在启用急切执行时可用 [英] NotImplementedError: numpy() is only available when eager execution is enabled
问题描述
当我尝试保存模型时遇到这些问题.另外,我使用的是Tensorflow 2.0.0和numpy 1.6.0,所以我不知道如何解决这个问题,因为在最新版本的tensorflow中,默认启用了eager execution.
I have these problem when I try to save my model. Besides, I am using Tensorflow 2.0.0 and numpy 1.6.0, so I don't know how to solve the problem because in the latest versions of tensorflow, the eager execution is enabled by default.
Compilamos
Entrenamos
Train on 946 samples, validate on 237 samples
Epoch 1/2
946/946 [==============================] - 5s 5ms/step - loss: 0.6866 - accuracy: 0.5719 - val_loss: 0.6897 - val_accuracy: 0.5316
Epoch 2/2
946/946 [==============================] - 5s 5ms/step - loss: 0.6782 - accuracy: 0.5729 - val_loss: 0.6862 - val_accuracy: 0.5316
Entrenamiento finalizado
Traceback (most recent call last):
File "<ipython-input-23-35267c139307>", line 1, in <module>
runfile('C:/Users/Narcis Teodoroiu/Desktop/Version MASK R-CNN/TILErecognitionYcant.py', wdir='C:/Users/Narcis Teodoroiu/Desktop/Version MASK R-CNN')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Narcis Teodoroiu/Desktop/Version MASK R-CNN/TILErecognitionYcant.py", line 332, in <module>
model.save('tile_cnn_model.h5')
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\network.py", line 1152, in save
save_model(self, filepath, overwrite, include_optimizer)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\saving.py", line 449, in save_wrapper
save_function(obj, filepath, overwrite, *args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\saving.py", line 541, in save_model
_serialize_model(model, h5dict, include_optimizer)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\saving.py", line 179, in _serialize_model
'config': model.optimizer.get_config()
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\optimizers.py", line 557, in get_config
config = {'learning_rate': float(K.get_value(self.learning_rate)),
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 2927, in get_value
return x.numpy()
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 579, in numpy
"numpy() is only available when eager execution is enabled.")
NotImplementedError: numpy() is only available when eager execution is enabled.
推荐答案
我在尝试将我的项目从tensorflow-gpu 1.12.0"迁移到tensorflow-gpu 2.0.0"时遇到了同样的问题,并且这个错误当我启用 tensorflow v2 函数时解决了(我首先禁用了 v2 函数).
I have the same issue when try to migrate my project from "tensorflow-gpu 1.12.0" to "tensorflow-gpu 2.0.0", and this error was solved when I enabled tensorflow v2 functions (I disabled v2 functions at first).
如果您之前禁用了tf_v2"功能,也许您可以尝试将其注释掉.
If you disabled "tf_v2" function before, maybe you can try to comment it out.
#tf.disable_v2_behavior()
# tf.disable_v2_behavior()
https://www.tensorflow.org/guide/migrate
这篇关于NotImplementedError: numpy() 仅在启用急切执行时可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!