{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/2221","repository_url":"https://api.github.com/repos/fchollet/keras","labels_url":"https://api.github.com/repos/fchollet/keras/issues/2221/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/2221/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/2221/events","html_url":"https://github.com/fchollet/keras/issues/2221","id":146549017,"number":2221,"title":"[enhancement] Write a custom layer for integer output","user":{"login":"philipperemy","id":4516927,"avatar_url":"https://avatars.githubusercontent.com/u/4516927?v=3","gravatar_id":"","url":"https://api.github.com/users/philipperemy","html_url":"https://github.com/philipperemy","followers_url":"https://api.github.com/users/philipperemy/followers","following_url":"https://api.github.com/users/philipperemy/following{/other_user}","gists_url":"https://api.github.com/users/philipperemy/gists{/gist_id}","starred_url":"https://api.github.com/users/philipperemy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philipperemy/subscriptions","organizations_url":"https://api.github.com/users/philipperemy/orgs","repos_url":"https://api.github.com/users/philipperemy/repos","events_url":"https://api.github.com/users/philipperemy/events{/privacy}","received_events_url":"https://api.github.com/users/philipperemy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-07T08:44:58Z","updated_at":"2016-04-17T22:46:46Z","closed_at":null,"body":"## This is not an issue but a proposal to enhance Keras. \r\n\r\n### Problem encountered\r\nPredict an integer value [0, +oo[. With the activation functions, I use relu or linear but I didn't know how to output only integers. So I came up with my own (very simple) implementation.\r\n\r\n\r\nWould it be useful to include this code in Keras? That's an open question. Also we could give a function pointer to have any function if Round is restrictive. For example \r\n```\r\nCustom.__init__(self, func_ptr, **kwargs)\r\n```\r\n\r\nLet me know.\r\n\r\n### Source code\r\n```\r\nfrom keras.layers import Layer\r\nimport keras.backend as K\r\n\r\nclass Round(Layer):\r\n\r\n    def __init__(self, **kwargs):\r\n        super(Round, self).__init__(**kwargs)\r\n\r\n    def get_output(self, train=False):\r\n        X = self.get_input(train)\r\n        return K.round(X)\r\n\r\n    def get_config(self):\r\n        config = {\"name\": self.__class__.__name__}\r\n        base_config = super(Round, self).get_config()\r\n        return dict(list(base_config.items()) + list(config.items()))\r\n```\r\n\r\n### Example of a network\r\n\r\n```\r\nm = Sequential()\r\nm.add(Dense(20, input_shape=(max_features,)))\r\nm.add(Activation('relu'))\r\nm.add(Dense(20))\r\nm.add(Activation('relu'))\r\nm.add(Dense(3))\r\nm.add(Round())\r\nm.compile(loss='mean_absolute_error', optimizer='adam')\r\n```"},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/211125409","html_url":"https://github.com/fchollet/keras/issues/2221#issuecomment-211125409","issue_url":"https://api.github.com/repos/fchollet/keras/issues/2221","id":211125409,"user":{"login":"carlthome","id":1595907,"avatar_url":"https://avatars.githubusercontent.com/u/1595907?v=3","gravatar_id":"","url":"https://api.github.com/users/carlthome","html_url":"https://github.com/carlthome","followers_url":"https://api.github.com/users/carlthome/followers","following_url":"https://api.github.com/users/carlthome/following{/other_user}","gists_url":"https://api.github.com/users/carlthome/gists{/gist_id}","starred_url":"https://api.github.com/users/carlthome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlthome/subscriptions","organizations_url":"https://api.github.com/users/carlthome/orgs","repos_url":"https://api.github.com/users/carlthome/repos","events_url":"https://api.github.com/users/carlthome/events{/privacy}","received_events_url":"https://api.github.com/users/carlthome/received_events","type":"User","site_admin":false},"created_at":"2016-04-17T22:46:46Z","updated_at":"2016-04-17T22:46:46Z","body":"Does this network actually train properly? It seems every layer before the Round() layer should never have their weights updated. Do the Dense layers' weights ever change, for example?"}}