# TensorFlowJs **Repository Path**: wdd667/TensorFlowJs ## Basic Information - **Project Name**: TensorFlowJs - **Description**: 谷歌开源TensorFlow.js demo尝试 - **Primary Language**: JavaScript - **License**: AFL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2019-12-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TensorFlowJs #### 介绍 谷歌开源TensorFlow.js demo尝试 #### 软件架构 软件架构说明 #### 安装教程 1. 2. yarn add @tensorflow/tfjs npm install @tensorflow/tfjs 3. 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(); }); ```