I followed this response doing:
get_custom_objects().update(act_dispatcher)
Where act_dispatcher is a dictionary with all the activation functions I want to add like {'fun_1':fun_1, 'fun_2': fun_2}.
The first thing that caught my attention is that at the beginning, if I add nothing, get_custom_objects() returns an empty dict {}. After adding the function I check that each call to get_custom_objects() has what I said it to be.
However, I am getting ValueError: Unknown activation function:<my_fun>
I added the line
assert 'my_func', in get_custom_objects().keys()
tf.keras.layers.Dense(128, activation='my_func')
And the assertion pass without problem having the error mentioned at the keras Dense init.
The error occurs at deserialize_keras_object where:
custom_objectsisNone_GLOBAL_CUSTOM_OBJECTSis{}(Probably this shouldn't be empty).module_objects.get(object_name)returns None (module_objects seams correct).
Installation
I am using an anaconda environment. Due to an error that I had first with from keras.utils.generic_utils import get_custom_objects I installed keras-applications with conda install -c conda-forge keras-applications
I can running those code without any error, you can try to change
from tensorflow.keras.utils.generic_utils import get_custom_objectstofrom tensorflow.keras.utils import get_custom_objectssee if it helps: