资源简介
一个用手势控制的计算器
代码片段和文件信息
import numpy as np
import pickle
import cv2
import os
from keras import optimizers
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import Flatten
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.utils import np_utils
from keras.callbacks import ModelCheckpoint
from keras import backend as K
K.set_image_dim_ordering(‘tf‘)
def get_image_size():
img = cv2.imread(‘gestures/0/100.jpg‘ 0)
return img.shape
def get_num_of_classes():
return len(os.listdir(‘gestures/‘))
image_x image_y = get_image_size()
def cnn_model():
num_of_classes = get_num_of_classes()
model = Sequential()
model.add(Conv2D(32 (55) input_shape=(image_x image_y 1) activation=‘relu‘))
model.add(MaxPooling2D(pool_size=(2 2) strides=(2 2) padding=‘same‘))
model.add(Conv2D(64 (55) activation=‘relu‘))
model.add(MaxPooling2D(pool_size=(5 5) strides=(5 5) padding=‘same‘))
model.add(Flatten())
model.add(Dense(1024 activation=‘relu‘))
model.add(Dropout(0.4))
model.add(Dense(num_of_classes activation=‘softmax‘))
sgd = optimizers.SGD(lr=1e-4)
model.compile(loss=‘categorical_crossentropy‘ optimizer=sgd metrics=[‘accuracy‘])
filepath=“cnn_model_keras2.h5“
checkpoint1 = ModelCheckpoint(filepath monitor=‘val_acc‘ verbose=1 save_best_only=True mode=‘max‘)
#checkpoint2 = ModelCheckpoint(filepath monitor=‘val_loss‘ verbose=1 save_best_only=True mode=‘min‘)
callbacks_list = [checkpoint1]
return model callbacks_list
def train():
with open(“train_images“ “rb“) as f:
train_images = np.array(pickle.load(f))
with open(“train_labels“ “rb“) as f:
train_labels = np.array(pickle.load(f) dtype=np.int32)
with open(“test_images“ “rb“) as f:
test_images = np.array(pickle.load(f))
with open(“test_labels“ “rb“) as f:
test_labels = np.array(pickle.load(f) dtype=np.int32)
train_images = np.reshape(train_images (train_images.shape[0] image_x image_y 1))
test_images = np.reshape(test_images (test_images.shape[0] image_x image_y 1))
train_labels = np_utils.to_categorical(train_labels)
test_labels = np_utils.to_categorical(test_labels)
model callbacks_list = cnn_model()
model.fit(train_images train_labels validation_data=(test_images test_labels) epochs=50 batch_size=100 callbacks=callbacks_list)
scores = model.evaluate(test_images test_labels verbose=0)
print(“CNN Error: %.2f%%“ % (100-scores[1]*100))
#model.save(‘cnn_model_keras2.h5‘)
train()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-03-04 17:49 Simple-OpenCV-Calculator-master\
文件 4125 2018-03-04 17:49 Simple-OpenCV-Calculator-master\README.md
文件 2541 2018-03-04 17:49 Simple-OpenCV-Calculator-master\cnn_keras.py
文件 8950256 2018-03-04 17:49 Simple-OpenCV-Calculator-master\cnn_model_keras2.h5
文件 3716 2018-03-04 17:49 Simple-OpenCV-Calculator-master\create_gestures.py
文件 900 2018-03-04 17:49 Simple-OpenCV-Calculator-master\display_all_gestures.py
文件 16384 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gesture_db.db
目录 0 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\
目录 0 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\10.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\100.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1000.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1001.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1002.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1003.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1004.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1005.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1006.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1007.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1008.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1009.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\101.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1010.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1011.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1012.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1013.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1014.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1015.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1016.jpg
文件 369 2018-03-04 17:49 Simple-OpenCV-Calculator-master\gestures\0\1017.jpg
............此处省略15594个文件信息
相关资源
- Python-最全中华古诗词数据库
- Python-导出qq音乐歌单的小工具导出格
- Python-利用keras模仿汪峰生成歌词
- Python-洛谷冬日绘板脚本
- Python-PermaNote是基于Sandstorm开源的个人
- Python-当朋友给你发iMessage时自动回复
- Python-中国县级行政区划的边界数据并
- Python-垃圾分类助手猜测可能是什么垃
- Python-csv2tex将csv数据变成LaTeX表格
- Python-这是一个DSStore文件泄漏利用脚本
- Python-基于itchat库和图灵机器人实现的
- Python-农业知识图谱农业领域的命名实
- Python-从Python高效处理FASTQ文件
- Python-一个WindowsLinux和Mac的简单键盘记
- Python-Binance虚拟货币交易机器人
- Python-AWDHunter一个基于Python27的AWD自动
- Python-ArkNights自动作战脚本
- Python-导出安卓微信聊天数据工具
- Python-这是一个简单的Web聊天系统可以
评论
共有 条评论