未验证 提交 e95653ca 编写于 作者: TensorSense's avatar TensorSense 提交者: GitHub

Merge pull request #7 from kawa23/master

open file by with to avoid do not close the file if IOError
...@@ -8,17 +8,17 @@ import numpy as np ...@@ -8,17 +8,17 @@ import numpy as np
import os import os
import pickle import pickle
data_dir = '../../Data/cifar-10-batches-py/'
train_o_dir = '../../Data/cifar-10-png/raw_train/' data_dir = os.path.join("..", "..", "Data", "cifar-10-batches-py")
test_o_dir = '../../Data/cifar-10-png/raw_test/' train_o_dir = os.path.join("..", "..", "Data", "cifar-10-png", "raw_train")
test_o_dir = os.path.join("..", "..", "Data", "cifar-10-png", "raw_test")
Train = False # 不解压训练集,仅解压测试集 Train = False # 不解压训练集,仅解压测试集
# 解压缩,返回解压后的字典 # 解压缩,返回解压后的字典
def unpickle(file): def unpickle(file):
fo = open(file, 'rb') with open(file, 'rb') as fo:
dict_ = pickle.load(fo, encoding='bytes') dict_ = pickle.load(fo, encoding='bytes')
fo.close()
return dict_ return dict_
def my_mkdir(my_dir): def my_mkdir(my_dir):
...@@ -30,7 +30,7 @@ def my_mkdir(my_dir): ...@@ -30,7 +30,7 @@ def my_mkdir(my_dir):
if __name__ == '__main__': if __name__ == '__main__':
if Train: if Train:
for j in range(1, 6): for j in range(1, 6):
data_path = data_dir + "data_batch_" + str(j) # data_batch_12345 data_path = os.path.join(data_dir, "data_batch_" + str(j)) # data_batch_12345
train_data = unpickle(data_path) train_data = unpickle(data_path)
print(data_path + " is loading...") print(data_path + " is loading...")
...@@ -50,7 +50,7 @@ if __name__ == '__main__': ...@@ -50,7 +50,7 @@ if __name__ == '__main__':
print("test_batch is loading...") print("test_batch is loading...")
# 生成测试集图片 # 生成测试集图片
test_data_path = data_dir + "test_batch" test_data_path = os.path.join(data_dir, "test_batch")
test_data = unpickle(test_data_path) test_data = unpickle(test_data_path)
for i in range(0, 10000): for i in range(0, 10000):
img = np.reshape(test_data[b'data'][i], (3, 32, 32)) img = np.reshape(test_data[b'data'][i], (3, 32, 32))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册