Attempting to serialize a model containing L1 or L2 weight regularization to YAML will blowup as the the get_config
method of WeightRegularizer
returns l1
and l2
as NumPy ndarrays. For instance, the following snippet will result in yaml.dump
raising a TypeError
when it tries to serialize the arrays:
import yaml
from keras.regularizers import WeightRegularizer
reg = WeightRegularizer(l1=0.0, l2=0.01)
yaml.dump(reg.get_config())
I have the same problem. It seems that the yaml dump doesn't recognize the float32 type, but recognized only float, int, ...
Confirmed.
This yaml problem with numpy types also applies to the Dense layer's output_dim parameter.
And, I had to futz with Input's dtype parameter, but in the course of looking in to that problem, the dtype problem went away! Love that sort of thing.
Ubuntu Trusty 14.04, yaml version 3.10.
Code attached.
Short version - don't yaml this:
x = Dense(output_dim = numpy.prod(input_data[0].shape), activation = 'sigmoid' )(prev_layer)
Most helpful comment
I have the same problem. It seems that the yaml dump doesn't recognize the float32 type, but recognized only float, int, ...