title: 1D CNN in TensorFlow for Time Series Classification
body: <p>My Time-Series is a 30000 x 500 table representing points from three different types of graphs: Linear, Quadratic, and Cubic Sinusoidal. Thus, there are 10000 Rows for Linear Graphs, 10000 for Quadratics, and 10000 for Cubics. I have sampled 500 points from every graph. Here's an image to illustrate my point:</p>
  <p><a href="https://i.stack.imgur.com/c3vHU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c3vHU.png" alt="enter image description here" /></a></p>
  <p>I've built a 98% accurate 2D CNN using TensorFlow, but now I want to build a 1D CNN using TensorFlow. Do I just replace every <code>Conv2D</code> layer with <code>Conv1D</code>? If so, what would my <code>filters</code> and <code>kernel_size</code> be? I don't even know how to import my 1D pandas dataframe. My 2D CNN has the following architecture:</p>
  <pre><code>model = tf.keras.Sequential([
    tf.keras.layers.experimental.preprocessing.Rescaling(1./255),
    tf.keras.layers.Conv1D( 32, 3, activation='relu', input_shape=input_shape[2:])(x), #32 FILTERS and square stride of size 3
    tf.keras.layers.MaxPooling2D(),
    tf.keras.layers.Conv2D(32, 3, activation='relu'),
    tf.keras.layers.MaxPooling2D(),
    tf.keras.layers.Conv2D(32, 3, activation='relu'),
    tf.keras.layers.MaxPooling2D(),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(num_classes)
  ])
  </code></pre>
  <p>If anyone can help, that would be great. Thank you. Below is an MWE and my 2D CNN is <a href="https://colab.research.google.com/drive/1pJhT2d4krNj4lvP_T8uLb7QZX4jt-SN3?usp=sharing" rel="nofollow noreferrer"><strong>here</strong></a>.</p>
  <pre><code>num_classes = 3
  model = tf.keras.Sequential([
    tf.keras.layers.experimental.preprocessing.Rescaling(1./255),
    tf.keras.layers.Conv2D(32, 3, activation='relu'), #32 FILTERS and square stride of size 3
    tf.keras.layers.MaxPooling2D(),
    tf.keras.layers.Conv2D(32, 3, activation='relu'),
    tf.keras.layers.MaxPooling2D(),
    tf.keras.layers.Conv2D(32, 3, activation='relu'),
    tf.keras.layers.MaxPooling2D(),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(num_classes)
  ])
  
  
  epochs = 5
  
  initial_learning_rate = 1
  decay = initial_learning_rate / epochs
  
  def lr_time_based_decay(epoch, lr):
      return lr * 1 / (1 + decay * epoch)
  
  history = model.fit(
    train_ds,
    validation_data=val_ds,
    epochs= epochs,
    callbacks= [tensorboard_callback, tf.keras.callbacks.LearningRateScheduler(lr_time_based_decay, verbose=1)]
  )
  </code></pre>