当我尝试保存我的模型时,我遇到了这些问题。此外,我使用的是Tensorflow 2.0.0和numpy 1.6.0,所以我不知道如何解决这个问题,因为在最新版本的tensorflow中,默认情况下启用了eager execution。
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.
3条答案
按热度按时间iyfjxgzm1#
当我尝试将我的项目从“tensorflow-gpu 1.12.0”迁移到“tensorflow-gpu 2.0.0”时,我遇到了同样的问题,当我启用tensorflow v2函数时,这个错误得到了解决(我最初禁用了v2函数)。
如果你之前禁用了“tf_v2”函数,也许你可以尝试注解掉它。
tf.disable_v2_behavior()
https://www.tensorflow.org/guide/migrate
sdnqo3pr2#
我升级到TensorFlow V2.0时也遇到了同样的问题。通过注解掉
#from keras import backend as K
解决了这个问题。并使用import tensorflow.keras.backend as K
nwlqm0z13#
对我来说,这个问题是由
tensorflow_addons
模块引起的,因为它在0.14
上使用了sefl.numpy
。要解决这个问题,你必须将tensorflow_addons
升级到0.16.0
或更高版本。要安装
tensorflow-addons
,请使用以下命令:pip install tensorflow-addons==0.16.1
请记住,您需要
python 3.7
及以上版本。