{"id":21932441,"url":"https://github.com/reneweb/react-native-tensorflow","last_synced_at":"2025-04-05T02:09:35.291Z","repository":{"id":57340812,"uuid":"104263174","full_name":"reneweb/react-native-tensorflow","owner":"reneweb","description":"A TensorFlow inference library for react native","archived":false,"fork":false,"pushed_at":"2021-02-15T19:19:05.000Z","size":49183,"stargazers_count":359,"open_issues_count":22,"forks_count":59,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-29T08:02:27.949Z","etag":null,"topics":["android","mobile","react-native","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reneweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-20T20:14:28.000Z","updated_at":"2024-11-12T11:42:23.000Z","dependencies_parsed_at":"2022-09-08T03:00:11.606Z","dependency_job_id":null,"html_url":"https://github.com/reneweb/react-native-tensorflow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reneweb%2Freact-native-tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reneweb%2Freact-native-tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reneweb%2Freact-native-tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reneweb%2Freact-native-tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reneweb","download_url":"https://codeload.github.com/reneweb/react-native-tensorflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276164,"owners_count":20912288,"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":["android","mobile","react-native","tensorflow"],"created_at":"2024-11-28T23:18:44.243Z","updated_at":"2025-04-05T02:09:35.273Z","avatar_url":"https://github.com/reneweb.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# react-native-tensorflow\n\n**Note: This project is not maintained anymore**\n\nA TensorFlow inference library for react native.\nIt follows the android inference api from TensorFlow: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/android\n\n## Getting started\n\n`$ npm install react-native-tensorflow --save`\n\n### Linking\n\n`$ react-native link react-native-tensorflow`\n\n#### Additional steps for iOS\n\nFor the iOS setup you will need CocoaPods.\n\nCreate a Podfile in the iOS directory with the following content:\n```\ntarget '\u003cProjectName\u003e'\n       pod 'TensorFlow-experimental'\n ```\n\nThen run `pod install`.\n\n## Usage\n\nThis library provides a api to directly interact with TensorFlow and a simple image recognition api.\nFor most use cases for image recognition the image recognition api should suffice.\n\n### Image recognition\n\nFirst you need to add the TensorFlow model as well as the label file to the project. There are a few ways to do that as described [here](#fetching-files)\n\nNext you need to initialize the TfImageRecognition class using the model and label files and then call the `recognize` function of the class with the image to recognize:\n\n```javascript\nimport { TfImageRecognition } from 'react-native-tensorflow';\n\nconst tfImageRecognition = new TfImageRecognition({\n  model: require('./assets/tensorflow_inception_graph.pb'),\n  labels: require('./assets/tensorflow_labels.txt'),\n  imageMean: 117, // Optional, defaults to 117\n  imageStd: 1 // Optional, defaults to 1\n})\n\nconst results = await tfImageRecognition.recognize({\n  image: require('./assets/apple.jpg'),\n  inputName: \"input\", //Optional, defaults to \"input\"\n  inputSize: 224, //Optional, defaults to 224\n  outputName: \"output\", //Optional, defaults to \"output\"\n  maxResults: 3, //Optional, defaults to 3\n  threshold: 0.1, //Optional, defaults to 0.1\n})\n\nresults.forEach(result =\u003e\n  console.log(\n    result.id, // Id of the result\n    result.name, // Name of the result\n    result.confidence // Confidence value between 0 - 1\n  )\n)\n\nawait tfImageRecognition.close() // Necessary in order to release objects on native side\n```\n\n### Direct API\n*Note: It is not recommended to use this API as it has some major problem described in [the second point in the known issues](https://github.com/reneweb/react-native-tensorflow/blob/master/README.md#known-issues) and is quite difficult to use in its current state.*\n\nFirst you need to add the TensorFlow model to the project. There are a few ways to do that as described [here](#fetching-files)\n\nAfter adding the model and creating a TensorFlow instance using the model you will need to feed your data as a array providing the input name, shape and data type.\nThen run the inference and lastly fetch the result.\n\n```javascript\nimport { TensorFlow } from 'react-native-tensorflow';\n\nconst tf = new TensorFlow('tensorflow_inception_graph.pb')\nawait tf.feed({name: \"inputName\", data: [1,2,3], shape:[1,2,4], dtype: \"int64\"})\nawait tf.run(['outputNames'])\nconst output = await tf.fetch('outputName')    \nconsole.log(output)\n\n```\n\nCheck the android TensorFlow example for more information on the API: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/TensorFlowImageClassifier.java\n\n### Fetching files\n\n- Add as react native asset\n\nCreate the file `rn-cli.config.js` in the root of the project and add the following code where the array contains all the file endings you want to bundle (in this case we bundle pb and txt  files next to the defaults).\n```\nmodule.exports = {\n  getAssetExts() {\n    return ['pb', 'txt']\n  }\n}\n```\nThen you can require the asset in the code, for example: `require('assets/tensorflow_inception_graph.pb')`\n\n- Add as iOS / Android asset\n\nPut the file in the android/src/main/assets folder for Android and for iOS put the file, using XCode, in the root of the project. In the code you can just reference the file path for the asset.\n\n- Load from file system\n\nPut the file into the file system and reference using the file path.\n\n- Fetch via url\n\nPass a url to fetch the file from a url. This won't store it locally, thus the next time the code is executed it will fetch it again.\n\n## Supported data types\n- DOUBLE\n- FLOAT\n- INT32\n- INT64\n- UINT8\n- BOOL - On Android will be converted into a byte array\n- STRING - On Android will be converted into a byte array\n\n## Known issues\n- When using the image recognition api the results don't match exactly between Android and iOS. Most of the time they seem reasonable close though.\n- When using the direct api the data to feed to TensorFlow needs to be provided on the JS side and is then passed to the native side. Transferring large payloads this way is very inefficient and will likely have a negative performance impact. The same problem exists when loading large data, like images, from the native side into JS side for processing.\n- The TensorFlow library itself as well as the TensorFlow models are quite large in size resulting in large builds.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freneweb%2Freact-native-tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freneweb%2Freact-native-tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freneweb%2Freact-native-tensorflow/lists"}