首页 > 解决方案 > 如何将图像和标签的 numpy 数组保存为 tar.gz 或 idx3-ubyte.gz?

问题描述

基本上我试图弄清楚如何以有效的格式存储我的机器学习图像数据集。现在,我想出了如何将我的训练图像、测试图像和标签保存为 .npz 文件中的 numpy 数组,但我希望弄清楚如何以 mnist 数据库的样式存储图像。我的图像尺寸为(128、128)并且有 3 个颜色通道。有没有办法将我的图像数据转换为更好的格式并 gzip 进行压缩?谢谢你。

这是我目前存储我收集的 11,500 张图像的方式。

import numpy as np

def load_data():
    print("Loading Recycle Data")
    path = 'recycle_data_shuffled.npz'
    recycle_data = np.load(path)
    x_train, y_train = recycle_data['x_train'], recycle_data['y_train']
    x_test, y_test = recycle_data['x_test'], recycle_data['y_test']
    recycle_data.close()

    return (x_train, y_train), (x_test, y_test)

标签: pythonnumpygzip

解决方案


推荐阅读