Concatenate two layers Tensorflow js

0 votes

I am new to TensorflowJS and I try to code something but I am stuck...

I have two input layers like that:

const input1 = tf.input({ shape: [64, 64, 3] });
const input2 = tf.input({ shape: [1536] });

The first one is for an image of 64 by 64 and the 3 is for RGB. The second one is for an array that contains 1536 numbers (floats).

I tried to concatenate them with .concatenate().apply(input1, input2) but got the following error:

ValueError: A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got input shapes: [[null,64,64,3],[null,1536]]

I also tried to add { axis: -1 } or { axis: 1 } (found that on stack overflow but that doesnt work too).

I also tried that (answer by chat gpt) :

const flatten1 = tf.layers.flatten().apply(input1);
const flatten2 = tf.layers.flatten().apply(input2);
const concat = tf.layers.concatenate({ axis: -1 }).apply([flatten1, flatten2]);

but same error...

Can someone help me? I just want to add this to my tf.sequential() as an input...

PS: This is the module I use: const tf = require('@tensorflow/tfjs-node');

Jan 31, 2023 in Data Science by Tejashwini
• 3,820 points

edited 5 days ago 12 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP