【问题标题】:Keras Conv1D steps parameterKeras Conv1D 步骤参数
【发布时间】:2019-11-06 16:32:31
【问题描述】:

我正在构建一个自然网络,但我不了解 Conv1D 的输入维度。参数是批处理、步骤、通道,我使用的是 to_categorical,所以我的数据适合这个输入形状。我只是不确定我是否使用了正确的输入。它目前是批处理、功能、to_categorical 数组。这是正确的吗?

【问题讨论】:

    标签: python machine-learning keras keras-layer


    【解决方案1】:

    下面的示例代码有望阐明如何使用 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, num_time_steps, 1))
    
    myModel.compile(optimizer='rmsprop', loss='mse')
    
    # train the model
    myModel.fit(x_train, y_train, epochs=2)
    
    myModel.predict(x_train)
    

    【讨论】:

    • 这很有用,我的主要问题是如果使用 2x2 数据帧,time_steps 将在哪里定义?它有行和列,那么额外的维度来自哪里?
    猜你喜欢
    • 1970-01-01
    • 2019-02-27
    • 2019-01-03
    • 2021-12-31
    • 2019-01-31
    • 1970-01-01
    • 2022-01-21
    • 2022-07-11
    • 2021-03-09
    相关资源
    最近更新 更多