资源简介
使用tensorflow,OpenCV Keras,matplotlib完成的一个小demo
基本操作如下
1 执行liveplot.py
2 执行trackgesture.py后, 在终端命令行输入1进行手势预测,调用摄像头后,请按键盘b 和g键
此时就可以进行预测了。
权重文件:链接:https://pan.baidu.com/s/1i6OE5A9 密码:by24
代码片段和文件信息
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
“““
Created on Thu Apr 6 01:01:43 2017
@author: abhisheksingh
“““
import pandas as pd
from keras.models import Sequential
from keras.layers import Dense Dropout Activation Flatten
from keras.layers import Conv2D MaxPooling2D ZeroPadding2D
from keras.optimizers import SGD RMSprop adam
from keras.utils import np_utils
# We require this for Theano lib ONLY. Remove it for TensorFlow usage
from keras import backend as K
K.set_image_dim_ordering(‘th‘)
import numpy as np
# import matplotlib.pyplot as plt
import os
import theano
from PIL import Image
# SKLEARN
from sklearn.utils import shuffle
from sklearn.model_selection import train_test_split
import json
import cv2
import matplotlib
# matplotlib.use(“TkAgg“)
from matplotlib import pyplot as plt
# input image dimensions
img_rows img_cols = 200 200
# number of channels
# For grayscale use 1 value and for color images use 3 (RGB channels)
img_channels = 1
# Batch_size to train
batch_size = 32
## Number of output classes (change it accordingly)
## eg: In my case I wanted to predict 4 types of gestures (Ok Peace Punch Stop)
## NOTE: If you change this then dont forget to change Labels accordingly
nb_classes = 5
# Number of epochs to train (change it accordingly)
nb_epoch = 15 # 25
# Total number of convolutional filters to use
nb_filters = 32
# Max pooling
nb_pool = 2
# Size of convolution kernel
nb_conv = 3
# %%
# data
path = “./“
path1 = “./gestures“ # path of folder of images
## Path2 is the folder which is fed in to training model
path2 = ‘./imgfolder_b‘
WeightFileName = [“ori_4015imgs_weights.hdf5“ “bw_4015imgs_weights.hdf5“ “bw_2510imgs_weights.hdf5“
“./bw_weight.hdf5“ “./final_c_weights.hdf5“ “./semiVgg_1_weights.hdf5“ “/new_wt_dropout20.hdf5“
“./weights-CNN-gesture_skinmask.hdf5“]
# outputs
output = [“OK“ “NOTHING“ “PEACE“ “PUNCH“ “STOP“]
# output = [“PEACE“ “STOP“ “THUMBSDOWN“ “THUMBSUP“]
# %%
# This function can be used for converting colored img to Grayscale img
# while copying images from path1 to path2
def convertToGrayImg(path1 path2):
listing = os.listdir(path1)
for file in listing:
if file.startswith(‘.‘):
continue
img = Image.open(path1 + ‘/‘ + file)
# img = img.resize((img_rowsimg_cols))
grayimg = img.convert(‘L‘)
grayimg.save(path2 + ‘/‘ + file “PNG“)
# %%
def modlistdir(path):
listing = os.listdir(path)
retlist = []
for name in listing:
# This check is to ignore any hidden files/folders
if name.startswith(‘.‘):
continue
retlist.append(name)
return retlist
# Load CNN model
def loadCNN(wf_index):
global get_output
model = Sequential()
model.add(Conv2D(nb_filters (nb_conv nb_conv)
padding=‘valid‘
input_shape=(img_channels img_rows img_cols)))
convout1 = Activation(‘relu‘)
m
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6148 2018-01-29 08:52 sss\CNNGestureRecognizer-master\.DS_Store
文件 43 2017-11-22 09:45 sss\CNNGestureRecognizer-master\.gitattributes
文件 1045 2017-11-22 09:45 sss\CNNGestureRecognizer-master\.gitignore
文件 398 2018-01-26 21:00 sss\CNNGestureRecognizer-master\.idea\CNNGestureRecognizer-master.iml
文件 211 2018-01-26 20:55 sss\CNNGestureRecognizer-master\.idea\misc.xm
文件 306 2018-01-26 20:55 sss\CNNGestureRecognizer-master\.idea\modules.xm
文件 31458 2018-01-28 19:32 sss\CNNGestureRecognizer-master\.idea\workspace.xm
文件 12671 2018-01-28 17:49 sss\CNNGestureRecognizer-master\gestureCNN.py
文件 144 2018-01-28 18:03 sss\CNNGestureRecognizer-master\gesturejson.txt
文件 2399 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok1.png
文件 2243 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok10.png
文件 2056 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok100.png
文件 2004 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok101.png
文件 2311 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok102.png
文件 2492 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok103.png
文件 2605 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok104.png
文件 2603 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok105.png
文件 2541 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok106.png
文件 2615 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok107.png
文件 2703 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok108.png
文件 2572 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok109.png
文件 2304 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok11.png
文件 2645 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok110.png
文件 2698 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok111.png
文件 2704 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok112.png
文件 2699 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok113.png
文件 2618 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok114.png
文件 2655 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok115.png
文件 2600 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok116.png
文件 2594 2017-11-22 09:45 sss\CNNGestureRecognizer-master\imgfolder_b\iiiok117.png
............此处省略4032个文件信息
- 上一篇:python网络数据采集 中文版
- 下一篇:Python写的一个比赛抽签软件
评论
共有 条评论