• 大小: 133KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-05-14
  • 语言: Python
  • 标签:

资源简介

手势识别使用在TensorFlow中卷积神经网络实现

资源截图

代码片段和文件信息

# The architecture is inspired by LeNet-5 (LeCun 1998)
import os

import tensorflow as tf

# Parameter
IMAGE_HEIGHT = 240
IMAGE_WIDTH = 320
BATCH_SIZE = 5
NUM_EPOCHS = 2
NUM_CLASS = 5
NUM_CHANNELS = 3
CONV1_FILTER_SIZE  = 32
CONV1_FILTER_COUNT  = 4
CONV2_FILTER_SIZE  = 16
CONV2_FILTER_COUNT  = 6
HIDDEN_layer_SIZE = 400

def read_images(data_dir):
    pattern = os.path.join(data_dir ‘*.png‘)
    filenames = tf.train.match_filenames_once(pattern name=‘list_files‘)
    
    queue = tf.train.string_input_producer(
        filenames 
        num_epochs=NUM_EPOCHS 
        shuffle=True 
        name=‘queue‘)
    
    reader = tf.WholeFileReader()
    filename content = reader.read(queue name=‘read_image‘)
    filename = tf.Print(
        filename 
        data=[filename]
        message=‘loading: ‘)
    filename_split = tf.string_split([filename] delimiter=‘/‘)
    label_id = tf.string_to_number(tf.substr(filename_split.values[1] 
        0 1) out_type=tf.int32)
    label = tf.one_hot(
        label_id-1 
        5 
        on_value=1.0 
        off_value=0.0 
        dtype=tf.float32)

    img_tensor = tf.image.decode_png(
        content 
        dtype=tf.uint8 
        channels=3
        name=‘img_decode‘)

    # Preprocess the image Performs random transformations
    # Random flip
    img_tensor_flip = tf.image.random_flip_left_right(img_tensor)

    # Random brightness
    img_tensor_bri = tf.image.random_brightness(img_tensor_flip 
        max_delta=0.2)

    # Per-image scaling
    img_tensor_std = tf.image.per_image_standardization(img_tensor_bri)

    min_after_dequeue = 1000
    capacity = min_after_dequeue + 3 * BATCH_SIZE
    example_batch label_batch = tf.train.shuffle_batch(
        [img_tensor_std label] 
        batch_size=BATCH_SIZE
        shapes=[(IMAGE_HEIGHT IMAGE_WIDTH NUM_CHANNELS) (NUM_CLASS)]
        capacity=capacity 
        min_after_dequeue=min_after_dequeue
        name=‘train_shuffle‘)

    return example_batch label_batch

# ‘images‘ is a 4-D tensor with the shape:
# [n_batch img_height img_width n_channel]
def inference(images):
    # Convolutional layer 1
    with tf.name_scope(‘conv1‘):
        W = tf.Variable(
            tf.truncated_normal(
                shape=(
                    CONV1_FILTER_SIZE 
                    CONV1_FILTER_SIZE
                    NUM_CHANNELS
                    CONV1_FILTER_COUNT)
                dtype=tf.float32
                stddev=5e-2) 
            name=‘weights‘)
        b = tf.Variable(
            tf.zeros(
                shape=(CONV1_FILTER_COUNT) 
                dtype=tf.float32) 
            name=‘biases‘)
        conv = tf.nn.conv2d(
            input=images 
            filter=W
            strides=(1 1 1 1) 
            padding=‘SAME‘
            name=‘convolutional‘)
        conv_bias = tf.nn.bias_add(conv b)
        conv_act = tf.nn.relu(
            features=conv_bias 
            name=‘activation‘)
        poo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-02-25 07:21  hsr-master\
     文件         569  2017-02-25 07:21  hsr-master\README.md
     文件      138259  2017-02-25 07:21  hsr-master\hsr-eval.png
     文件        6113  2017-02-25 07:21  hsr-master\hsr.py
     文件        2129  2017-02-25 07:21  hsr-master\train.py

评论

共有 条评论