【问题标题】:Combining datasets in a single .npz file在单个 .npz 文件中组合数据集
【发布时间】:2021-06-09 11:10:24
【问题描述】:

我有四个目录 x_train、y_train、x_test 和 y_test

每个目录包含许多图像。我想将它们全部转换为一个 .npz 文件,以便我可以加载它们,如下所示。

DATA_URL = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz'

path = tf.keras.utils.get_file('mnist.npz', DATA_URL)
with np.load(path) as data:
  train_examples = data['x_train']
  train_labels = data['y_train']
  test_examples = data['x_test']
  test_labels = data['y_test']

不用担心网址我只想创建文件

【问题讨论】:

    标签: python python-3.x numpy tensorflow


    【解决方案1】:

    只需使用savez() 方法,参见docs

    import numpy as np
    file_name = 'something.npz'
    np.savez(file_name, x_train=x_train, y_train=y_train, x_test=x_test, y_test=y_test)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 2016-01-02
      • 1970-01-01
      • 2017-11-03
      • 2018-07-17
      • 1970-01-01
      相关资源
      最近更新 更多