Keras: Regularizer config does not serialize to YAML

Created on 14 Apr 2016  路  3Comments  路  Source: keras-team/keras

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())
stale

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, ...

All 3 comments

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)

Was this page helpful?
0 / 5 - 0 ratings