【笔记】Cifar-100数据集介绍:​它有100个类,每个类包含600个图像,其中500个训练图像和100个测试图像;100类实际是由20个类(每个类又包含5个子类)构成(5*20=100)

这篇笔记介绍了如何将CIFAR-100数据集从原始格式转换为图片,并保存为jpg格式。同时,提供了加载CIFAR-100数据集的代码,包括训练集和测试集,用于图像处理和分析。文章还强调了CIFAR-100数据集的特点,即包含100个类别,每个类别有600张图像,其中500张用于训练,100张用于测试,类别分为20个大类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

笔记1:

cifar10与cifar100下载地址:CIFAR-10 and CIFAR-100 datasets

Cifar100 转图片:

def cifar100_to_images():
  tar_dir='../data/cifar-100-python/' #原始数据库目录
  train_root_dir='../data/cifar100/train/' #图片保存目录
  test_root_dir='../data/cifar100/test/'
  if not os.path.exists(train_root_dir):
    os.makedirs(train_root_dir)
  if not os.path.exists(test_root_dir):
    os.makedirs(test_root_dir)
 
  #获取label对应的class,分为20个coarse class,共100个 fine class
  meta_Name = tar_dir+"meta" 
  Meta_dic= unpickle(meta_Name)
  coarse_label_names=Meta_dic['coarse_label_names']
  fine_label_names=Meta_dic['fine_label_names']
  print(fine_label_names)
 
  #生成训练集图片,如果需要png格式,只需要改图片后缀名即可。
  dataName = tar_dir+"train" 
  Xtr = unpickle(dataName)
  print(dataName + " is loading...")
  for i in range(0,Xtr['data'].shape[0]):
      img = np.reshape(Xtr['data'][i], (3, 32, 32))  # Xtr['data']为图片二进制数据
      img = img.transpose(1, 2, 0)  # 读取image
      ###img_name:fine_label+coarse_label+fine_class+coarse_class+index
      picName = train_root_dir + str(Xtr['fine_labels'][i])+ '_' + str(Xtr['coarse_labels'][i]) + '_&' +fine_label_names[Xtr['fine_labels'][i]]+'&_'+coarse_label_names[ Xtr['coarse_labels'][i]]+'_'+str(i) + '.jpg' 
      cv2.imwrite(picName, img)
  print(dataName + " loaded.")
 
  print("test_batch is loading...")
  # 生成测试集图片
  testXtr = unpickle(tar_dir+"test")
  for i in range(0, testXtr['data'].shape[0]):
      img = np.reshape(testXtr['data'][i], (3, 32, 32))
      img = img.transpose(1, 2, 0)
      picName = test_root_dir +str(testXtr['fine_labels'][i])+ '_' + str(testXtr['coarse_labels'][i]) + '_&' +fine_label_names[testXtr['fine_labels'][i]]+'&_'+coarse_label_names[ testXtr['coarse_labels'][i]]+'_'+str(i) + '.jpg' 
      cv2.imwrite(picName, img)
  print("test_batch loaded.")

结果:文件名为 # fine_label+coarse_label+fine_class+coarse_class+index.jpg

fine表示类,coarse表示大类。

 

 

笔记2:

CIFAR100和CIFAR-10类似,它有100个类,每个类包含600个图像,其中500个训练图像和100个测试图像

100类实际是由20个类(每个类又包含5个子类)构成(5*20=100)。

 

# -*- coding:utf-8 -*-
import pickle as p
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as plimg
from PIL import Image
 
def load_CIFAR_batch(filename):
    """ load single batch of cifar """
    with open(filename, 'rb')as f:
        datadict = p.load(f,encoding='bytes')
        #X = datadict[b'data']
        #Y = datadict[b'labels']
        #X = X.reshape(10000, 3, 32, 32)
        X = datadict[b'data']
        Y = datadict[b'coarse_labels']+datadict[b'fine_labels']
        X = X.reshape(50000, 3, 32, 32)
        Y = np.array(Y)
        return X, Y
 
 
if __name__ == "__main__":
    #imgX, imgY = load_CIFAR_batch("./cifar-10-batches-py/data_batch_1")
    imgX, imgY = load_CIFAR_batch("dataset/cifar-100-python/train")
    print(imgX.shape)
    print("正在保存图片:")
    for i in range(imgX.shape[0]):
        imgs = imgX[i]
        if i < 100:#只循环100张图片,这句注释掉可以便利出所有的图片,图片较多,可能要一定的时间
            img0 = imgs[0]
            img1 = imgs[1]
            img2 = imgs[2]
            i0 = Image.fromarray(img0)
            i1 = Image.fromarray(img1)
            i2 = Image.fromarray(img2)
            img = Image.merge("RGB",(i0,i1,i2))
            name = "img" + str(i)+".png"
            img.save("dataset/cifar-100-python/extract-pic1/"+name,"png")#文件夹下是RGB融合后的图像
            for j in range(imgs.shape[0]):
                img = imgs[j]
                name = "img" + str(i) + str(j) + ".jpg"
                print("正在保存图片" + name)
                plimg.imsave("dataset/cifar-100-python/extract-pic2/" + name, img)#文件夹下是RGB分离的图像
    print("保存完毕.")
 

### 关于Cadence 17.2版本中Pspice的教程 #### 安装指南 对于希望安装Cadence PSpice 17.2版本的用户来说,需注意几个关键步骤。当点击安装Cadence软件时,应指定添加安装包路径以及设定不含空格汉字字符的安装路径[^1]。完成基础软件部署后,还需通过加入Hotfix文件的方式安装必要的更新补丁。最后,在一切设置妥当之后,务必记得重启计算机以使更改生效。 #### 绘制原理图 一旦上述准备工作就绪,则可以在重新启动后的环境中利用OrCAD Capture CIS工具着手绘制所需的电路原理图。此阶段涉及的具体操作包括但不限于元件的选择、放置及其间的连接构建等动作。 #### 创建自定义电路模块 针对那些想要进一步定制化工作流或者提高效率的技术人员而言,掌握如何基于个人需求创建专属的电路组件显得尤为重要。在Cadence PSpice环境下,这意呸着能够把一系列预设好的子电路打包成独立单元以便重复调用或分享给团队成员。具体实现过程涵盖了从草稿构思到最后成品导出的一系列环节[^2]。 #### 设计流程概览 在整个电子设计自动化领域里,由概念验证直至最终产品成型往往遵循一套既定的工作模式。对于采用Cadence平台开展工作的工程师们来讲,这套方法论通常始于案例研究进而过渡至详尽的设计实施;期间会经历诸如原理图表绘、错误检测修正、性能测试评估等多个重要节点直到所有目标达成为止[^3]。 #### 原理图设计概述 深入探讨一下项目结构的话就会发现,“Design Resources”部分主要负责存储整个项目的配置信息。“Outputs”则用于汇总各中间产物或是终期报告文档。“Referenced Projects”允许设计师轻松关联其他辅助性的外部资料库从而促进跨部门协作交流活动顺利展开。值得注意的是如果当前任务涉及到仿真的话那么这里还会额外显示出专门用来支持此作业的相关条目——即所谓的“PSpice Resources”。 ```python # Python代码示例仅作为装饰用途,并不实际参与解释说明逻辑 def example_function(): pass ```
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值