{"id":19459803,"url":"https://github.com/jsflo/kotlin-tensorflow-ext","last_synced_at":"2026-06-20T14:06:37.935Z","repository":{"id":187794771,"uuid":"103043347","full_name":"JsFlo/kotlin-tensorflow-ext","owner":"JsFlo","description":"Kotlin extension functions to wrap the Tensorflow Java API","archived":false,"fork":false,"pushed_at":"2017-09-11T23:16:37.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T02:16:02.865Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/JsFlo.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}},"created_at":"2017-09-10T16:14:31.000Z","updated_at":"2017-09-11T23:19:57.000Z","dependencies_parsed_at":"2023-08-12T06:52:19.314Z","dependency_job_id":null,"html_url":"https://github.com/JsFlo/kotlin-tensorflow-ext","commit_stats":null,"previous_names":["jsflo/kotlin-tensorflow-ext"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JsFlo%2Fkotlin-tensorflow-ext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JsFlo%2Fkotlin-tensorflow-ext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JsFlo%2Fkotlin-tensorflow-ext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JsFlo%2Fkotlin-tensorflow-ext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JsFlo","download_url":"https://codeload.github.com/JsFlo/kotlin-tensorflow-ext/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240664480,"owners_count":19837563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-10T17:34:09.741Z","updated_at":"2026-06-20T14:06:32.915Z","avatar_url":"https://github.com/JsFlo.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kotlin-tensorflow-ext\n\nI've been using the Python API of [Tensorflow](https://www.tensorflow.org/)\nrecently for creating some simple models. I also have been trying to learn a new\nprogramming language called Kotlin since [Google announced that Kotlin is an officially\n                                          supported language for Android Developement](https://www.youtube.com/watch?v=d8ALcQiuPWs).\n\nI noticed that the Java API of Tensorflow is in its early stages and had an [\"experimental API\"](https://www.tensorflow.org/api_docs/java/reference/org/tensorflow/package-summary)\nwhich felt like the perfect opportunity to try to use and learn\nKotlin's extension functions to provide a better API and to learn the current limitations, compared to the python api, of the Java API.\n\n## Constants\n```kotlin\nGraph().use { graph -\u003e\n\n    val value = \"Hello from  ${TensorFlow.version()}\"\n    val myConst = graph.addConstant(\"aConstant\", value)\n\n    Session(graph).use { sess -\u003e\n\n        sess.runner()\n        .fetch(myConst)\n        .runFirstTensor({ output -\u003e\n        Assert.assertEquals(value, output.bytesValue().toUTF8String())\n        })\n\n    }\n}\n```\n\n## Placeholders\n```kotlin\nGraph().use { graph -\u003e\n\n    // Creates a graph for y = a (placeholder) + b (placeholder)\n    val a = graph.addPlaceholder(\"a\", DataType.FLOAT)\n    val b = graph.addPlaceholder(\"b\", DataType.FLOAT)\n    val y = graph.Operation(\"y\", OperationType.ADD, a, b)\n\n    Session(graph).use { sess -\u003e\n\n        val ta = Tensor.create(10f)\n        val tb = Tensor.create(10f)\n        sess.runner()\n        .feed(a, ta)\n        .feed(b, tb)\n        .fetch(y)\n        .runFirstTensor {\n            println(\"${ta.floatValue()} + ${tb.floatValue()} = ${it.floatValue()}\")\n            Assert.assertEquals(ta.floatValue() + tb.floatValue(), it.floatValue())\n        }\n    ta.close()\n    tb.close()\n    }\n}\n```\n## Operations\n```kotlin\nval a = graph.addPlaceholder(\"a\", DataType.FLOAT)\nval b = graph.addPlaceholder(\"b\", DataType.FLOAT)\n\nval y = graph.Operation(\"y\", OperationType.ADD, a, b)\nval y = graph.Operation(\"y\", OperationType.SUB, a, b)\nval y = graph.Operation(\"y\", OperationType.MUL, a, b)\nval y = graph.Operation(\"y\", OperationType.DIV, a, b)\n\nval y = graph.Operation(\"multiArg\", OperationType.Add, a, b, c, d, e, f)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsflo%2Fkotlin-tensorflow-ext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsflo%2Fkotlin-tensorflow-ext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsflo%2Fkotlin-tensorflow-ext/lists"}