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

数据集007:垃圾分类数据集(含数据集下载链接)

数据集简介

本数据拥有

训练集:43685张;

验证集:5363张;

测试集:5363张;

总类别数:158类。

部分代码:

定义数据集

class MyDataset(Dataset):
    def __init__(self, mode='train', transform=None):
        super(MyDataset, self).__init__()
        self.data = []
        self.transform = transform
        with open(f'{data_path}{mode}.txt') as f:
            for line in f.readlines():
                info = line.strip().split(' ')
                if len(info) > 0:
                    self.data.append(
                        [data_path+'/'+info[0].strip(), info[1].strip()])

    def __getitem__(self, idx):
        image_file, label = self.data[idx]
        img = Image.open(image_file).convert('RGB')
        img = np.array(img)
        # (Tensor(shape=[3, 227, 227], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
        if self.transform is not None:
            img = self.transform(img)
        label = np.array([label], dtype="int64")
        return img, label

    def __len__(self):

定义ResNet网络


resnet50 = paddle.vision.models.resnet50(num_classes=158)

取单张测试图片进行可视化展示

import pylab as pl
import matplotlib.font_manager as fm

test_path = '/home/aistudio/Mydata/test1.txt'
myfont = fm.FontProperties(fname=r'/home/aistudio/simkai.ttf') # 设置字体   
jetson_path = '/home/aistudio/Mydata/garbage_classification.json'
with open(jetson_path, 'r') as f1:
    load_dict = json.load(f1)
with open(test_path, 'r') as f2:
    img_path = f2.readline().strip().split(' ')
test_img_path = '/home/aistudio/Mydata/' + f'{img_path[0]}'
print('输入测试图片路径为:')
print(test_img_path)
clas = load_dict[f'{lab1}']#从字典中查找标签0对应的垃圾种类
img = cv2.imread(test_img_path)
plt.imshow(img)
plt.title(f'预测:{clas}', fontproperties = myfont, fontsize=20)

数据库下载链接:垃圾分类数据集

相关文章:

  • 宝塔部署纯Vue项目,无后端
  • 文献分享《Microbiome and cancer》
  • 在 Visual Studio Code(VS Code)中调试 .NET Core 程序详细步骤
  • markdown画时序图的时候,如何自动显示每一条时序的序号
  • 服务器端口转发,服务器端口转发的作用、好处与坏处
  • Divisibility Part2(整除理论2)
  • PY32F002A单片机 us 延时,非常惊讶
  • 宿舍管理系统代码详解(操作界面)
  • 代码随想录算法训练营第四十一天|509. 斐波那契数、70. 爬楼梯、746. 使用最小花费爬楼梯
  • 消费增值:国家支持的消费新零售模型
  • linux 查看csv文件,按指定列聚合 排序
  • Unity面试八股文之基础篇
  • 扩散模型的一些公式证明
  • 图论(四)—最短路问题(Dijkstra)
  • JS书写规范
  • TCP/IP协议族
  • 使用python将多个mp3或者wma合并成一个mp3
  • Windows系统使用Docker部署Focalboard团队协作工具详细流程
  • can设备调试 - linux driver
  • Jmeter元件及基本作用域
  • 涉军民事案件类型日益增多,最高法新规明晰管辖争议问题
  • 上海市闵行区原二级巡视员琚汉铮接受纪律审查和监察调查
  • 迎世界读书日,2025年首都大学生系列读书活动发布
  • 河南濮阳南乐县官方回应“幼儿园强制订园服”:已责令整改
  • 一场12年的马拉松,他用声音陪伴中国路跑成长
  • 外汇局:4月以来外汇市场交易保持平稳,跨境资金延续净流入