资源简介
CNN卷积神经网络,包含数据,代码有标注,可以用来参考学习
代码片段和文件信息
# Lab 11 MNIST and Convolutional Neural Network
import tensorflow as tf
import random
import scipy.io as scio
# import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
tf.set_random_seed(777) # reproducibility
mnist = input_data.read_data_sets(“MNIST_data/“ one_hot=True)
# Check out https://www.tensorflow.org/get_started/mnist/beginners for
# more information about the mnist dataset
# hyper parameters
learning_rate = 0.002
training_epochs = 3
batch_size = 50
# input place holders
X = tf.placeholder(tf.float32 [None 784])
X_img = tf.reshape(X [-1 28 28 1]) # img 28x28x1 (black/white)
Y = tf.placeholder(tf.float32 [None 10])
# L1 ImgIn shape=(? 28 28 1)
W1 = tf.Variable(tf.random_normal([5 5 1 6] stddev=0.01))
b1 = tf.Variable(tf.random_normal([6]))
# Conv -> (? 24 24 6)
# Pool -> (? 12 12 6)
L1 = tf.nn.conv2d(X_img W1 strides=[1 1 1 1] padding=‘VALID‘)
L1 = tf.nn.relu(L1 + b1)
L1 = tf.nn.avg_pool(L1 ksize=[1 2 2 1]
strides=[1 2 2 1] padding=‘SAME‘)
‘‘‘
Tensor(“Conv2D:0“ shape=(? 24 24 6) dtype=float32)
Tensor(“Relu:0“ shape=(? 24 24 6) dtype=float32)
Tensor(“avgPool:0“ shape=(? 12 12 6) dtype=float32)
‘‘‘
# L2 ImgIn shape=(? 12 12 6)
W2 = tf.Variable(tf.random_normal([5 5 6 16] stddev=0.01))
b2 = tf.Variable(tf.random_normal([16]))
# Conv ->(? 8 8 16)
# Pool ->(? 4 4 16)
L2 = tf.nn.conv2d(L1 W2 strides=[1 1 1 1] padding=‘VALID‘)
L2 = tf.nn.relu(L2 + b2)
L2 = tf.nn.avg_pool(L2 ksize=[1 2 2 1]
strides=[1 2 2 1] padding=‘SAME‘)
L2_flat = tf.reshape(L2 [-1 4 * 4 * 16])
#L2_flat = tf.nn.relu(L2_flat)
‘‘‘
Tensor(“Conv2D_1:0“ shape=(? 14 14 64) dtype=float32)
Tensor(“Relu_1:0“ shape=(? 14 14 64) dtype=float32)
Tensor(“MaxPool_1:0“ shape=(? 7 7 64) dtype=float32)
Tensor(“Reshape_1:0“ shape=(? 3136) dtype=float32)
‘‘‘
# Final FC 7x7x64 inputs -> 10 outputs
W3 = tf.Variable(tf.random_normal([4*4*16 10] stddev=0.01))
#W3 = tf.get_variable(“W3“ shape=[4 * 4 * 16 10]
# initializer=tf.contrib.layers.xavier_initializer())
b3 = tf.Variable(tf.random_normal([10]))
logits = tf.matmul(L2_flat W3) + b3
#logits = tf.nn.relu(logits)
# define cost/loss & optimizer
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(
logits=logits labels=Y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
#creat a saver
saver = tf.train.Saver()
# initialize
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
# train my model
print(‘Learning started. It takes sometime.‘)
for epoch in range(training_epochs):
avg_cost = 0
total_batch = int(mnist.train.num_examples / batch_size)
for i in range(total_batch):
batch_xs batch_ys = mnist.train.next_batch(batc
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-10-26 18:53 MNIST_data\
文件 9912422 2018-10-26 18:52 MNIST_data\train-images-idx3-ubyte.gz
文件 4289 2018-10-09 10:33 convolutional_network.py
文件 7005 2018-10-26 18:49 CNN_TEST.py
相关资源
- 基于CNN的图像搜索demo
- python实现的卷积神经网络CNN无框架
- 机器学习对应的相关python代码SVM、C
- 基于 CNN 的疲劳检测源码-Python
- CNN网络代码,数据集,及对应论文和
- Faster-RCNN-TensorFlow-Python3.5-master
- MTCNN源码python版
- keras实现中文文本分类
- pytorch版本手写体识别MNIST.zip
- Mask R-CNN源码(TensorFlow版本)
- TensorflowOpenCV实现的CNN车牌识别代码
- 文本分类代码集合含数据_TextCNN_Text
- python实现CNN中文文本分类
- Deep learning with Python Francois Chollet
- 基于卷积神经网络的手势识别
- CNN用于图像分类以外的数字序列.rar
- DnCNN tensorflow实现
- Python-Tensorflow实现SpatialAsDeepSpatialCNN
- CNN+pythoncode8.18.zip
- 肺结节识别采用CNN
- RNN python
- 车牌识别Tensorflow_CNN_python_opencv.zip
- cifar-10 90%+代码
- 深度学习testCNN的python实现
- labelme标注数据集到COCO格式数据集转化
- 指静脉识别,keras,CNN
- python3使用tensorflow构建CNN卷积神经网络
- CNN卷积神经网络python代码
- Attention-CNN(Jianlong-Fu 大神制作)
- 基于卷积神经网络的手写数字识别
评论
共有 条评论