python - 如何为 1D CNN 格式化 1D 数组数据

标签 python machine-learning deep-learning neural-network conv-neural-network

我想知道如何将我的数据(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/

相关文章:

algorithm - 随机投影算法伪代码

machine-learning - 在 GraphLab Sframe 中过滤和显示值?

machine-learning - 理解论文中关于 VGGNet 的一段话

deep-learning - pytorch - loss.backward() 和 optimizer.step() 在 eval 模式下与批量规范层?

python - 什么是 python 的 useAutomationExtension for selenium?

python mechanize.Browser 返回

python - df.duplicated() 误报?

python - 用于分类功能的LabelEncoder?

python - 如何在pytorch中测试一张图片

python - 使用 Python 通过 Mailgun 提交变量时出错