• <legend id='ckHo7'><style id='ckHo7'><dir id='ckHo7'><q id='ckHo7'></q></dir></style></legend>
      <bdo id='ckHo7'></bdo><ul id='ckHo7'></ul>

    1. <small id='ckHo7'></small><noframes id='ckHo7'>

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

      1. <tfoot id='ckHo7'></tfoot>

        从图像本地目录创建 tensorflow 数据集

        Create tensorflow dataset from image local directory(从图像本地目录创建 tensorflow 数据集)
        <legend id='mPQXh'><style id='mPQXh'><dir id='mPQXh'><q id='mPQXh'></q></dir></style></legend><tfoot id='mPQXh'></tfoot>
          <tbody id='mPQXh'></tbody>
              <bdo id='mPQXh'></bdo><ul id='mPQXh'></ul>
            • <i id='mPQXh'><tr id='mPQXh'><dt id='mPQXh'><q id='mPQXh'><span id='mPQXh'><b id='mPQXh'><form id='mPQXh'><ins id='mPQXh'></ins><ul id='mPQXh'></ul><sub id='mPQXh'></sub></form><legend id='mPQXh'></legend><bdo id='mPQXh'><pre id='mPQXh'><center id='mPQXh'></center></pre></bdo></b><th id='mPQXh'></th></span></q></dt></tr></i><div id='mPQXh'><tfoot id='mPQXh'></tfoot><dl id='mPQXh'><fieldset id='mPQXh'></fieldset></dl></div>
                • <small id='mPQXh'></small><noframes id='mPQXh'>

                  本文介绍了从图像本地目录创建 tensorflow 数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在本地有一个非常庞大的图像数据库,数据分布就像每个文件夹都包含一个类的图像.

                  I have a very huge database of images locally, with the data distribution like each folder cointains the images of one class.

                  我想使用 tensorflow 数据集 API 来批量获取数据,而无需将所有图像都加载到内存中.

                  I would like to use the tensorflow dataset API to obtain batches de data without having all the images loaded in memory.

                  我尝试过这样的事情:

                  def _parse_function(filename, label):
                      image_string = tf.read_file(filename, "file_reader")
                      image_decoded = tf.image.decode_jpeg(image_string, channels=3)
                      image = tf.cast(image_decoded, tf.float32)
                      return image, label
                  
                  image_list, label_list, label_map_dict = read_data()
                  
                  dataset = tf.data.Dataset.from_tensor_slices((tf.constant(image_list), tf.constant(label_list)))
                  dataset = dataset.shuffle(len(image_list))
                  dataset = dataset.repeat(epochs).batch(batch_size)
                  
                  dataset = dataset.map(_parse_function)
                  
                  iterator = dataset.make_one_shot_iterator()
                  

                  image_list 是一个列表,其中添加了图像的路径(和名称),而 label_list 是一个列表,其中每个图像的类都以相同的顺序添加了.

                  image_list is a list where the path (and name) of the images have been appended and label_list is a list where the class of each image has been appended in the same order.

                  但是 _parse_function 不起作用,我记录的错误是:

                  But the _parse_function does not work, the error that I recibe is:

                  ValueError:形状必须为 0 级,但对于输入形状为 [?] 的file_reader"(操作:ReadFile")为 1 级.

                  ValueError: Shape must be rank 0 but is rank 1 for 'file_reader' (op: 'ReadFile') with input shapes: [?].

                  我已经用谷歌搜索了错误,但对我没有任何作用.

                  I have googled the error, but nothing works for me.

                  如果我不使用地图功能,我只是记录图像的路径(存储在 image_list 中),所以我认为我需要地图功能来读取图像,但我无法做到有效.

                  If I do not use the map function, I just recibe the path of the images (which are store in image_list), so I think that I need the map function to read the images, but I am not able to make it works.

                  提前谢谢你.

                      def read_data():
                          image_list = []
                          label_list = []
                          label_map_dict = {}
                          count_label = 0
                  
                          for class_name in os.listdir(base_path):
                              class_path = os.path.join(base_path, class_name)
                              label_map_dict[class_name]=count_label
                  
                              for image_name in os.listdir(class_path):
                                  image_path = os.path.join(class_path, image_name)
                  
                                  label_list.append(count_label)
                                  image_list.append(image_path)
                  
                              count_label += 1
                  

                  推荐答案

                  错误在这一行 dataset = dataset.repeat(epochs).batch(batch_size) 你的管道添加了batchsize作为维度输入.

                  The error is in this line dataset = dataset.repeat(epochs).batch(batch_size) Your pipeline adds batchsize as a dimension to input.

                  您需要在这样的地图功能之后批处理您的数据集

                  You need to batch your dataset after map function like this

                      dataset = tf.data.Dataset.from_tensor_slices((tf.constant(image_list), tf.constant(label_list)))
                      dataset = dataset.shuffle(len(image_list))
                      dataset = dataset.repeat(epochs)
                      dataset = dataset.map(_parse_function).batch(batch_size)
                  

                  这篇关于从图像本地目录创建 tensorflow 数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据框制作线图?)
                    <tbody id='0tEIQ'></tbody>
                    <bdo id='0tEIQ'></bdo><ul id='0tEIQ'></ul>

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

                          <small id='0tEIQ'></small><noframes id='0tEIQ'>

                            <tfoot id='0tEIQ'></tfoot>