Browse Source

删除文件 deep_leakage by xiaodouzi/DLG-FOR-Mindspore/extract_cifar100.py

pull/311/head
小豆子 Gitee 3 years ago
parent
commit
e3bfeab2a9
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 0 additions and 55 deletions
  1. +0
    -55
      deep_leakage by xiaodouzi/DLG-FOR-Mindspore/extract_cifar100.py

+ 0
- 55
deep_leakage by xiaodouzi/DLG-FOR-Mindspore/extract_cifar100.py View File

@@ -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.")

Loading…
Cancel
Save