- 🍨 本文为🔗365天深度学习训练营 中的学习记录博客
- 🍖 原作者:K同学啊
目标
具体实现
(一)环境
语言环境:Python 3.10
编 译 器: PyCharm
框 架: Pytorch
(二)具体步骤
1. Utils.py
import torch
import pathlib
import matplotlib.pyplot as plt
# 第一步:设置GPU
def USE_GPU():
if torch.cuda.is_available():
print('CUDA is available, will use GPU')
device = torch.device("cuda")
else:
print('CUDA is not available. Will use CPU')
device = torch.device("cpu")
return device
def data_from_directory(directory, show=True):
"""
提供是的数据集是文件形式的,提供目录方式导入数据,简单分析数据并返回数据分类
:param directory: 数据集所在目录
:param show: 是否需要以柱状图形式显示数据分类情况,默认显示
:return: 数据分类列表,类型: list
""" print("数据目录:{}".format(directory))
data_dir = pathlib.Path(directory)
data_path = list(data_dir.glob('*'))
class_name = [str(path).split('\\')[-1] for path in data_path]
print("数据分类: {}, 类别数量:{}".format(class_name, len(list(data_dir.glob('*')))))
total_image = len(list(data_dir.glob('*/*')))
print("图片数据总数: {}".format(total_image))
temp_sum = 0
if s

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



