Ibr*_*idi 1 javascript machine-learning angular tensorflow.js
我正在尝试在 Angular 上设计软件,使用带有 Angular 的 Tensorflow.js 正确猜测正确的书面文字
应用程序组件.ts
import { Component, ViewChild, OnInit } from '@angular/core';
import * as tf from '@tensorflow/tfjs';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
linearModel?: tf.Sequential;
prediction: any;
ngOnInit(){
// this.trainNewModel();
}
// async trainNewModel(){
// this.linearModel = tf.sequential();
// this.linearModel.add(tf.layers.dense({
// units: 1,
// inputShape:[1]
// }));
// this.linearModel.compile({
// loss: 'meanSquareError',
// optimizer: 'sgd'
// });
// const xs = tf.tensor1d([3.2,4.4,5.5,6.71,6.98,7.168,9.779,7.59,2.16]);
// const ys = tf.tensor1d([1.6,2.7,2.9,3.19,1.684,2.53,3.366,2.596,2.53,1.22]);
// await this.linearModel.fit(xs,ys);
// console.log('model trained!');
// }
// linearPrediction(val:any){
// const output = this.linearModel.predict(tf.tensor2d([val], [1, 1])) as any;
// this.prediction = Array.from(output.dataSync())[0]
// }
}
Run Code Online (Sandbox Code Playgroud)
应用程序组件.html
<!--
<h4> preicted value: {{ prediction }}</h4>
<input type = "number" (change)= "linearPrediction()"> -->
Run Code Online (Sandbox Code Playgroud)
错误看起来像这样
ERROR
node_modules/@tensorflow/tfjs-core/dist/hash_util.d.ts:2:49 - error TS2304: Cannot find name 'Long'.
2 export declare function hexToLong(hex: string): Long;
~~~
Run Code Online (Sandbox Code Playgroud)
我找不到正确的文档来清楚地说明 tensorflow.js 在 Angular 上的用法;有人可以告诉我吗?
小智 7
与 AngularJS 无关,这是由于 TypeScript 在您的项目中针对所有依赖项(而不仅仅是您的代码)全局启用了严格类型检查
这是一个已知问题 - TFJS 是使用旧的 TS 3.x 编写的,并且 typedef 不完全符合标准
skipLibCheck=true最好的建议是通过设置来禁用 TFJS 内项目的类型检查tsconfig.json
但如果您确实想在 TS 上使用类型检查,祝您好运 - 您需要将其long@4.0.0作为依赖项包含在您的应用程序中(最新版本long@5.x不兼容)
| 归档时间: |
|
| 查看次数: |
1455 次 |
| 最近记录: |