Python 如何选择一维信号(加速度计信号)的张量形状?由于张量的形状,我一直得到Vlauer误差
我试图模拟CNN的一维信号,但我无法理解秩误差 我的程序是这样的:Python 如何选择一维信号(加速度计信号)的张量形状?由于张量的形状,我一直得到Vlauer误差,python,tensorflow,valueerror,convolutional-neural-network,Python,Tensorflow,Valueerror,Convolutional Neural Network,我试图模拟CNN的一维信号,但我无法理解秩误差 我的程序是这样的: #Weights def init_weights(shape): init_random_dist = tf.truncated_normal(shape, stddev=0.1) return tf.Variable(init_random_dist) #Bias def init_bias(shape): init_bias = tf.constant(0.1,shape=shape)
#Weights
def init_weights(shape):
init_random_dist = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(init_random_dist)
#Bias
def init_bias(shape):
init_bias = tf.constant(0.1,shape=shape)
return tf.Variable(init_bias)
def conv1d(x,W):
#x is input accelration data and W is corresponding weight
x = tf.cast(x, tf.float32)
tf.nn.conv1d(x,W,stride=1,padding='VALID')
def convolution_layer(input_x,shape):
w = init_weights(shape)
b = init_bias([shape[3]])
return tf.nn.relu(conv1d(input_x,w)+b)
现在是占位符
x=tf.placeholdertf.float32,shape=[1,1200,1]
y_true=tf.placeholdertf.float32,shape=[None,6]
当使用con_layer_1=卷积_layerx,shape=[1,20,1,32]创建第一层时,我得到的秩值误差无法消除。错误语句是:
ValueError:对于输入形状为[1,1,1200,1],[1,1,20,1,32]的“conv1d_20/Conv2D”op:“Conv2D”,形状必须为第4级,但为第5级。nn.conv1d的输入和权重形状不正确。nn.conv1d的输入形状大小应为:[批次大小、输入长度、输入通道],权重矩阵大小应为[过滤器大小、输入通道、输出通道]。因此,您需要将代码更改为:
def convolution_layer(input_x,shape):
w = init_weights(shape)
b = init_bias([shape[2]])
return tf.nn.relu(conv1d(input_x,w)+b)
x = tf.placeholder(tf.float32,shape=[1,200,1])
y_true = tf.placeholder(tf.float32,shape=[None,6])
con_layer_1 = convolution_layer(x,shape=[20,1,32])
注意:您应该尝试使用tf.layers API来处理权重分配和所有这些