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

      • <bdo id='zHJSO'></bdo><ul id='zHJSO'></ul>
      <tfoot id='zHJSO'></tfoot>
    1. <legend id='zHJSO'><style id='zHJSO'><dir id='zHJSO'><q id='zHJSO'></q></dir></style></legend>

      <i id='zHJSO'><tr id='zHJSO'><dt id='zHJSO'><q id='zHJSO'><span id='zHJSO'><b id='zHJSO'><form id='zHJSO'><ins id='zHJSO'></ins><ul id='zHJSO'></ul><sub id='zHJSO'></sub></form><legend id='zHJSO'></legend><bdo id='zHJSO'><pre id='zHJSO'><center id='zHJSO'></center></pre></bdo></b><th id='zHJSO'></th></span></q></dt></tr></i><div id='zHJSO'><tfoot id='zHJSO'></tfoot><dl id='zHJSO'><fieldset id='zHJSO'></fieldset></dl></div>
    2. 在 TensorFlow 2.0 中,如何查看数据集中的元素数量?

      In TensorFlow 2.0, how can I see the number of elements in a dataset?(在 TensorFlow 2.0 中,如何查看数据集中的元素数量?)
          <bdo id='wLcTs'></bdo><ul id='wLcTs'></ul>
          <i id='wLcTs'><tr id='wLcTs'><dt id='wLcTs'><q id='wLcTs'><span id='wLcTs'><b id='wLcTs'><form id='wLcTs'><ins id='wLcTs'></ins><ul id='wLcTs'></ul><sub id='wLcTs'></sub></form><legend id='wLcTs'></legend><bdo id='wLcTs'><pre id='wLcTs'><center id='wLcTs'></center></pre></bdo></b><th id='wLcTs'></th></span></q></dt></tr></i><div id='wLcTs'><tfoot id='wLcTs'></tfoot><dl id='wLcTs'><fieldset id='wLcTs'></fieldset></dl></div>
        • <tfoot id='wLcTs'></tfoot>

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

        • <legend id='wLcTs'><style id='wLcTs'><dir id='wLcTs'><q id='wLcTs'></q></dir></style></legend>

              <tbody id='wLcTs'></tbody>

              • 本文介绍了在 TensorFlow 2.0 中,如何查看数据集中的元素数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当我加载数据集时,我想知道是否有任何快速方法可以找到该数据集中的样本数或批次数.我知道如果我使用 with_info=True 加载数据集,我可以看到例如 total_num_examples=6000, 但如果我拆分数据集,则此信息不可用.

                When I load a dataset, I wonder if there is any quick way to find the number of samples or batches in that dataset. I know that if I load a dataset with with_info=True, I can see for example total_num_examples=6000, but this information is not available if I split a dataset.

                目前,我统计样本数如下,但想知道是否有更好的解决方案:

                Currently, I count the number of samples as follows, but wondering if there is any better solution:

                train_subsplit_1, train_subsplit_2, train_subsplit_3 = tfds.Split.TRAIN.subsplit(3)
                
                cifar10_trainsub3 = tfds.load("cifar10", split=train_subsplit_3)
                
                cifar10_trainsub3 = cifar10_trainsub3.batch(1000)
                
                n = 0
                for i, batch in enumerate(cifar10_trainsub3.take(-1)):
                    print(i, n, batch['image'].shape)
                    n += len(batch['image'])
                
                print(i, n)
                

                推荐答案

                如果可以知道长度,那么你可以使用:

                If it's possible to know the length then you could use:

                tf.data.experimental.cardinality(dataset)
                

                但问题是 TF 数据集本质上是延迟加载的.所以我们可能事先不知道数据集的大小.确实,完全有可能让一个数据集代表无限的数据集!

                but the problem is that a TF dataset is inherently lazily loaded. So we might not know the size of the dataset up front. Indeed, it's perfectly possible to have a dataset represent an infinite set of data!

                如果它是一个足够小的数据集,您也可以对其进行迭代以获得长度.我之前使用过以下丑陋的小结构,但它取决于数据集足够小,我们可以很高兴地加载到内存中,而且它实际上并不是对上面的 for 循环的改进!

                If it is a small enough dataset you could also just iterate over it to get the length. I've used the following ugly little construct before but it depends on the dataset being small enough for us to be happy to load into memory and it's really not an improvement over your for loop above!

                dataset_length = [i for i,_ in enumerate(dataset)][-1] + 1
                

                这篇关于在 TensorFlow 2.0 中,如何查看数据集中的元素数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
              • <i id='32C75'><tr id='32C75'><dt id='32C75'><q id='32C75'><span id='32C75'><b id='32C75'><form id='32C75'><ins id='32C75'></ins><ul id='32C75'></ul><sub id='32C75'></sub></form><legend id='32C75'></legend><bdo id='32C75'><pre id='32C75'><center id='32C75'></center></pre></bdo></b><th id='32C75'></th></span></q></dt></tr></i><div id='32C75'><tfoot id='32C75'></tfoot><dl id='32C75'><fieldset id='32C75'></fieldset></dl></div>
                    <bdo id='32C75'></bdo><ul id='32C75'></ul>
                      <tbody id='32C75'></tbody>

                    <small id='32C75'></small><noframes id='32C75'>

                    <tfoot id='32C75'></tfoot>
                      <legend id='32C75'><style id='32C75'><dir id='32C75'><q id='32C75'></q></dir></style></legend>