【发布时间】:2021-03-25 21:14:02
【问题描述】:
我关注了this的回复:
get_custom_objects().update(act_dispatcher)
act_dispatcher 是一个字典,其中包含我想添加的所有激活函数,例如 {'fun_1':fun_1, 'fun_2': fun_2}。
首先引起我注意的是,在开始时,如果我什么都不添加,get_custom_objects() 返回一个空字典{}。添加函数后,我检查每个对get_custom_objects() 的调用是否符合我所说的。
但是,我收到了ValueError: Unknown activation function:<my_fun>
我加了一行
assert 'my_func', in get_custom_objects().keys()
tf.keras.layers.Dense(128, activation='my_func')
并且断言通过没有问题,在 keras Dense init 中提到了错误。
错误发生在deserialize_keras_object,其中:
-
custom_objects是None -
_GLOBAL_CUSTOM_OBJECTS是{}(可能不应该为空)。 -
module_objects.get(object_name)返回无(module_objects 接缝正确)。
安装
我正在使用 anaconda 环境。由于我首先使用from keras.utils.generic_utils import get_custom_objects 出现错误,我使用conda install -c conda-forge keras-applications 安装了keras-applications
【问题讨论】:
标签: python tensorflow tensorflow2.0 activation-function