I am building a neural network architecture where the 'approach_1' layer takes an input of shape (None, 1024,12). Each of the 12 channels of the input is processed separately. Basically, this is an input of ECG signal of 12 leads. Where, each lead has 1024 data points.
For each lead, I have used a defined layer named 'OneD_Net_1'. This is simply processing a single input channel with a 1D convolutional layer and pooling.
Now, after processing 12 channels differently with OneD_Net_1, I am taking global average pooling for each channel. So, according to my model, after global pooling, each channel has an output shape of (None, 256).
Now I want to contact these 12 outputs in a shape (None, 256,12)
I am using TensorFlow concat to do so. But the output shape is not showing what I wanted. I know there are serious mistakes while I am concatenating. But I am not able to debug this. Can anyone please help?
def OneD_Net_1(x):
conv_1= Conv1D(64,32,activation='relu',padding='same')(x)
conv_1= AveragePooling1D(4)(conv_1)
conv_2=Conv1D(128,16,activation='relu',padding='same')(conv_1)
conv_2=AveragePooling1D(4)(conv_2)
conv_3=Conv1D(256,4,activation='relu',padding='same')(conv_2)
conv_3=AveragePooling1D(4)(conv_3)
return conv_3
def approach_1(x):
# shape of x: (None, 1024,12)
OneD_Net_1_1=OneD_Net_1(x[:,:,0:1])
global_avg_pool_1 = GlobalAveragePooling1D()(OneD_Net_1_1)
OneD_Net_1_2=OneD_Net_1(x[:,:,1:2])
global_avg_pool_2 = GlobalAveragePooling1D()(OneD_Net_1_2)
OneD_Net_1_3=OneD_Net_1(x[:,:,2:3])
global_avg_pool_3 = GlobalAveragePooling1D()(OneD_Net_1_3)
OneD_Net_1_4=OneD_Net_1(x[:,:,3:4])
global_avg_pool_4 = GlobalAveragePooling1D()(OneD_Net_1_4)
OneD_Net_1_5=OneD_Net_1(x[:,:,4:5])
global_avg_pool_5 = GlobalAveragePooling1D()(OneD_Net_1_5)
OneD_Net_1_6=OneD_Net_1(x[:,:,5:6])
global_avg_pool_6 = GlobalAveragePooling1D()(OneD_Net_1_6)
OneD_Net_1_7=OneD_Net_1(x[:,:,6:7])
global_avg_pool_7 = GlobalAveragePooling1D()(OneD_Net_1_7)
OneD_Net_1_8=OneD_Net_1(x[:,:,7:8])
global_avg_pool_8 = GlobalAveragePooling1D()(OneD_Net_1_8)
OneD_Net_1_9=OneD_Net_1(x[:,:,8:9])
global_avg_pool_9 = GlobalAveragePooling1D()(OneD_Net_1_9)
OneD_Net_1_10=OneD_Net_1(x[:,:,9:10])
global_avg_pool_10 = GlobalAveragePooling1D()(OneD_Net_1_10)
OneD_Net_1_11=OneD_Net_1(x[:,:,10:11])
global_avg_pool_11 = GlobalAveragePooling1D()(OneD_Net_1_11)
print(global_avg_pool_11.shape)
OneD_Net_1_12=OneD_Net_1(x[:,:,11:12])
global_avg_pool_12 = GlobalAveragePooling1D()(OneD_Net_1_12)
concat= tf.keras.layers.Concatenate(axis=1)([global_avg_pool_1,global_avg_pool_2,global_avg_pool_3,global_avg_pool_4,global_avg_pool_5,global_avg_pool_6,global_avg_pool_7,
global_avg_pool_8,global_avg_pool_9,global_avg_pool_10,global_avg_pool_11,global_avg_pool_12])
return concat
And the output:
x=np.ones((10,1024,12))
x.shape
net=approach_1(x)
net.shape # (10,3072), but I wanted (10,256,12)