cnn是什么意思|CNN通俗解析( 三 )
在下面的图示中,我们有两个输入w1 = x和w2 = y,这个输入将流经图形,其中图形中的每个节点都是数学运算,为我们提供以下输出:
w3 = cos(x),余弦三角函数操作
w4 = sin(x),正弦三角函数操作
w5 = w3?w4,乘法操作
w6 = w1 / w2,除法操作
w7 = w5 + w6,加法操作

现在我们了解了什么是计算图,下面让我们TensorFlow中构建自己的计算图吧 。
代码:# Import the deep learning libraryimport tensorflow as tf# Define our compuational graph W1 = tf.constant(5.0, name = "x")W2 = tf.constant(3.0, name = "y")W3 = tf.cos(W1, name = "cos")W4 = tf.sin(W2, name = "sin")W5 = tf.multiply(W3, W4, name = "mult")W6 = tf.divide(W1, W2, name = "div")W7 = tf.add(W5, W6, name = "add")# Open the sessionwith tf.Session() as sess: cos = sess.run(W3) sin = sess.run(W4) mult = sess.run(W5) div = sess.run(W6) add = sess.run(W7) # Before running TensorBoard, make sure you have generated summary data in a log directory by creating a summary writer writer = tf.summary.FileWriter("./Desktop/ComputationGraph", sess.graph) # Once you have event files, run TensorBoard and provide the log directory # Command: tensorboard --logdir="path/to/logs"使用Tensorboard进行可视化:什么是Tensorboard?TensorBoard是一套用于检查和理解TensorFlow运行和图形的Web应用程序,这也是Google的TensorFlow比Facebook的Pytorch最大的优势之一 。

上面的代码在Tensorboard中进行可视化
在卷积神经网络、TensorFlow和TensorBoard有了深刻的理解,下面让我们一起构建我们的第一个使用MNIST数据集识别手写数字的卷积神经网络 。

MNIST数据集
我们的卷积神经网络模型将似于LeNet-5架构,由卷积层、最大池化和非线性操作层 。

卷积神经网络三维仿真
代码:
【cnn是什么意思|CNN通俗解析】
# Import the deep learning libraryimport tensorflow as tfimport time# Import the MNIST datasetfrom tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("/tmp/data/", one_hot=True)# Network inputs and outputs# The network's input is a 2828 dimensional inputn = 28m = 28num_input = n * m # MNIST data input num_classes = 10 # MNIST total classes (0-9 digits)# tf Graph inputX = tf.placeholder(tf.float32, [None, num_input])Y = tf.placeholder(tf.float32, [None, num_classes])# Storing the parameters of our LeNET-5 inspired Convolutional Neural Networkweights = { "W_ij": tf.Variable(tf.random_normal([5, 5, 1, 32])), "W_jk": tf.Variable(tf.random_normal([5, 5, 32, 64])), "W_kl": tf.Variable(tf.random_normal([7 * 7 * 64, 1024])), "W_lm": tf.Variable(tf.random_normal([1024, num_classes])) }biases = { "b_ij": tf.Variable(tf.random_normal([32])), "b_jk": tf.Variable(tf.random_normal([64])), "b_kl": tf.Variable(tf.random_normal([1024])), "b_lm": tf.Variable(tf.random_normal([num_classes])) }# The hyper-parameters of our Convolutional Neural Networklearning_rate = 1e-3num_steps = 500batch_size = 128display_step = 10def ConvolutionLayer(x, W, b, strides=1): # Convolution Layer x = t百思特网f.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding='SAME') x = tf.nn.bias_add(x, b) return xdef ReLU(x): # ReLU activation function return tf.nn.relu(x)def PoolingLayer(x, k=2, strides=2): # Max Pooling layer return tf.nn.max_pool(x, ksize=[1, k, k, 1], strides=[1, strides, strides, 1], padding='SAME')def Softmax(x): # Softmax activation function for the CNN's final output return tf.nn.softmax(x)# Create modeldef ConvolutionalNeuralNetwork(x, weights, biases): # MNIST data input is a 1-D row vector of 784 features (2828 pixels) # Reshape to match picture format [Height x Width x Channel] # Tensor input become 4-D: [Batch Size, Height, Width, Channel] x = tf.reshape(x, shape=[-1, 28, 28, 1]) # Convolution Layer Conv1 = ConvolutionLayer(x, weights["W_ij"], biases["b_ij"]) # Non-Linearity ReLU1 = ReLU(Conv1) # Max Pooling (down-sampling) Pool1 = PoolingLayer(ReLU1, k=2) # Convolution Layer Conv2 = ConvolutionLayer(Pool1, weights["W_jk"], biases["b_jk"]) # Non-Linearity ReLU2 = ReLU(Conv2) # Max Pooling (down-sampling) Pool2 = PoolingLayer(ReLU2, k=2) # Fully connected layer # Reshape conv2 output to fit fully connected layer input FC = tf.reshape(Pool2, [-1, weights["W_kl"].get_shape().as_list(百思特网)[0]]) FC = tf.add(tf.matmul(FC, weights["W_kl&q百思特网uot;]), biases["b_kl"]) FC = ReLU(FC) # Output, class prediction output = tf.add(tf.matmul(FC, weights["W_lm"]), biases["b_lm"])
- 夏至|2022夏至是什么时候几月几日
- 方言|搞耍是什么意思
- 2023|2023年闰二月是什么星座
- 保健品|磷脂酰丝氨酸是什么东西
- 南宁|2022年南宁回南天是什么时候
- 棉花娃娃|棉花娃娃有声骨架是什么材料
- 衣服|graf是什么牌子
- 衣服|714street是什么牌子
- 假燕窝|市面上的假燕窝是什么做的
- 女生|女生第一次之后还出血是什么原因
