我有一个批处理生成器,它以(500, 1, 12)
的形式给我数据,其中(batch size, time steps, features)
。
def batch_generator(batch_size, gen_x,gen_y):
batch_features = np.zeros((batch_size,1, 12))
batch_labels = np.zeros((batch_size,9))
while True:
for i in range(batch_size):
batch_features[i] = next(gen_x)
batch_labels[i] = next(gen_y)
yield batch_features, batch_labels
def generate_X():
while True:
with open("/my_path/my_data.csv") as f:
for line in f:
currentline = line.rstrip('\n').split(",")
currentline = np.asarray(currentline)
currentline = currentline.reshape(1,1,12)
yield currentline
def generate_y():
while True:
for i in range(len(y_train)):
y= y_train[i]
yield y
然后我尝试将其输入一维CNN中>
model = Sequential() model.add(Conv1D(filters=100, kernel_size=1, activation='relu', input_shape=(1,12), data_format="channels_last"))
但是现在我不能使用超过
kernel_size = 1
的值。这可能是因为我的时间步等于1。
如何使用整个批处理大小作为一维CNN的输入并增加kernel_size?
请问一个不清楚的问题
我有一个批处理生成器,它以(500,1,12)的形式给我数据,其中(批大小,时间步长,特征)。 def batch_generator(batch_size,gen_x,gen_y):batch_features = np.zeros((......>
请记住,当我们的每个输入样本都是序列时,即使用一维卷积,即值的顺序很重要/已指定,例如一周的股市值或一个月或一个月的天气温度值。基因组或单词的序列。话虽如此,考虑到您的数据,存在三种不同的情况:
如果csv文件中的每一行都是长度为12的序列,则您正在处理形状为(12,1)
的样本,即,在每个样本中有12个时间步长,每个时间步长仅具有特征。因此,您应该相应地调整其形状(即更改为(12,1)
而不是(1,12)
)。