<i id='6XK2P'><tr id='6XK2P'><dt id='6XK2P'><q id='6XK2P'><span id='6XK2P'><b id='6XK2P'><form id='6XK2P'><ins id='6XK2P'></ins><ul id='6XK2P'></ul><sub id='6XK2P'></sub></form><legend id='6XK2P'></legend><bdo id='6XK2P'><pre id='6XK2P'><center id='6XK2P'></center></pre></bdo></b><th id='6XK2P'></th></span></q></dt></tr></i><div id='6XK2P'><tfoot id='6XK2P'></tfoot><dl id='6XK2P'><fieldset id='6XK2P'></fieldset></dl></div>

    <tfoot id='6XK2P'></tfoot>
  1. <legend id='6XK2P'><style id='6XK2P'><dir id='6XK2P'><q id='6XK2P'></q></dir></style></legend>

      <bdo id='6XK2P'></bdo><ul id='6XK2P'></ul>

      <small id='6XK2P'></small><noframes id='6XK2P'>

    1. 将 .npy(numpy 文件)输入 tensorflow 数据管道

      Feeding .npy (numpy files) into tensorflow data pipeline(将 .npy(numpy 文件)输入 tensorflow 数据管道)
    2. <i id='d8bB7'><tr id='d8bB7'><dt id='d8bB7'><q id='d8bB7'><span id='d8bB7'><b id='d8bB7'><form id='d8bB7'><ins id='d8bB7'></ins><ul id='d8bB7'></ul><sub id='d8bB7'></sub></form><legend id='d8bB7'></legend><bdo id='d8bB7'><pre id='d8bB7'><center id='d8bB7'></center></pre></bdo></b><th id='d8bB7'></th></span></q></dt></tr></i><div id='d8bB7'><tfoot id='d8bB7'></tfoot><dl id='d8bB7'><fieldset id='d8bB7'></fieldset></dl></div>
    3. <tfoot id='d8bB7'></tfoot><legend id='d8bB7'><style id='d8bB7'><dir id='d8bB7'><q id='d8bB7'></q></dir></style></legend>

        <bdo id='d8bB7'></bdo><ul id='d8bB7'></ul>

        <small id='d8bB7'></small><noframes id='d8bB7'>

              <tbody id='d8bB7'></tbody>
              • 本文介绍了将 .npy(numpy 文件)输入 tensorflow 数据管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Tensorflow 似乎缺少.npy"文件的阅读器.如何将我的数据文件读入新的 tensorflow.data.Dataset 管道?我的数据不适合内存.

                每个对象都保存在单独的.npy"文件中.每个文件包含 2 个不同的 ndarray 作为特征和一个标量作为它们的标签.

                解决方案

                你的数据适合内存吗?如果是这样,您可以按照文档的 Consuming NumPy Arrays 部分中的说明进行操作:

                <块引用>

                使用 NumPy 数组

                如果您的所有输入数据都适合内存,从它们创建数据集的最简单方法是将它们转换为 tf.Tensor 对象并使用 Dataset.from_tensor_slices().

                # 将训练数据加载到两个 NumPy 数组中,例如使用 `np.load()`.使用 np.load("/var/data/training_data.npy") 作为数据:特征=数据[特征"]标签=数据[标签"]# 假设 `features` 的每一行对应于 `labels` 的同一行.断言 features.shape[0] == labels.shape[0]数据集 = tf.data.Dataset.from_tensor_slices((特征,标签))

                如果文件不适合内存,似乎唯一推荐的方法是首先将 npy 数据转换为 TFRecord 格式,然后然后使用 TFRecord 数据集格式,无需完全加载到内存即可流式传输.

                这是一个包含一些说明的帖子.

                FWIW,我觉得 TFRecord 不能直接用 npy 文件的目录名或文件名实例化,但这似乎是普通 Tensorflow 的限制.p>

                如果您可以将单个大型 npy 文件拆分为较小的文件,每个文件大致代表一个批次进行训练,那么您可以在 Keras 中编写一个自定义数据生成器,该生成器仅生成当前批次所需的数据.

                一般来说,如果您的数据集无法放入内存中,将其存储为一个大的 npy 文件会使其非常难以处理,最好先将数据重新格式化为 TFRecord 或多个 npy 文件,然后使用其他方法.

                Tensorflow seems to lack a reader for ".npy" files. How can I read my data files into the new tensorflow.data.Dataset pipline? My data doesn't fit in memory.

                Each object is saved in a separate ".npy" file. each file contains 2 different ndarrays as features and a scalar as their label.

                解决方案

                Does your data fit into memory? If so, you can follow the instructions from the Consuming NumPy Arrays section of the docs:

                Consuming NumPy arrays

                If all of your input data fit in memory, the simplest way to create a Dataset from them is to convert them to tf.Tensor objects and use Dataset.from_tensor_slices().

                # Load the training data into two NumPy arrays, for example using `np.load()`.
                with np.load("/var/data/training_data.npy") as data:
                  features = data["features"]
                  labels = data["labels"]
                
                # Assume that each row of `features` corresponds to the same row as `labels`.
                assert features.shape[0] == labels.shape[0]
                
                dataset = tf.data.Dataset.from_tensor_slices((features, labels))
                

                In the case that the file doesn't fit into memory, it seems like the only recommended approach is to first convert the npy data into a TFRecord format, and then use the TFRecord data set format, which can be streamed without fully loading into memory.

                Here is a post with some instructions.

                FWIW, it seems crazy to me that TFRecord cannot be instantiated with a directory name or file name(s) of npy files directly, but it appears to be a limitation of plain Tensorflow.

                If you can split the single large npy file into smaller files that each roughly represent one batch for training, then you could write a custom data generator in Keras that would yield only the data needed for the current batch.

                In general, if your dataset cannot fit in memory, storing it as one single large npy file makes it very hard to work with, and preferably you should reformat the data first, either as TFRecord or as multiple npy files, and then use other methods.

                这篇关于将 .npy(numpy 文件)输入 tensorflow 数据管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Select randomly x files in subdirectories(随机选择子目录中的 x 个文件)
                Converting CSV files to TF Records(将 CSV 文件转换为 TF 记录)
                DASK Metadata mismatch found in #39;from_delayed#39; JSON file(在“from_delayedJSON 文件中发现 DASK 元数据不匹配)
                In TensorFlow 2.0, how can I see the number of elements in a dataset?(在 TensorFlow 2.0 中,如何查看数据集中的元素数量?)
                Scikit-learn labeled dataset creation from segmented time series(从分段时间序列创建 Scikit-learn 标记数据集)
                Chunking, processing amp; merging dataset in Pandas/Python(分块、处理和在 Pandas/Python 中合并数据集)

                • <bdo id='AT5Vd'></bdo><ul id='AT5Vd'></ul>

                        <tfoot id='AT5Vd'></tfoot>

                        <i id='AT5Vd'><tr id='AT5Vd'><dt id='AT5Vd'><q id='AT5Vd'><span id='AT5Vd'><b id='AT5Vd'><form id='AT5Vd'><ins id='AT5Vd'></ins><ul id='AT5Vd'></ul><sub id='AT5Vd'></sub></form><legend id='AT5Vd'></legend><bdo id='AT5Vd'><pre id='AT5Vd'><center id='AT5Vd'></center></pre></bdo></b><th id='AT5Vd'></th></span></q></dt></tr></i><div id='AT5Vd'><tfoot id='AT5Vd'></tfoot><dl id='AT5Vd'><fieldset id='AT5Vd'></fieldset></dl></div>
                        <legend id='AT5Vd'><style id='AT5Vd'><dir id='AT5Vd'><q id='AT5Vd'></q></dir></style></legend>

                          <small id='AT5Vd'></small><noframes id='AT5Vd'>

                            <tbody id='AT5Vd'></tbody>