[AI教程]TensorFlow入门:使用卷积网络模型实现手势识别

本文提供了一篇关于使用TensorFlow 1.9.0和Python 3.6.3搭建卷积网络模型进行手势识别的教程。通过SIGNS数据集,介绍数据准备、参数初始化、前向传播、代价函数和模型构建的过程,展示了训练过程中的成本变化。
摘要由CSDN通过智能技术生成

介绍

本文介绍了搭建简单的卷积网络模型进行手势数字识别
数据集:https://github.com/stormstone/deeplearning.ai/tree/c38b8ea7cc7fef5caf88be6e06f4e3452690fde7
工具:TensorFlow 1.9.0 + Python 3.6.3

1.相关包导入

// An highlighted block
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 *
%matplotlib inline
np.random.seed(1)

2.数据准备

本实验使用SIGNS数据集是6个符号的集合,表示从0到5的数字。
训练集:1080个图像(64乘64像素)的符号表示从0到5的数字(每个数字180个图像)。
测试集:120张图片(64乘64像素)的符号,表示从0到5的数字(每个数字20张图片)。

2.1数据实例

下面将显示数据集中标记图像的示例。 随意更改下面的index的值,然后重新运行以查看不同的示例。

index = 6
plt.imshow(X_train_orig[index])
print ("y = " + str(np.squeeze(Y_train_orig[:, index])))

y = 2
在这里插入图片描述

2.2数据检查

X_train = X_train_orig/255.
X_test = X_test_orig/255.
Y_train = convert_to_one_hot(Y_train_orig, 6).T
Y_test = convert_to_one_hot(Y_test_orig, 6).T
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 = {
   }

运行结果:
number of training examples = 1080
number of test examples = 120
X_train shape: (1080, 64, 64, 3)
Y_train shape: (1080, 6)
X_test shape: (120, 64, 64, 3)
Y_test shape: (120, 6)

3.参数初始化

# GRADED FUNCTION: initialize_parameters

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)                              # so that your "random" numbers match ours
        
    ### START CODE HERE ### (approx. 2 lines of code)
    W1 = tf.get_variable("W1", [4,4,3,8], initializer = tf.contrib.layers.xavier_initializer(seed = 0))
    W2 = tf.get_variable(&#
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值