payload: {"action":"opened","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/34140","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/34140/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/34140/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/34140/events","html_url":"https://github.com/tensorflow/tensorflow/issues/34140","id":520608646,"node_id":"MDU6SXNzdWU1MjA2MDg2NDY=","number":34140,"title":"[tf2.0] Can not load keras saved model with customized loss function","user":{"login":"saintthor","id":3753880,"node_id":"MDQ6VXNlcjM3NTM4ODA=","avatar_url":"https://avatars1.githubusercontent.com/u/3753880?v=4","gravatar_id":"","url":"https://api.github.com/users/saintthor","html_url":"https://github.com/saintthor","followers_url":"https://api.github.com/users/saintthor/followers","following_url":"https://api.github.com/users/saintthor/following{/other_user}","gists_url":"https://api.github.com/users/saintthor/gists{/gist_id}","starred_url":"https://api.github.com/users/saintthor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saintthor/subscriptions","organizations_url":"https://api.github.com/users/saintthor/orgs","repos_url":"https://api.github.com/users/saintthor/repos","events_url":"https://api.github.com/users/saintthor/events{/privacy}","received_events_url":"https://api.github.com/users/saintthor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-11-10T14:29:02Z","updated_at":"2019-11-10T14:29:02Z","closed_at":null,"author_association":"NONE","body":"I run tensorflow.keras on colab.research.google.com. \r\n\r\nIn tf2.0, I trained a model with a customized loss function named Loss, then saved it by keras.Model.save().\r\nWhen I try loading it by \r\n`keras.models.load_model( 'filename', custom_objects = { 'Loss': Loss } )`\r\nIt raises:\r\n> /tensorflow-2.0.0/python3.6/tensorflow_core/python/keras/engine/training_utils.py in get_loss_function(loss)\r\n>    1092   return losses.LossFunctionWrapper(\r\n>    1093       loss_fn,\r\n> -> 1094       name=loss_fn.__name__,\r\n>    1095       reduction=losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE)\r\n>    1096 \r\n> \r\n> AttributeError: 'Loss' object has no attribute '__name__'\r\n\r\nEven to set Loss.__name__ = 'xxx' before calling load_model does not help.\r\n\r\nIf set the 'compile' param to True for load_model, it may load successfully. But the loaded model can not work on evaluating or predicting.\r\n\r\nTo load the files saved by keras of tf1.5 is all OK. The model is trained by the same customized loss function. The model is saved to a file by tf1.5, while to a path by tf2.0.\r\n\r\nHow can I solve it?"}}
other: {"actor":{"display_login":"saintthor"}}