我想知道如何将我的数据(1000 个数字特征的列表)格式化为我的 1D CNN 将采用的形状。这是一个 image of my dataset (它采用数据帧格式 - 1000 列,9923 行),我的 CNN 的第一层将类似于
model.add(Conv1D(64,3, activation ='relu', input_shape= (1000, 1)))
最佳答案
该层的输入形状为(1000,1)。这意味着该层接受形状为 (*,1) 的任何输入。因此输入的最后一个维度应为 1。您可以 reshape 数据,如下例所示。
import tensorflow as tf
import numpy as np
data=tf.Variable(np.random.random((9923,1000)),dtype=tf.float32) #your data has shape (9923,1000)
#print(data)
data=tf.reshape(data,(9923,1000,1)) #reshape data
#print(data)
conv1d=tf.keras.layers.Conv1D(64,3, activation ='relu', input_shape= (1000, 1)) # the layer accpets any input with shape (*,1).
# That means the last dimention should be 1
cnn_data=conv1d(data) # output cnn_data has shape (9923,998,64)
关于python - 如何为 1D CNN 格式化 1D 数组数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62886956/