{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/569","labels_url":"https://api.github.com/repos/fchollet/keras/issues/569/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/569/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/569/events","html_url":"https://github.com/fchollet/keras/issues/569","id":102339743,"number":569,"title":"Any idea of adjusting task contributions in multi-task training","user":{"login":"rex-yue-wu","id":11779725,"avatar_url":"https://avatars.githubusercontent.com/u/11779725?v=3","gravatar_id":"","url":"https://api.github.com/users/rex-yue-wu","html_url":"https://github.com/rex-yue-wu","followers_url":"https://api.github.com/users/rex-yue-wu/followers","following_url":"https://api.github.com/users/rex-yue-wu/following{/other_user}","gists_url":"https://api.github.com/users/rex-yue-wu/gists{/gist_id}","starred_url":"https://api.github.com/users/rex-yue-wu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rex-yue-wu/subscriptions","organizations_url":"https://api.github.com/users/rex-yue-wu/orgs","repos_url":"https://api.github.com/users/rex-yue-wu/repos","events_url":"https://api.github.com/users/rex-yue-wu/events{/privacy}","received_events_url":"https://api.github.com/users/rex-yue-wu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-21T09:39:28Z","updated_at":"2015-08-21T10:05:20Z","closed_at":"2015-08-21T10:05:20Z","body":"Hi,\r\n\r\nI am using **Graph** to train a multi-task CNN. Intutively, it makes sense to force training to focus on a main task, but I did not think this simple feature has already been supported. I guess I can introduce **task_weight** into the current Graph model, but please correct me if I am wrong. \r\n\r\n```python\r\nclass Graph(Model, containers.Graph):\r\n    def compile(self, optimizer, loss, theano_mode=None):\r\n        # loss is a dictionary mapping output name to loss functions\r\n        ys = []\r\n        ys_train = []\r\n        ys_test = []\r\n        weights = []\r\n        train_loss = 0.\r\n        test_loss = 0.\r\n        for output_name in self.output_order:\r\n            loss_fn = loss[output_name]\r\n            output = self.outputs[output_name]\r\n            y_train = output.get_output(True)\r\n            y_test = output.get_output(False)\r\n            y = T.zeros_like(y_test)\r\n            ys.append(y)\r\n            ys_train.append(y_train)\r\n            ys_test.append(y_test)\r\n\r\n            if hasattr(output, \"get_output_mask\"):\r\n                mask = output.get_output_mask()\r\n            else:\r\n                mask = None\r\n\r\n            weight = T.ones_like(y_test)\r\n            weights.append(weight)\r\n            weighted_loss = weighted_objective(objectives.get(loss_fn))\r\n            # <-- begin of using task weight --> \r\n            train_loss += weighted_loss(y, y_train, weight, mask) *  task_weight\r\n            test_loss += weighted_loss(y, y_test, weight, mask) * task_weight\r\n            # <-- end of using task weight -->\r\n        train_loss.name = 'train_loss'\r\n        test_loss.name = 'test_loss'\r\n```\r\nI've also seen papers claiming it is important to stop different tasks at different iterations, but not sure how to support this feature in a systematic way ( sure I can manually stop training a model, remove the task I want to stop, and reload weights from previous trained model and lanch training on the rest of tasks again). "},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/133362259","html_url":"https://github.com/fchollet/keras/issues/569#issuecomment-133362259","issue_url":"https://api.github.com/repos/fchollet/keras/issues/569","id":133362259,"user":{"login":"fchollet","id":710255,"avatar_url":"https://avatars.githubusercontent.com/u/710255?v=3","gravatar_id":"","url":"https://api.github.com/users/fchollet","html_url":"https://github.com/fchollet","followers_url":"https://api.github.com/users/fchollet/followers","following_url":"https://api.github.com/users/fchollet/following{/other_user}","gists_url":"https://api.github.com/users/fchollet/gists{/gist_id}","starred_url":"https://api.github.com/users/fchollet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fchollet/subscriptions","organizations_url":"https://api.github.com/users/fchollet/orgs","repos_url":"https://api.github.com/users/fchollet/repos","events_url":"https://api.github.com/users/fchollet/events{/privacy}","received_events_url":"https://api.github.com/users/fchollet/received_events","type":"User","site_admin":false},"created_at":"2015-08-21T10:05:20Z","updated_at":"2015-08-21T10:05:20Z","body":"Well, that's an easy one: you multiply each loss function by a scalar. Something like:\r\n\r\n```python\r\nfrom keras.objectives import mse\r\nmodel.compile(optimizer='adam', loss={'output1': 0.2 * mse, 'ouput2':0.8 * mse})\r\n```"}}