-
在卷积层中调用模型文件
from mnist import model data = read_data_sets('MNIST_data', one_hot=True) with tf.variable_scope('convolutional'): x = tf.placeholder(tf.float32, [None, 784]) keep_prob = tf.placeholder(tf.float32) y, variables = model.convolutional(x,keep_prob) _y = tf.placeholder(tf.float32, [None, 10]) cross_entropy = -tf.reduce_sum(_y * tf.log(y)) train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(_y, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) saver=tf.train.Saver(variables) with tf.Session() as sess: merged_summary_op = tf.summary.merge_all() summary_writer = tf.summary.FileWriter('/tmp/mnist_log/1', sess.graph) summary_writer.add_graph(sess.graph)
查看全部 -
完成剩余的卷积神经网络模型
W_conv2 = weight_variable([5, 5, 32, 64]) b_conv2 = bias_variable([64]) h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2) h_pool2 = max_pool_2x2(h_conv2) W_fc1 = weight_variable([7 * 7 * 64, 1024]) b_fc1 = bias_variable([1024]) h_pool2_flat = tf.reshape(h_pool2, [-1, 7 * 7 * 64]) h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1) h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob) W_fc2 = weight_variable([1024, 10]) b_fc2 = bias_variable([10]) y = tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) return y, [W_conv1, b_conv1, W_conv2, b_conv2, W_fc1, b_fc1, W_fc2, b_fc2]
查看全部 -
简单构建cnn的网络
def convolutional(x, keep_prob): def conv2d(x, W): return tf.nn.conv2d([1, 1, 1, 1], padding='SAME') def max_pool_2x2(x): return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME') def weight_variable(shape): initial = tf.truncated_normal(shape, stddev=0.1) return tf.Variable(initial) def bias_variable(shape): initial = tf.constant(0.1, shape=shape) return tf.Variable(initial) x_image = tf.reshape(x, [-1, 28, 28, 1]) W_conb1 = weight_variable([5, 5, 1, 32]) b_conv1 = bias_variable([32]) h_conv1 = tf.nn.relu(conv2d(x_image, W_conb1) + b_conv1) h_pool1 = max_pool_2x2(h_conv1)
查看全部 -
完成线性模型的构建
import tensorflow as tf import os from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets from mnist import model data = read_data_sets('MNIST_data', one_hot=True) with tf.variable_scope('regression'): x = tf.placeholder(tf.float32, [None, 784]) y, variables = model.regression(x) _y = tf.placeholder('float', [None, 10]) cross_entropy = -tf.reduce_sum(_y * tf.log(y)) train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(_y, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) saver=tf.train.Saver(variables) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) for _ in range(1000): batch_xs,batch_ys=data.train.next_batch(100) sess.run(train_step,feed_dict={x:batch_xs,_y:batch_ys}) print(sess.run(accuracy,feed_dict={x:data.test.images,_y:data.test.labels})) path=saver.save(sess,os.path.join(os.path.dirname(__file__),'data','regression.ckpt'),write_meta_graph=False,write_state=False) print('Saver:'+path)
最终保存了训练好的模型
查看全部 -
进行模型的构建
先是线性模型
import tensorflow as tf from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets from mnist import model data = read_data_sets('MNIST_data', one_hot=True) with tf.variable_scope('regression'): x = tf.placeholder(tf.float32, [None, 784]) y, variables = model.regression(x) _y = tf.placeholder('float', [None, 10]) cross_entropy = -tf.reduce_sum(_y * tf.log(y)) train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(_y, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
查看全部 -
使用tensorflow提供的函数来
下载官方的mnist数据集
查看全部 -
flask一种轻量的web框架
训练好模型
使用flask来调用模型
查看全部 -
mnist数据集是手写数字数据集
包含0到9的手写数字图片
可以用来训练深度学习网络
查看全部 -
tensorflow是一个深度学习库
支持cnn rnn lstm等
可以实现语音识别和图像识别
查看全部 -
将人工智能与现有的技术相结合
可以进一步提高使用体验
tensorflow与flask结合
查看全部 -
MNIST
查看全部 -
整合步骤。
查看全部 -
MNIST查看全部
-
MNIST
查看全部 -
TensorFlow
查看全部
举报
0/150
提交
取消