用python写神经网络_在3分钟内:用Python编写你的第一个神经网络

def neural_network_model(data):

#Define weights and biases with their dimensions

hidden_1_layer = {'weights' : tf.Variable(tf.random_normal([784,n_nodes_hl1])),

'biases' : tf.Variable(tf.random_normal([n_nodes_hl1]))}

#bias is used to make some neurons fire even if all inputs is 0

hidden_2_layer = {'weights' : tf.Variable(tf.random_normal([n_nodes_hl1,n_nodes_hl2])),

'biases' : tf.Variable(tf.random_normal([n_nodes_hl2]))}

hidden_3_layer = {'weights' : tf.Variable(tf.random_normal([n_nodes_hl2,n_nodes_hl3])),

'biases' : tf.Variable(tf.random_normal([n_nodes_hl3]))}

output_layer = {'weights' : tf.Variable(tf.random_normal([n_nodes_hl3,n_classes])),

'biases' : tf.Variable(tf.random_normal([n_classes]))}

# Layer values =(input_data*weights) + biases

l1 = tf.add(tf.matmul(data,hidden_1_layer['weights']),hidden_1_layer['biases'])

l1 = tf.nn.relu(l1)

l2 = tf.add(tf.matmul(l1,hidden_2_layer['weights']),hidden_2_layer['biases'])

l2 = tf.nn.relu(l2)

l3 = tf.add(tf.matmul(l2,hidden_3_layer['weights']),hidden_3_layer['biases'])

l3 = tf.nn.relu(l3)

output = tf.matmul(l3,output_layer['weights'])+ output_layer['biases']

return output

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值