利用opencv将从torchvision中加载的Cirfar10数据集再转成图片

import os
import cv2
import torchvision


if __name__ == '__main__':

    trainset = torchvision.datasets.CIFAR10(root='./datasets/', train=True, download=True)

    mp = {}
    for i in trainset.classes:
        mp[i] = 0
        
    for i in range(len(trainset)):
        image = trainset.data[i]
        label = trainset.classes[trainset.targets[i]]
        fp = './results/%s' % (label)
        if not os.path.exists(fp):
            os.makedirs(fp)
        fp = os.path.join(fp, 'img_%s.jpg' % mp[label])
        mp[label] += 1 
        print(fp)
        cv2.imwrite( fp, image)
    
        

利用opencv将从torchvision中加载的Cirfar10数据集再转成图片_第1张图片利用opencv将从torchvision中加载的Cirfar10数据集再转成图片_第2张图片

 

 

你可能感兴趣的:(其他,python,人工智能,开发语言)