input shape for 3d tensor

406 views
Skip to first unread message

gotostereo

unread,
Dec 23, 2020, 3:03:45 AM12/23/20
to TensorFlow.js Discussion
Hello, i have data in 3d array

tf.tensor3d

Tensor
    [[[0 , 0.5 ],
      [1 , 1.5 ],
      [2 , 2.5 ],
      [3 , 3.5 ],
      [4 , 4.5 ]],

     [[5 , 5.5 ],
      [6 , 6.5 ],
      [7 , 7.5 ],
      [8 , 8.5 ],
      [9 , 9.5 ]],

     [[10, 10.5],
      [11, 11.5],
      [12, 12.5],
      [13, 13.5],
      [14, 14.5]],

     [[15, 15.5],
      [16, 16.5],
      [17, 17.5],
      [18, 18.5],
      [19, 19.5]],

     [[20, 20.5],
      [21, 21.5],
      [22, 22.5],
      [23, 23.5],
      [24, 24.5]]]

I don't set input shape, try 

        this.model.add( tf.layers.dense( { 
            units: 5, 
            inputShape: [[2]],
            activation: 'linear'
        } ) );

Error: Tensor must have a shape comprised of positive integers but got shape [2,5].
How fix it?

Mark Strefford

unread,
Dec 23, 2020, 4:48:19 AM12/23/20
to TensorFlow.js Discussion, gotos...@gmail.com
Dense layers only take a 1D tensor, for example of shape [5]. I'm assuming in your example that you have 5 training examples there, each of shape [2, 5]. If this is the case, you'll need to flatten / reshape each example to be shape [10] and build your dense layer accordingly.

Mark Strefford

unread,
Dec 23, 2020, 4:50:32 AM12/23/20
to TensorFlow.js Discussion, Mark Strefford, gotos...@gmail.com
See https://js.tensorflow.org/api/latest/#layers.dense

  • inputDim (number) If specified, defines inputShape as [inputDim].

Reply all
Reply to author
Forward
0 new messages