(1)方法1:从CIFAR-10数据集中提取图像,并将它们按类别保存为PNG格式的文件。
目标目录结构如图:
import numpy as np
import pickle
import os
from torchvision import datasets
from imageio import imwrite
# 数据集放置路径 cifar10/cifar-10-batches-py
data_save_pth = "./"
train_pth = os.path.join(data_save_pth, "train")
test_pth = os.path.join(data_save_pth, "test")
# 创建必要的目录
def create_dir(path):
if not os.path.exists(path):
os.makedirs(path)
create_dir(train_pth)
create_dir(test_pth)
# 解压路径
data_dir = os.path.join(data_save_pth, "cifar-10-batches-py")
# 数据集下载</