# python imaging library
from PIL import Image
import matplotlib.pyplot as plt
import pickle
with open('train.p', 'rb') as f:
data = pickle.load(f)
X_train = data['features']
y_train = data['labels']
# (39209, 32, 32, 3)
print(X_train.shape)
print(X_train.shape[0])
for i in range(X_train.shape[0]):
new_im = Image.fromarray(X_train[i]) # 感觉不使用fromarray()函数也可以,并且1通道图像用squeeze()处理后就可以显示
new_im.save('images/'+str(i)+'.png')
# 显示图片
plt.imshow(new_im)
plt.show()
将.p文件转换为图片
最新推荐文章于 2022-11-14 20:52:01 发布