How to configure layers for simple networks in tensorflow.js?

57 Views Asked by At

TLDR: Can anyone provide the calls and params that will reproduce the example network configs below in tensorflow.js? Thanks in advance!

I'm trying to convert my existing neural networks to tensorflow.js, but I find the API confusing and the documentation isn't really helping (I am a newbie in this field). Specifically, when I add layers, I'm not sure what values I should send.

Also, I don't really understand the input 'shape'. What shape? I understand it more as a length, i.e. a number of input nodes.

I am using a sequential model and calling tf.layers.dense. My input is simple arrays of floats; XY and XYZ coords. I'm not clear on 'inputShape' vs 'batchInput' with respect to 'units'. Also, when I show modelSummary, it lists values for "Output Shape" and "# Of Params" that I don't expect.

two simple neural networks

1

There are 1 best solutions below

0
On BEST ANSWER

It turns out there is no discrete create-input-layer step. Rather, the 'input layer' is the shape of the network inputs, set as a property of the first added layer.

So in my case, I add one dense layer to network A, and two to network B, like this:

// Network A
modelA.add(tf.layers.dense({
  inputShape: 2,
  units: 1,
  useBias: true
}));

// Network B
modelB.add(tf.layers.dense({
  inputShape: 3,
  units: 4
}));

modelB.add(tf.layers.dense({
  units: 2,
  useBias: true
}));