使用Keras时,如果混合使用Keras和tensorflow.keras,并从不同的来源导入不同的模块混用,可能导致该错误,毕竟这俩不完全一样。例如:
# 导致出错
from tensorflow.keras.optimizers import Adam
from keras.utils import multi_gpu_model
# 正常执行
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.utils import multi_gpu_model
错误提示类似:
Traceback (most recent call last):
File "/home/guillaume/Documents/Allianz/ConstatOrNotConstatv3/train_network.py", line 109, in <module>
model = LeNet.build(width=100, height=100, depth=3, classes=5)
File "/home/guillaume/Documents/Allianz/ConstatOrNotConstatv3/lenet.py", line 39, in build
output = model(pretrainedOutput)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 443, in __call__
previous_mask = _collect_previous_mask(inputs)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 1311, in _collect_previous_mask
mask = node.output_masks[tensor_index]
AttributeError: 'Node' object has no attribute 'output_masks'
如果想解决该错误就是完全用Keras或完全用tensorflow.keras。
参考:
1、AttributeError: 'Node' object has no attribute 'output_masks'
2、https://blog.csdn.net/qq_30638831/article/details/84193517