在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:TensorFlow.js开源软件地址:https://gitee.com/mirrors/TensorFlowjs开源软件介绍:TensorFlow.jsTensorFlow.js is an open-source hardware-accelerated JavaScript library fortraining and deploying machine learning models. Develop ML in the Browser Develop ML in Node.js Run Existing models Retrain Existing models About this repoThis repository contains the logic and scripts that combineseveral packages. APIs:
Backends/Platforms:
If you care about bundle size, you can import those packages individually. If you are looking for Node.js support, check out the TensorFlow.js Node directory. ExamplesCheck out ourexamples repositoryand our tutorials. GalleryBe sure to check out the gallery of all projects related to TensorFlow.js. Pre-trained modelsBe sure to also check out our models repository where we host pre-trained modelson NPM. Benchmarks
Getting startedThere are two main ways to get TensorFlow.js in your JavaScript project:via script tags or by installing it from NPMand using a build tool like Parcel,WebPack, or Rollup. via Script TagAdd the following code to an HTML file: <html> <head> <!-- Load TensorFlow.js --> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"> </script> <!-- Place your code in the script tag below. You can also use an external .js file --> <script> // Notice there is no 'import' statement. 'tf' is available on the index-page // because of the script tag above. // Define a model for linear regression. const model = tf.sequential(); model.add(tf.layers.dense({units: 1, inputShape: [1]})); // Prepare the model for training: Specify the loss and the optimizer. model.compile({loss: 'meanSquaredError', optimizer: 'sgd'}); // Generate some synthetic data for training. const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]); const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]); // Train the model using the data. model.fit(xs, ys).then(() => { // Use the model to do inference on a data point the model hasn't seen before: // Open the browser devtools to see the output model.predict(tf.tensor2d([5], [1, 1])).print(); }); </script> </head> <body> </body></html> Open up that HTML file in your browser, and the code should run! via NPMAdd TensorFlow.js to your project using yarn or npm. Note: Becausewe use ES2017 syntax (such as import * as tf from '@tensorflow/tfjs';// Define a model for linear regression.const model = tf.sequential();model.add(tf.layers.dense({units: 1, inputShape: [1]}));// Prepare the model for training: Specify the loss and the optimizer.model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});// Generate some synthetic data for training.const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);// Train the model using the data.model.fit(xs, ys).then(() => { // Use the model to do inference on a data point the model hasn't seen before: model.predict(tf.tensor2d([5], [1, 1])).print();}); See our tutorials, examplesand documentation for more details. Importing pre-trained modelsWe support porting pre-trained models from: Various ops supported in different backendsPlease refer below : Find out moreTensorFlow.js is a part of theTensorFlow ecosystem. For more info:
Thanks, BrowserStack, for providing testing support. |
请发表评论