
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
enh-tfjs-react-native
Advanced tools
This package provides a TensorFlow.js platform adapter for react native. It provides GPU accelerated execution of TensorFlow.js supporting all major modes of tfjs usage, include:
These instructions (and this library) assume that you are generally familiar with react native development.
This library relies on expo-gl and expo-gl-cpp. Thus you must use a version of React Native that is supported by Expo.
Some parts of tfjs-react-native are not compatible with managed expo apps. You must use the bare workflow (or just plain react native) if you want to use the following functionality:
You can use the React Native CLI or Expo.
On macOS (to develop iOS applications) You will also need to use CocoaPods to install these dependencies.
Note that if you are using in a managed expo app the install instructions may be different.
npm install @tensorflow/tfjs
npm install enh-tfjs-react-native
After this point, if you are using Xcode to build for ios, you should use a ‘.workspace’ file instead of the ‘.xcodeproj’
This step is only needed if you want to use the bundleResourceIO loader.
Edit your metro.config.js
to look like the following. Changes are noted in
the comments below.
const { getDefaultConfig } = require('metro-config');
module.exports = (async () => {
const defaultConfig = await getDefaultConfig();
const { assetExts } = defaultConfig.resolver;
return {
resolver: {
// Add bin to assetExts
assetExts: [...assetExts, 'bin'],
}
};
})();
Before using tfjs in a react native app, you need to call tf.ready()
and wait for it to complete. This is an async function so you might want to do this in a componentDidMount
or before the app is rendered.
The example below uses a flag in the App state to indicate that TensorFlow is ready.
import * as tf from '@tensorflow/tfjs';
import 'enh-tfjs-react-native';
export class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isTfReady: false,
};
}
async componentDidMount() {
// Wait for tf to be ready.
await tf.ready();
// Signal to the app that tensorflow.js can now be used.
this.setState({
isTfReady: true,
});
}
render() {
//
}
}
If you use expo and encounter a build failure when running npm run web
due to
You may need an appropriate loader to handle this file type...
error, follow
the steps below to make expo correctly transpile tfjs packages:
expo customize:web
webpack.config.js
entry, then press "enter".webpack.config.js
file.webpack.config.js
file as follows:const createExpoWebpackConfigAsync = require('@expo/webpack-config');
module.exports = async function(env, argv) {
const config = await createExpoWebpackConfigAsync(
{
...env,
babel: {
dangerouslyAddModulePathsToTranspile: [
// Ensure that all packages starting with @tensorflow are
// transpiled.
'@tensorflow',
],
},
},
argv);
return config;
};
You can take a look at integration_rn59/App.tsx
for an example of what using tfjs-react-native looks like. In future we will add an example to the tensorflow/tfjs-examples repository.
The Webcam demo folder has an example of a style transfer app.
Many tfjs-models use web APIs for rendering or input, these are not generally compatible with React Native, to use them you generally need to feed a tensor into the model and do any rendering of the model output with react native components. If there is no API for passing a tensor into a tfjs-model, feel free to file a GitHub issue.
When reporting bugs with tfjs-react-native please include the following information:
FAQs
TensorFlow.js platform implementation for React Native
The npm package enh-tfjs-react-native receives a total of 0 weekly downloads. As such, enh-tfjs-react-native popularity was classified as not popular.
We found that enh-tfjs-react-native demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.