资源简介
tensorflow框架下构建训练一个简单的3层卷积神经网络实现分类问题
代码片段和文件信息
import math
import numpy as np
import h5py
import matplotlib.pyplot as plt
import scipy
from PIL import Image
from scipy import ndimage
import tensorflow as tf
from tensorflow.python.framework import ops
from cnn_utils import *
import scipy.misc as misc
get_ipython().magic(‘matplotlib inline‘)
np.random.seed(1)
X_train_orig Y_train_orig X_test_orig Y_test_orig classes = load_dataset()
index = 6
plt.imshow(X_train_orig[index])
print (“y = “ + str(np.squeeze(Y_train_orig[: index])))
print (“X: “ + str(X_train_orig[0]))
print (“Y: “ + str(Y_train_orig[0]))
X_train = X_train_orig/255.
X_test = X_test_orig/255.
print (“X: “ + str(X_train[1]))
Y_train = convert_to_one_hot(Y_train_orig 6).T
Y_test = convert_to_one_hot(Y_test_orig 6).T
print (“Y: “ + str(Y_train[1]))
print (“number of training examples = “ + str(X_train.shape[0]))
print (“number of test examples = “ + str(X_test.shape[0]))
print (“X_train shape: “ + str(X_train.shape))
print (“Y_train shape: “ + str(Y_train.shape))
print (“X_test shape: “ + str(X_test.shape))
print (“Y_test shape: “ + str(Y_test.shape))
conv_layers = {}
def create_placeholders(n_H0 n_W0 n_C0 n_y):
“““
Creates the placeholders for the tensorflow session.
Arguments:
n_H0 -- scalar height of an input image
n_W0 -- scalar width of an input image
n_C0 -- scalar number of channels of the input
n_y -- scalar number of classes
Returns:
X -- placeholder for the data input of shape [None n_H0 n_W0 n_C0] and dtype “float“
Y -- placeholder for the input labels of shape [None n_y] and dtype “float“
“““
X = tf.placeholder(dtype = tf.float32shape = [None n_H0 n_W0 n_C0])
Y = tf.placeholder(dtype = tf.float32shape = [None n_y])
return X Y
X Y = create_placeholders(64 64 3 6)
print (“X = “ + str(X))
print (“Y = “ + str(Y))
def initialize_parameters():
“““
Initializes weight parameters to build a neural network with tensorflow. The shapes are:
W1 : [4 4 3 8]
W2 : [2 2 8 16]
Returns:
parameters -- a dictionary of tensors containing W1 W2
“““
tf.set_random_seed(1)
W1 = tf.get_variable(“W1“ [4438] initializer = tf.contrib.layers.xavier_initializer(seed = 0))
W2 = tf.get_variable(“W2“ [22816] initializer = tf.contrib.layers.xavier_initializer(seed = 0))
parameters = {“W1“: W1
“W2“: W2}
return parameters
tf.reset_default_graph()
with tf.Session() as sess_test:
parameters = initialize_parameters()
init = tf.global_variables_initializer()
sess_test.run(init)
print(“W1 = “ + str(parameters[“W1“].eval()[111]))
print(“W2 = “ + str(parameters[“W2“].eval()[111]))
def forward_propagation(X parameters):
“““
Implements the forward propagation for the model:
CONV2D -> RELU -> MAXPOOL -> CONV2D -> RELU -> MAXPOOL -> FLATTEN -> FULLYCONNECTED
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 48943 2018-12-23 14:23 TensorFlow入门:使用卷积网络模型实现手势识别\.ipynb_checkpoints\Convolution+model+-+Application+-+v1-checkpoint.ipynb
文件 9542 2018-12-23 15:09 TensorFlow入门:使用卷积网络模型实现手势识别\cnn.py
文件 5635 2018-08-15 08:14 TensorFlow入门:使用卷积网络模型实现手势识别\cnn_utils.py
文件 20 2018-08-15 08:14 TensorFlow入门:使用卷积网络模型实现手势识别\datasets\README.md
文件 1477712 2018-08-15 08:14 TensorFlow入门:使用卷积网络模型实现手势识别\datasets\test_signs.h5
文件 13281872 2018-08-15 08:14 TensorFlow入门:使用卷积网络模型实现手势识别\datasets\train_signs.h5
文件 205 2018-08-15 08:14 TensorFlow入门:使用卷积网络模型实现手势识别\README.md
文件 3652 2018-12-23 14:21 TensorFlow入门:使用卷积网络模型实现手势识别\__pycache__\cnn_utils.cpython-36.pyc
目录 0 2018-12-24 09:32 TensorFlow入门:使用卷积网络模型实现手势识别\.ipynb_checkpoints
目录 0 2018-12-24 09:32 TensorFlow入门:使用卷积网络模型实现手势识别\datasets
目录 0 2018-12-24 09:32 TensorFlow入门:使用卷积网络模型实现手势识别\__pycache__
目录 0 2018-12-24 09:32 TensorFlow入门:使用卷积网络模型实现手势识别
----------- --------- ---------- ----- ----
14827581 12
评论
共有 条评论