{"id":18080672,"url":"https://github.com/omaraflak/keras-android-xor","last_synced_at":"2026-03-17T18:36:51.185Z","repository":{"id":82863435,"uuid":"119731502","full_name":"omaraflak/Keras-Android-XOR","owner":"omaraflak","description":"How to run a Keras model on Android using Tensorflow API.","archived":false,"fork":false,"pushed_at":"2018-02-01T17:15:38.000Z","size":177,"stargazers_count":32,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T14:23:01.053Z","etag":null,"topics":["android","keras","tensorflow","tensorflow-inference-interface","tensorflow-lite","xor"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/omaraflak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-01-31T19:15:00.000Z","updated_at":"2024-12-09T07:17:12.000Z","dependencies_parsed_at":"2023-03-02T04:45:56.518Z","dependency_job_id":null,"html_url":"https://github.com/omaraflak/Keras-Android-XOR","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/omaraflak/Keras-Android-XOR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaraflak%2FKeras-Android-XOR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaraflak%2FKeras-Android-XOR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaraflak%2FKeras-Android-XOR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaraflak%2FKeras-Android-XOR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omaraflak","download_url":"https://codeload.github.com/omaraflak/Keras-Android-XOR/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaraflak%2FKeras-Android-XOR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30628419,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","keras","tensorflow","tensorflow-inference-interface","tensorflow-lite","xor"],"created_at":"2024-10-31T13:09:22.150Z","updated_at":"2026-03-17T18:36:51.175Z","avatar_url":"https://github.com/omaraflak.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to run a Keras model on Android\n\nThis code is a simple example to understand how to run a Keras model on Android using Tensorflow API.\n\n## Train the model on a computer\n\nThis is a super simple model that uses Keras to learn XOR operation :\n\n**[index.py](https://github.com/OmarAflak/Keras-Android-XOR/blob/master/keras/index.py)**\n\n```python\nX = np.array([[0,0],[0,1],[1,0],[1,1]])\nY = np.array([[0],[1],[1],[0]])\n\nmodel = Sequential()\nmodel.add(Dense(8, input_dim=2, activation='tanh'))\nmodel.add(Dense(1, activation='sigmoid'))\nmodel.compile(loss='binary_crossentropy', optimizer=SGD(lr=0.1))\nmodel.fit(X, Y, batch_size=1, nb_epoch=1000)\n```\n\nrun the python script :\n\n    python index.py\n    \nWhen done, the script should have created an `out` folder which contains several files. Among them, **`tensorflow_lite_xor_nn.pb`**, which is the model to export in Android **assets** folder.\n\n## Run the model on Android\n\n**[MainActivity.java](https://github.com/OmarAflak/Keras-Android-XOR/blob/master/android/app/src/main/java/aflak/me/tensorflowlitexor/MainActivity.java)**\n\n```java\npublic class MainActivity extends AppCompatActivity {\n    private TensorFlowInferenceInterface inferenceInterface;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n        // Load model from assets\n        inferenceInterface = new TensorFlowInferenceInterface(getAssets(), \"tensorflow_lite_xor_nn.pb\");\n\n        // run the model for all possible inputs i.e. [0,0], [0,1], [1,0], [1,1]\n        for(int i=0 ; i\u003c2 ; i++){\n            for(int j=0 ; j\u003c2 ; j++){\n                float[] input = {i,j};\n                float[] output = predict(input);\n\n                Log.d(getClass().getSimpleName(), Arrays.toString(input)+\" -\u003e \"+Arrays.toString(output));\n            }\n        }\n    }\n\n    private float[] predict(float[] input){\n        // model has only 1 output neuron\n        float output[] = new float[1];\n\n        // feed network with input of shape (1,input.length) = (1,2)\n        inferenceInterface.feed(\"dense_1_input\", input, 1, input.length);\n        inferenceInterface.run(new String[]{\"dense_2/Sigmoid\"});\n        inferenceInterface.fetch(\"dense_2/Sigmoid\", output);\n\n        // return prediction\n        return output;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomaraflak%2Fkeras-android-xor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomaraflak%2Fkeras-android-xor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomaraflak%2Fkeras-android-xor/lists"}