'1D CNN in TensorFlow for Time Series Classification
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:
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 Conv2D layer with Conv1D? If so, what would my filters and kernel_size be? I don't even know how to import my 1D pandas dataframe. My 2D CNN has the following architecture:
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)
])
If anyone can help, that would be great. Thank you. Below is an MWE and my 2D CNN is here.
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)]
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

