{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/1014","labels_url":"https://api.github.com/repos/fchollet/keras/issues/1014/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/1014/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/1014/events","html_url":"https://github.com/fchollet/keras/issues/1014","id":116976635,"number":1014,"title":"Switch to a modular backend for Theano and TensorFlow support","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},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":58,"created_at":"2015-11-15T06:29:52Z","updated_at":"2015-11-27T20:30:55Z","closed_at":null,"body":"Here's the `backend` branch, introducing `theano_backend.py` and `tensorflow_backend.py`: https://github.com/fchollet/keras/tree/backend/keras/backend\r\n\r\nIt's still a work in progress. It contains 95% of the Theano functionality used in Keras, implemented both in Theano and in TensorFlow, and accessible through a same API. \r\n\r\nThe general usage in Keras would be as follow (just a trivial example):\r\n```python\r\nfrom keras import backend as K\r\n\r\nx = K.variable(np.random.random((3, 4)))\r\ny = K.placeholder(ndim=2)\r\nz = K.exp(x) + y\r\nf = K.function(inputs=[y], outputs=[z], updates=[(x, x * 2)])\r\n```\r\n\r\n### What isn't implemented:\r\n- `rnn`, the equivalent of Theano's `scan`.\r\n- the remaining 5%: as far as I can tell, `shape_padright`, `tensordot`, and `batched_tensordot`, the broadcasting business... we might deal with it by eliminating these from the Keras codebase.\r\n\r\n### Known issues\r\n`conv2d` and `maxpool2d` work separately in TF and Theano, but output different values. It is unclear yet why. Not a big issue unless we want trained models to be portable from one backend to another (which I would prefer, of course).\r\n\r\n### What's next\r\n\r\n- adding Theano and TF implementations for `rnn`\r\n- figuring out the `conv2d` and `maxpool2d` issue\r\n- rewriting Keras to use the backend (`K`) instead of Theano. In 95% of cases this would be a trivial search-and-replace. The remaining 5% might require extending the backend a little bit, or reimplementing old Theano functionality with existing backend primitives.\r\n\r\nIf you have cycles to spare, please consider helping out with the rewriting of Keras. It is simple and quite impactful."},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/160200679","html_url":"https://github.com/fchollet/keras/issues/1014#issuecomment-160200679","issue_url":"https://api.github.com/repos/fchollet/keras/issues/1014","id":160200679,"user":{"login":"farizrahman4u","id":11006006,"avatar_url":"https://avatars.githubusercontent.com/u/11006006?v=3","gravatar_id":"","url":"https://api.github.com/users/farizrahman4u","html_url":"https://github.com/farizrahman4u","followers_url":"https://api.github.com/users/farizrahman4u/followers","following_url":"https://api.github.com/users/farizrahman4u/following{/other_user}","gists_url":"https://api.github.com/users/farizrahman4u/gists{/gist_id}","starred_url":"https://api.github.com/users/farizrahman4u/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/farizrahman4u/subscriptions","organizations_url":"https://api.github.com/users/farizrahman4u/orgs","repos_url":"https://api.github.com/users/farizrahman4u/repos","events_url":"https://api.github.com/users/farizrahman4u/events{/privacy}","received_events_url":"https://api.github.com/users/farizrahman4u/received_events","type":"User","site_admin":false},"created_at":"2015-11-27T20:30:55Z","updated_at":"2015-11-27T20:30:55Z","body":"> How should the choice of the backend be handled by the user?\r\n\r\nSomething like `keras.set_backend('tensorflow')` would be the best way to do. One of the key features of Keras is that a single python file completely defines a model (no prototxt etc), so we have everything in one  place. Declaring a backend flag in an external text file would be against this spirit of  keras in my opinion. "}}