如何在CNNs TensorFlow中设置网络的权重?

2024-04-26 18:22:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在以下链接中使用了卷积神经网络的以下代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/convolutional_network.py,我想为我的模型设置参数:

我的输入是35*128的数组

我设置了以下网络参数:

# Network Parameters
n_input = 35*128 
n_classes = 6 
dropout = 0.75

你能告诉我如何设置重量和偏差吗?默认值为:

# Store layers weight & bias
weights = {
    # 5x5 conv, 1 input, 32 outputs
    'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32])),
    # 5x5 conv, 32 inputs, 64 outputs
    'wc2': tf.Variable(tf.random_normal([5, 5, 32, 64])),
    # fully connected, 7*7*64 inputs, 1024 outputs
    'wd1': tf.Variable(tf.random_normal([7*7*64, 1024])),
    # 1024 inputs, 10 outputs (class prediction)
    'out': tf.Variable(tf.random_normal([1024, n_classes]))
}

biases = {
    'bc1': tf.Variable(tf.random_normal([32])),
    'bc2': tf.Variable(tf.random_normal([64])),
    'bd1': tf.Variable(tf.random_normal([1024])),
    'out': tf.Variable(tf.random_normal([n_classes]))
}

Tags: 代码input参数链接tf神经网络randomout
2条回答

我没有足够的声誉发表评论。因此,只需明确说明设置权重和偏差的确切含义。如果您想用一些条件设置的值,请参阅以下链接https://www.tensorflow.org/api_docs/python/tf/random_normal

在这里,您可以指定权重和偏差值的平均值、标准偏差和数据类型。你知道吗

最后,我通过阅读tensorflow中的以下教程找到了我的解决方案,该教程非常有用:

https://www.tensorflow.org/tutorials/layers

我的输入图像大小是35*128,我应该将密集层(“wd1”)中的参数设置为9*32*64。你知道吗

'wd1': tf.Variable(tf.random_normal([9*32*64, 1024]))

相关问题 更多 >