资源简介
多层感知机python代码,属于深度网络学习中的内容,multilayer-perceptron,python代码
代码片段和文件信息
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets(“.“ one_hot=True reshape=False)
import tensorflow as tf
# Parameters
learning_rate = 0.001
training_epochs = 20
batch_size = 128 # Decrease batch size if you don‘t have enough memory
display_step = 1
n_input = 784 # MNIST data input (img shape: 28*28)
n_classes = 10 # MNIST total classes (0-9 digits)
n_hidden_layer = 256 # layer number of features
# Store layers weight & bias
weights = {
‘hidden_layer‘: tf.Variable(tf.random_normal([n_input n_hidden_layer]))
‘out‘: tf.Variable(tf.random_normal([n_hidden_layer n_classes]))
}
biases = {
‘hidden_layer‘: tf.Variable(tf.random_normal([n_hidden_layer]))
‘out‘: tf.Variable(tf.random_normal([n_classes]))
}
# tf Graph input
x = tf.placeholder(“float“ [None 28 28 1])
y = tf.placeholder(“float“ [None n_classes])
x_flat = tf.reshape(x [-1 n_input])
# Hidden layer with RELU activation
layer_1 = tf.add(tf.matmul(x_flat weights[‘hidden_layer‘]) biases[‘hidden_layer‘])
layer_1 = tf.nn.relu(layer_1)
# Output layer with linear activation
logits = tf.matmul(layer_1 weights[‘out‘]) + biases[‘out‘]
# Define loss and optimizer
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits y))
optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate).minimize(cost)
# Initializing the variables
init = tf.initialize_all_variables()
# Launch the graph
with tf.Session() as sess:
sess.run(init)
# Training cycle
for epoch in range(training_epochs):
total_batch = int(mnist.train.num_examples/batch_size)
# Loop over all batches
for i in range(total_batch):
batch_x batch_y = mnist.train.next_batch(batch_size)
# Run optimization op (backprop) and cost op (to get loss value)
sess.run(optimizer feed_dict={x: batch_x y: batch_y})
# Display logs per epoch step
if epoch % display_step == 0:
c = sess.run(cost feed_dict={x: batch_x y: batch_y})
print(“Epoch:“ ‘%04d‘ % (epoch+1) “cost=“ \
“{:.9f}“.format(c))
print(“Optimization Finished!“)
# Test model
correct_prediction = tf.equal(tf.argmax(logits 1) tf.argmax(y 1))
# Calculate accuracy
accuracy = tf.reduce_mean(tf.cast(correct_prediction “float“))
# Decrease test_size if you don‘t have enough memory
test_size = 256
print(“Accuracy:“ accuracy.eval({x: mnist.test.images[:test_size] y: mnist.test.labels[:test_size]}))
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-01-03 11:28 multil
文件 6148 2017-01-03 11:28 multil
目录 0 2017-01-03 11:28 __MACOSX\
目录 0 2017-01-03 11:28 __MACOSX\multil
文件 120 2017-01-03 11:28 __MACOSX\multil
文件 1386 2016-10-25 19:49 multil
文件 226 2016-10-25 19:49 __MACOSX\multil
文件 2555 2017-01-03 11:26 multil
文件 226 2017-01-03 11:28 __MACOSX\._multil
相关资源
- Deep Learning Cookbook_ practical recipes to g
- 深度学习视频中的行为识别
- deep learning with python 中文版
- 吴恩达深度学习超参数调制完整程序
- 深度学习入门 基于python理论与实现
- Python-基于深度学习的语音增强使用
- 《深度学习Deep Learning with Python 2017》
- 深度学习进阶:自然语言处理
- 基于深度学习堆栈自动编码器模型的
- 深度学习入门:基于python的理论与实
- 吴恩达深度学习1-21-31-42-1编程作业线
- 基于Python的深度学习
- 安全帽检测detect.7z
- deep_learning_with_python.pdf(Jason Brownlee)
- 人脸识别python代码187268
- Make Your Own Neural Network - 搭建自己的神
- BrownLee Better Deep Learning
- python 直方图规定化代码
- 简单粗暴 TensorFlow
- 5. 深度学习中的目标检测 python代码实
- 深度学习入门:基于Python的理论与实
- Deep Learning from Scratch中文名:深度学习
- Deep Learning for Natural Language Processing.
- 字符型图片数字验证码识别完整过程
- Python深度学习122512
- 基于Tensorflow的人脸识别源码
- 中文情感分析python程序
- 基于深度学习Superpoint 的Python图像全景
- 《深度学习入门:基于Python的理论与
- Machine Learning with Python Cookbook.pdf
评论
共有 条评论