顾名思义 这波是百度paddle学习的第二天
今天学习的是利用神经网络实现手势识别
数据和部分代码来自:https://aistudio.baidu.com
首先 把任务比作火箭🚀 神经网络就是火箭的发动机 那数据集就是 火箭的油
数据这里就暂时无法提供了 可以去aistudio自取
这里就是数据集里面已经分好类的图片了,到时候方便我们调用
下面我们来到我们的代码部分:
import os
import time
import random
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import paddle
import paddle.fluid as fluid
import paddle.fluid.layers as layers
from multiprocessing import cpu_count
from PIL._imaging import display
from paddle.fluid.dygraph import Pool2D,Conv2D
from paddle.fluid.dygraph import Linear
直接把需要的库调用出来
对于飞桨的API查找直接百度搜索飞桨进入官网查看文档即可
# 生成图像列表
data_path = 'data/data23668/Dataset'
character_folders = os.listdir(data_path)
# print(character_folders)
if (os.path.exists('./train_data.list')):
os.remove('./train_data.list')
if (os.path.exists('./test_data.list')):
os.remove('./test_data.list')
for character_folder in character_folders:
with open('./train_data.list', 'a') as f_train:
with open('./test_data.list', 'a') as f_test:
if character_folder == '.DS_Store':
continue
character_imgs = os.listdir(os.path.join(data_path, character_folder))
count = 0
for img in character_imgs:
if img == '.DS_Store':
continue
if count % 10 == 0:
f_test.write(os.path.join(data_path, character_folder, img) + '\t' + character_folder + '\n')
else:
f_train.write(os.path.join(data_path, character_folder, img) + '\t' + character_folder + '\n')
count += 1
print('列表已生成')
# 定义训练集和测试集的reader
def data_mapper(sample):
img, label = sample
img = Image.open