如何确定简单卷积神经网络的参数

2024-04-24 17:05:30 发布

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

我想用我自己的数据集训练CNN(这不是用于图像分类),但是我是CNN新手,示例代码中的参数真的让我困惑。我试图改变参数,但失败了。在

我的训练数据中的每个样本是205*8=1640(8行x 205列), 我只有两个类(目标和非目标)。在

但我不知道如何设置下面代码的参数以适应我的数据集。在

这是源代码的一部分(我借用了它)

此代码用于将28*28分钟的图像分为10类

n_classes = 2
batch_size = 128

x = tf.placeholder('float', [None, 1640])
y = tf.placeholder('float')

def conv2d(x, W):
    return tf.nn.conv2d(x, W, strides=[1,1,1,1], padding='SAME')

def maxpool2d(x):
#                           size of window      movement of window
    return tf.nn.max_pool(x, ksize=[1,2,2,1], strides=[1,2,2,1], padding='SAME')

def convolutional_neural_network(x):
    weights = {'W_Conv1': tf.Variable(tf.random_normal([5, 5, 1, 32])),
               'W_Conv2': tf.Variable(tf.random_normal([5, 5, 32, 64])),
               'W_fc': tf.Variable(tf.random_normal([7*7*64, 1024])),
               'out': tf.Variable(tf.random_normal([1024, n_classes]))}

    biases = {'b_Conv1': tf.Variable(tf.random_normal([32])),
              'b_Conv2': tf.Variable(tf.random_normal([64])),
              'b_fc': tf.Variable(tf.random_normal([64])),
              'out': tf.Variable(tf.random_normal([n_classes]))}

x = tf.reshape(x, shape=[-1, 28, 28, 1])

conv1 = conv2d(x, weights['W_Conv1'])
conv1 = maxpool2d(conv1)

conv2 = conv2d(conv1, weights['W_Conv2'])
conv2 = maxpool2d(conv2)

fc = tf.reshape(conv2, [-1, 7*7*64])
fc = tf.nn.relu(tf.matmul(fc, weights['W_fc']) + biases['b_fc'])

output = tf.matmul(fc, weights['out']) + biases['out']

return output

Tags: 数据代码参数tfdefrandomoutvariable