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

一个简单的图像分类项目(三)编写脚本:参数设置

368dba2ac0f4427780dbe6ea31d5532f.png

 项目所有的参数均在这个脚本内设置,方便管理和移植。

sript.setting.py:

import osimport torch
from PIL import Image# 获取当前脚本的绝对路径
script_dir = os.path.dirname(os.path.abspath(__file__))# 获取当前脚本的上一层目录
parent_dir = os.path.dirname(script_dir)# 学习集路径
train_path = os.path.join(parent_dir, "image", "train")
# print(train_path)# 测试集路径
test_path = os.path.join(parent_dir, "image", "test")# 错误集路径
error_path = os.path.join(parent_dir, "image", "error")# 模型路径
model_path = os.path.join(parent_dir, "model")# 对应的数字
label_dict = {'airplane': 0, 'automobile': 1, 'bird': 2, 'cat': 3, 'deer': 4,'dog': 5, 'frog': 6, 'horse': 7, 'ship': 8, 'truck': 9}# 数字对应的类别标签
label_name = {0: 'airplane', 1: 'automobile', 2: 'bird', 3: 'cat', 4: 'deer',5: 'dog', 6: 'frog', 7: 'horse', 8: 'ship', 9: 'truck'}# 标签类别的数量
classes = len(label_dict)# 标准化参数
# normalize_values = {(0.485, 0.456, 0.406), (0.229, 0.224, 0.225)}
normalize_mean = (0.485, 0.456, 0.406)  # 标准化参数, 均值
normalize_std = (0.229, 0.224, 0.225)  # 标准化参数, 标准差
normalize_size = (32, 32)  # 标准化参数, 图像尺寸# batch size
batch_size = 128# 子进程数量
num_workers = 12# 网络是否预训练
is_pretrained = False# 学习率
learning_rate = 0.01# 训练轮数
num_epoches = 100# 优先使用GPU训练
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')# 图片数据出错后的默认数据
error_default_path = os.path.join(error_path, "error_default.png")
_img = Image.open(error_default_path)
error_default_img = _img.convert('RGB')  # 转换成RGB模式


http://www.mrgr.cn/news/60730.html

相关文章:

  • 平价十大蓝牙耳机品牌怎么选?最顶尖的真无线蓝牙耳机盘点
  • 【C++笔记】list结构剖析及其模拟实现
  • 一种小型固定翼无人机弹射着陆系统的设计
  • OceanBase 安全体系解析之身份鉴别
  • 稳定性分析案例
  • PostgreSQL-06-入门篇-集合运算
  • Python学习-列表基本操作
  • MODSI EVI 数据的时间序列拟合一阶谐波模型
  • Pandas简介
  • 数组排序简介-插入排序(Insertion Sort)
  • 阿里巴巴运营技巧分享
  • 【c++篇】:探索c++中的std::string类--掌握字符串处理的精髓
  • Ubuntu虚拟机的安装以及相关文件配置(保姆级攻略)
  • 多个立方体盒子组成
  • HTML的总结作业
  • C++设计模式创建型模式———简单工厂模式、工厂方法模式、抽象工厂模式
  • MambaAD 5总结 分析
  • 前端必备的环境搭建
  • 一文理解平流层温度变化规律
  • Java中如何在两个线程间共享数据
  • 监控易系统:引领智能阈值管理与网络设备监控的创新
  • 信号 和 槽
  • “雷鸟效应”引领全民AR新纪元:专注影音体验,打造消费级AR天花板
  • 理想传输线等效模型与特性阻抗
  • 实现RPC接口的demo记录
  • Windows端口管理与进程控制