在Angular上使用tensorflow时无法编译片段着色器

时间:2018-07-12 01:31:25

标签: angular tensorflow.js

我正在尝试在有角度的应用程序上实现迁移学习。为了收集新数据,我想我将只使用tensorflow js教程中的完全相同的代码,这是pacman游戏中使用的代码。

这是来自tensorflow.js教程的controller_dataset.js的代码。我将其导入了angular的组件上。

import * as tf from '@tensorflow/tfjs';


export class ControllerDataset {
    constructor(numClasses) {
      this.numClasses = numClasses;
    }


   addExample(example, label) {

    const y = tf.tidy(() => tf.oneHot(tf.tensor1d([label]).toInt(), this.numClasses));

    if (this.xs == null) {
      this.xs = tf.keep(example);
      this.ys = tf.keep(y);
    } else {
      const oldX = this.xs;
      this.xs = tf.keep(oldX.concat(example, 0));

      const oldY = this.ys;
      this.ys = tf.keep(oldY.concat(y, 0));

      oldX.dispose();
      oldY.dispose();
      y.dispose();
    }
  }
}

问题是,当调用controller.addExample时,它将导致以下错误

ERROR Error: Failed to compile fragment shader.
at createFragmentShader (tf-core.esm.js:17)
at e.createProgram (tf-core.esm.js:17)
at compileProgram (tf-core.esm.js:17)
at tf-core.esm.js:17
at e.getAndSaveBinary (tf-core.esm.js:17)
at e.compileAndRun (tf-core.esm.js:17)
at e.oneHot (tf-core.esm.js:17)
at ENV.engine.runKernel.indices (tf-core.esm.js:17)
at e.runKernel (tf-core.esm.js:17)
at e.oneHot (tf-core.esm.js:17)

1 个答案:

答案 0 :(得分:0)

您的错误来自使用<IfModule mod_ssl.c> <VirtualHost *:443> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin (...) DocumentRoot /var/www/html/(site) ServerName (site) # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf <Directory "/var/www/html/(site)"> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet </IfModule> 。在类的构造函数中,您传入了参数this.numClasses。但是,在调用组件时,没有定义参数numClasses。结果,numClasses将不确定。

考虑为this.numClasses分配一个值

this.numClasses