Keras Conv1D步骤参数

我正在建立自然网络,但我不了解Conv1D的输入范围。参数是批处理,步骤,通道,我使用的是to_categorical,因此我的数据适合此输入形状。我只是不确定我是否使用了正确的输入。当前是批处理,功能,to_categorical数组。这是正确的吗?

tickerly 回答:Keras Conv1D步骤参数

下面的示例代码应有望阐明如何使用Conv1D以及尺寸的含义。提醒一下,在Keras中,定义模型时通常不指定批次/样品尺寸。它是根据实际输入数据自动推断的。这就是为什么在定义x_train和y_train之前看不到使用“ num_samples”的原因。我希望这会有所帮助。

import tensorflow as tf
import numpy as np

num_output_units = 4
num_time_steps = 10
num_features = 6
num_samples = 20

myInput = tf.keras.layers.Input(shape=(num_time_steps,num_features))
x = tf.keras.layers.Conv1D(num_output_units,kernel_size=3,padding='same')(myInput)
final_output = tf.keras.layers.Dense(1)(x)

myModel = tf.keras.Model(inputs=myInput,outputs=final_output)

# display the model architecture
print(myModel.summary())

# Input data
x_train = np.random.random((num_samples,num_time_steps,num_features))

# Target/label data
y_train = np.random.random((num_samples,1))

myModel.compile(optimizer='rmsprop',loss='mse')

# train the model
myModel.fit(x_train,y_train,epochs=2)

myModel.predict(x_train)
本文链接:https://www.f2er.com/3150458.html

大家都在问