• Wayne Cheng

DCGAN on 1D Datasets : How to Use Conv2D and Conv2DTranspose on 1D Data

For building Deep Convolutional Generative Adversarial Networks (DCGAN), many tutorials typically work with 2D datasets.

But what if you have a 1D dataset?

The following explains the methods that I find effective for converting 2D Keras commands to work on 1D datasets. I am creating my neural network models in Jupyter Notebook, and running Keras version 2.3.1 and Tensorflow version 2.0.0.

Use Conv1D in Place of Conv2D

The following is an example code for using Conv2D on a 2D dataset :

model.add(Conv2D(filters=64, kernel_size=(4,4), strides=(2, 2) ...

This is equivalent to using Conv1D on a 1D dataset :

model.add(Conv1D(filters=64, kernel_size=4, strides=2 ...

Reshape 1D dataset to 2D for Conv2DTranspose

The following is an example code for using Conv2DTranspose on a 2D dataset :

model.add(Conv2DTranspose(filters=64, kernel_size=(4,4), strides=(2,2) ...

This is equivalent to using Reshape on a 1D dataset :

model.add(Reshape((1, nodes_div, 64))) model.add(Conv2DTranspose(filters=64, kernel_size=(1,4), strides=(1,2) ...

In this case, a 1 row X dimension is added. During convolution, the kernel strides across the Y dimension. "nodes_div" represents the division of the final number of nodes, which is divided by the stride length for every convolution layer.

Thank you for reading. I hope you find this guide helpful for building your DCGAN on 1D datasets.

Questions or comments? You can reach me at info@audoir.com

Wayne Cheng is an A.I., machine learning, and deep learning developer at Audoir, LLC. His research involves the use of artificial neural networks to create music. Prior to starting Audoir, LLC, he worked as an engineer in various Silicon Valley startups. He has an M.S.E.E. degree from UC Davis, and a Music Technology degree from Foothill College.

Copyright © 2020 Audoir, LLC

All rights reserved