From e3bfeab2a97c190387c7ddd1064c43eac3d2374e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B1=86=E5=AD=90?= <172074482@qq.com> Date: Tue, 18 Jan 2022 19:17:20 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20deep=5Fl?= =?UTF-8?q?eakage=20by=20xiaodouzi/DLG-FOR-Mindspore/extract=5Fcifar100.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DLG-FOR-Mindspore/extract_cifar100.py | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 deep_leakage by xiaodouzi/DLG-FOR-Mindspore/extract_cifar100.py diff --git a/deep_leakage by xiaodouzi/DLG-FOR-Mindspore/extract_cifar100.py b/deep_leakage by xiaodouzi/DLG-FOR-Mindspore/extract_cifar100.py deleted file mode 100644 index 394227a..0000000 --- a/deep_leakage by xiaodouzi/DLG-FOR-Mindspore/extract_cifar100.py +++ /dev/null @@ -1,55 +0,0 @@ -import cv2 -import numpy as np -import pickle -import os - - -# 解压缩,返回解压后的字典 -def unpickle(file): - fo = open(file, 'rb') - dict = pickle.load(fo, encoding='latin1') - fo.close() - return dict - - -def cifar100_to_images(): - tar_dir = '/root/DLG-FOR-Mindspore/data/cifar-100-python' # 原始数据库目录 - train_root_dir = '/root/DLG-FOR-Mindspore/data/train' # 图片保存目录 - test_root_dir = '/root/DLG-FOR-Mindspore/data/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) - - # 生成训练集图片 - 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.") \ No newline at end of file