ValueError:未知的激活函数:swish_activation

时间:2019-10-22 09:25:59

标签: python tensorflow keras activation-function

我正在尝试使用keras load_model()加载保存权重。

from keras.models import load_model

model=load_model("weights.hdf5")

这是我得到的错误。

ValueError                                Traceback (most recent call last)
<ipython-input-34-52d6983dfc34> in <module>()
      1 from keras.models import load_model
----> 2 model=load_model("weights.hdf5")

14 frames
/usr/local/lib/python3.6/dist-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    165             if fn is None:
    166                 raise ValueError('Unknown ' + printable_module_name +
--> 167                                  ':' + function_name)
    168         return fn
    169     else:

ValueError: Unknown activation function:swish_activation

2 个答案:

答案 0 :(得分:1)

# model use some custom objects, so before loading saved model
# import module your network was build with
# e.g. import efficientnet.keras / import efficientnet.tfkeras
import efficientnet.tfkeras
from tensorflow.keras.models import load_model
model = load_model('path/to/model.h5')

答案 1 :(得分:0)

Keras默认不提供

Swish激活。而是添加以下内容:

from keras import backend as K

def swish_activation(x):
        return (K.sigmoid(x) * x)

get_custom_objects().update({'swish_activation': Activation(swish_activation)})