コアAPIを使用してモデルを作成する際にエラー

アラーEddine Chouchane:

私はTensorFlowのチュートリアルに従うことを試みた公式サイトをコアAPIに基づいて機械学習モデルを作成します。しかし、私は、次のエラーを得ました:

エラー:「MATMUL」に渡される引数「b」はテンソルまたはTensorLikeであってもよいが、得なければならない「NULL」

私は、Windows 10上と[email protected]で働いています

const tf = require('@tensorflow/tfjs');
const tfcore = require('@tensorflow/tfjs-core')


const w1 = tf.variable(tf.randomNormal([784, 32]));
const b1 = tf.variable(tf.randomNormal([32]));
const w2 = tf.variable(tf.randomNormal([32, 10]));
const b2 = tf.variable(tf.randomNormal([10]));

function model(x) {
  console.log(w1);
  return x.matMul(w1).add(b1).relu().matMul(w2).add(b2).softmax();
}


model(tfcore);

あなたは、このエラーで私を助けていただけますか?

バルボサは行きます:

@edkeveked述べ、あなたはのための2つのテンソルを供給する必要がありますtf.matMul

アプローチ1

const a = tf.tensor2d([1, 2], [1, 2]);
const b = tf.tensor2d([1, 2, 3, 4], [2, 2]);

a.matMul(b);

またはアプローチ2

const a = tf.tensor2d([1, 2], [1, 2]);
const b = tf.tensor2d([1, 2, 3, 4], [2, 2]);

tf.matMul(a, b);

あなたの例では、渡すことによってtfcoremodel()ご使用しているアプローチ2を、したがって、第二にテンソルを渡す必要がありますmatMulあなたがテンソルを渡した場合しかし、model()それのように動作するはずのアプローチ1

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=30729&siteId=1