当前位置: 首页 > news >正文

人工只能综合项目开发8---手势识别data_processing

import numpy as np
import h5py
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from keras.preprocessing.image import ImageDataGenerator
from keras.utils import to_categorical# 中文显示配置
plt.rcParams["font.family"] = ["SimHei", "SimSun", "Microsoft YaHei"]
plt.rcParams["axes.unicode_minus"] = Falsedef load_dataset():"""加载并分割数据集为训练/验证/测试集"""with h5py.File('./train_signs.h5', "r") as f:train_x, train_y = np.array(f["train_set_x"][:]), np.array(f["train_set_y"][:])with h5py.File('./test_signs.h5', "r") as f:test_x, test_y = np.array(f["test_set_x"][:]), np.array(f["test_set_y"][:])classes = np.array(f["list_classes"][:])# 分层分割训练集为训练/验证集train_x, val_x, train_y, val_y = train_test_split(train_x, train_y, test_size=0.2, random_state=42, stratify=train_y)return train_x, train_y, val_x, val_y, test_x, test_y, classesdef preprocess_data(images):"""图像预处理:归一化到[0,1]并确保3通道"""images = images.astype('float32') / 255.0if images.shape[-1] == 1:images = np.repeat(images, 3, axis=-1)return imagesdef create_data_augmenter():"""创建轻量数据增强生成器"""return ImageDataGenerator(horizontal_flip=True,width_shift_range=0.03,height_shift_range=0.03,fill_mode='nearest')# 加载并预处理数据
X_train_orig, Y_train_orig, X_val_orig, Y_val_orig, X_test_orig, Y_test_orig, classes = load_dataset()X_train = preprocess_data(X_train_orig)
X_val = preprocess_data(X_val_orig)
X_test = preprocess_data(X_test_orig)# 标签转为one-hot编码
Y_train = to_categorical(Y_train_orig, 6)
Y_val = to_categorical(Y_val_orig, 6)
Y_test = to_categorical(Y_test_orig, 6)# 验证数据形状
print(f"Y_train形状: {Y_train.shape} (应为 (864,6))")
print(f"Y_val形状: {Y_val.shape} (应为 (216,6))")
print(f"Y_test形状: {Y_test.shape} (应为 (120,6))")# 数据增强配置
datagen = create_data_augmenter()
augmented_train_generator = datagen.flow(X_train, Y_train, batch_size=32, shuffle=True)
steps_per_epoch = X_train.shape[0] // 32
http://www.dtcms.com/a/520056.html

相关文章:

  • C primer plus (第六版)第十一章 编程练习第13题
  • 网站被k申述泉州专业网站建设公司
  • FLUMINER福禄T3 115T挖矿机深度评测:智能管理与高效性能如何平衡?
  • 怎么调网站兼容性公益网站怎么做
  • 压缩与缓存调优实战指南:从0到1根治性能瓶颈(四)
  • 嵌入式软件架构--显示界面架构(工厂流水线模型,HOME界面,命令界面)
  • Ubuntu20.04 + QT5.14.2 + Android23的开发平台搭建总结
  • 【思维链条CoT与React模式深度解析】AI智能体的核心推理框架
  • svchost第一个是rpcss第二个是termsvcs第三个是NetworkService第四个是LocalService第五个是netsvcs----备忘
  • 餐饮网站模板免费下载jetpack wordpress
  • Hadoop High Availability 简介
  • Tier 1 供应商EDI对接:Forvia EDI需求分析
  • 2025最新策略答案引擎优化(AEO):在AI搜索引擎中获得更多曝光
  • SpringAI Redis RAG 搜索
  • 服务器和域名都有了 怎么做网站网站seo诊断分析报告
  • SpringBoot的Web开发
  • 基于springboot的大创管理系统开发与设计
  • GitHub 热榜项目 - 日榜(2025-10-23)
  • RAG:让大模型“既懂又查”的智能系统
  • cms网站建设的优缺点wordpress两个站合并
  • 数据结构——B树及其基本操作
  • java.text.MessageFormat的用法
  • 公司网站怎么做分录平面设计怎么网上接单
  • Java爬虫性能优化:以喜马拉雅音频元数据抓取为例
  • 使用 Java 对 PDF 添加水印:提升文档安全与版权保护
  • CRMEB-PHP订单改价模块详解
  • 丽水 网站建设注册163免费邮箱
  • 网站建设微信开发怎么做订阅号
  • TypeScript Array(数组)
  • E160系列全国产超外差无线射频模块技术解析与应用指南