-
Notifications
You must be signed in to change notification settings - Fork 2k
Custom Layer incompatible dimensions #8676
Copy link
Copy link
Open
Labels
Description
Hi, i try to realize a custom layer (a dense layer with bias and relu activation function only). I implemented the demonstration setup in a single page web-app and end up with following error when i start training:
Uncaught (in promise) Error: Input 0 is incompatible with layer dense_Dense1: expected min_ndim=2, found ndim=1.
Can you give me some advice or resources where different kind of custom layers are implemented in javascript (not typescript).
Here the complete web-app: index.html
Here is the custom layer i created:
class FixedRampLayer extends tf.layers.Layer {
constructor(config) {
super(config);
this.units = config.units;
}
computeOutputShape(inputShape) {
return [inputShape[0], this.units];
}
build(inputShape) {
this.bias = this.addWeight(
'bias',
[this.units],
'float32',
tf.initializers.randomUniform({minval: -1, maxval: 1})
);
}
call(inputs) {
return tf.relu(tf.add(inputs, this.bias.read()));
}
static get className() {
return 'FixedRampLayer';
}
}Here the model:
const model = tf.sequential();
model.add(new FixedRampLayer({units: 10, inputShape: [1]}));
model.add(tf.layers.dense({units: 1, useBias:true}));Reactions are currently unavailable