mlem icon indicating copy to clipboard operation
mlem copied to clipboard

Errror using custom loss

Open max37400 opened this issue 2 years ago • 1 comments

Hello!

I've tried to use custom loss function like this:

def rmlse(y_true, y_pred):
    return mean_squared_logarithmic_error(y_true, y_pred)**0.5

optimizer = keras.optimizers.Adam(learning_rate=0.05)
model.compile(optimizer=optimizer, loss=rmlse, metrics=['mean_absolute_error'])

The model was built successfully, but when we tried to upload that model with mlem, the provided error rises:

Unexpected error: Unknown loss function: 'rmlse'. Please ensure you are using a keras.utils.custom_object_scope and that this object is included in the scope. See 
https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

How can I use the custom loss functions? Thanks!

max37400 avatar Apr 14 '23 10:04 max37400

I assume this happens when trying to load the model. Looks like MLEM does not pin down this requirement when recursively going over the model at saving, I guess we need to see if this is fixable as a special case + add some option to make MLEM investigate reqs deeper (get more broad list of reqs, but at the same time pin reqs like this down).

aguschin avatar Apr 19 '23 10:04 aguschin