I want to build a 1D convolution autoencoder with 4 channels in Keras. Instead of images with RGB channels, I am working with triaxial sensor data + magnitude which calls for 4 channels. I haven't seen much information on this and I am not fully sure how to incorporate the channel information for constructing the network.

Each example is 100 data points, and 4 channels (x, y, z, mag) so the input is of shape (100,4). Since it's not image data but rather each axis is 1D sensor data, I want to just use 1D convolutions. I am not super concerned with the autoencoder architecture (what I have below is just an example I implemented quickly), but I do want to understand how to implement a 1D convolution autoencoder using multiple channels. This is what I have so far, but I am not sure it is incorporating the channels correctly so I'd love feedback on this! While the final output from the decoder is of shape (100,4), is that the correct way to reconstruct the original input?

# Encoder
encoder = Conv1D(50, 12, activation = 'relu', padding = 'same')(input_layer)
encoder = MaxPooling1D(4, padding = 'same')(encoder)

# Decoder
decoder = Conv1D(50, 12, activation = 'relu', padding = 'same')(encoder)
decoder = UpSampling1D(4)(decoder)
decoder = Conv1D(4, 12, activation = 'relu', padding = 'same')(decoder)

1 Answer 1


Conv1D has a parameter called data_format which by default is set to "channels_last". So, by default it expects inputs to be of the form (batch_size,steps,channels). To quote from the Documentation:

data_format: A string, one of "channels_last" (default) or "channels_first". The ordering of the dimensions in the inputs. "channels_last" corresponds to inputs with shape (batch, steps, channels) (default format for temporal data in Keras) while "channels_first" corresponds to inputs with shape (batch, channels, steps).

Concretely, in your network you have inputs of shape (100,4). You apply 50 1DConv filters of shape (12,4) (12 shared weights per channels) to get the output of dimension (batch_size,100,50) (50 channels each of length 100). You then apply MaxPooling1D with pool_size=4 and stride=4 with padding="same" i.e. padding=0 so your final latent feature has dimension (25,50). The convolution that follows does not change the shape. The UpSampling1D will then change the shape to (100,50) and the final convolution converts the input back to shape (100,4). So is this correct? If you are just worried about whether you got the syntax for incorporating the channels correctly then yes, you did get it right. That is how it's done.


Not the answer you're looking for? Browse other questions tagged or ask your own question.