【发布时间】:2021-08-24 08:55:42
【问题描述】:
自从 Tensorflow 2.6 版发布以来,我遇到了 2.5 版没有的问题。
以下代码可以正常工作:
from tensorflow.keras.utils import get_custom_objects
from tensorflow.keras.layers import Dense
def my_act(x):
return x
get_custom_objects().update({"my_act": my_act})
dense = Dense(3, activation="my_act")
但是,如果我尝试使用自定义层而不是 Tensorflow 内置层执行相同操作,则会出现错误:
ValueError: Unknown activation function: my_act. Please ensure this object is passed to the `custom_objects` argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
Here 你有最少的代码可以重现,而且我证明了 2.5 版可以正常工作(你需要重新启动运行时才能运行它)。
【问题讨论】: