[英]Understanding the keras input_shape for Conv1D, Dense layers (1-dimensional input)
Folks!伙计们!
I try to implement my first own dl-net in keras
which will be an auto-encoder (hopefully de-noising and stacked).我尝试在
keras
中实现我的第一个自己的 dl-net,这将是一个自动编码器(希望去噪和堆叠)。 But I struggle with the input shape format of my input layer, which can be an Conv1D
or Dense
Layer (currently it's a Dense
layer because I hoped that will fix the problem) - I also tried pytorch
but this did not solve my issue either.但是我对输入层的输入形状格式感到困惑,它可以是
Conv1D
或Dense
层(目前它是Dense
层,因为我希望它能解决问题) - 我也尝试pytorch
但这也没有解决我的问题。
The underlying problem is that I feel as I don't get the input shape argument and its structure.根本问题是我觉得我没有得到输入形状参数及其结构。 For images you find great and logical explanations all over the internet.
对于图像,您可以在互联网上找到很好且合乎逻辑的解释。 But as I use 1-dimensional data , these techniques could not applied here - also the
Dense
/ Conv1D
API do not answer my question properly.但是由于我使用一维数据,这些技术不能在这里应用 -
Dense
/ Conv1D
API 也不能正确回答我的问题。
I have 7000 samples where each is represented by a 1-D array of 500 integers , thats is no additional feature dimensions or properties - just one channel if i understood correctly.我有7000 个样本,其中每个样本由500 个整数的一维数组表示,这不是额外的特征维度或属性 - 如果我理解正确,只有一个通道。 Therefore
input_shape=(,500)
should work fine as i don't have to state the batch size .因此
input_shape=(,500)
应该可以正常工作,因为我不必 state批量大小。 But it does not work, I just get the message that my incoming data and the shape mismatch.但它不起作用,我只是收到我传入的数据和形状不匹配的消息。
Maybe someone can clear that up?也许有人可以清除它? Maybe my input data is shaped incorrect - how should the numpy input look like?
也许我的输入数据形状不正确- numpy 输入应该是什么样子? Or is my layer misconfigured ?
还是我的图层配置错误?
Thank you in advance.先感谢您。 I really tried to wrap my head around this and already tried several reshaping or input shape definitions - unfortunately nothing worked.
我真的试图解决这个问题,并且已经尝试了几个重塑或输入形状定义 - 不幸的是,没有任何效果。
You just forgot about "channels" dimension.您只是忘记了“渠道”维度。 Like an image, a sequence can also have channels.
像图像一样,序列也可以有通道。
For example you can run the following code:例如,您可以运行以下代码:
import tensorflow as tf
layer = tf.keras.layers.Conv1D(input_shape=(500,), kernel_size=3, filters=2)
sample = tf.ones((1, 500, 1), dtype=tf.float32) # (bs, input_shape, channels)
out = layer(sample) # out.shape will be (1, 498, 2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.