簡體   English   中英

如何將jpeg數據加載,標記和提供給Tensorflow?

[英]How do you load, label, and feed jpeg data into Tensorflow?

我一直在嘗試將1750 * 1750圖像輸入Tensorflow,但在使用tf.image.decode_jpeg()函數將圖像轉換為Tensor之后,我不知道如何標記和提供數據。

目前,我的代碼是:

import tensorflow as tf
import numpy as np

import imageflow
import os, glob

sess = tf.InteractiveSession()

def read_jpeg(filename_queue):
 reader = tf.WholeFileReader()
 key, value = reader.read(filename_queue)

 my_img = tf.image.decode_jpeg(value)
 my_img.set_shape([1750, 1750, 1])
 print(value)
 return my_img

#####################################################
def read_image_data():
 jpeg_files = []
 images_tensor = []

 i = 1
 WORKING_PATH = "/Users/Zanhuang/Desktop/NNP/DATA"
 jpeg_files_path = glob.glob(os.path.join(WORKING_PATH, '*.jpeg'))

 for filename in jpeg_files_path:
    print(i)
    i += 1
    jpeg_files.append(filename)


 filename_queue = tf.train.string_input_producer(jpeg_files)

 mlist = [read_jpeg(filename_queue) for _ in range(len(jpeg_files))]

 init = tf.initialize_all_variables()

 sess = tf.Session()
 sess.run(init)

 images_tensor = tf.convert_to_tensor(images_tensor)


 sess.close()

現在,正如我之前所說,我需要提供和標記數據。 我已經看過CIFAR-10教程文件,但是他們將標簽存儲在一個文件中,我打算不這樣做。

我對Tensorflow很新,所以請盡可能詳細地保持響應。

謝謝!

根據您的嘗試,有幾個方向需要考慮。

  1. 如果您只想對任意JPEG文件進行推理(即不需要標簽),那么您可以按照classify_image.py的示例,將JPEG圖像輸入到預先訓練的Inception網絡中:

    github.com/tensorflow/models/blob/master/tutorials/image/imagenet/classify_image.py

  2. 如果您希望在JPEG圖像的小型自定義數據集上訓練(或微調)模型,那么請查看此示例,了解如何從一小組JPEG圖像中訓練模型。

    github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py

  3. 如果您希望在JPEG圖像的大型自定義數據集上訓練(或微調)模型,那么讀取許多單獨的JPEG文件將是低效的並且極大地減慢了訓練速度。

我建議按照初始/模型庫中描述的過程將JPEG圖像的目錄轉換為包含序列化JPEG圖像的分片RecordIO。

github.com/tensorflow/models/blob/master/research/inception/inception/data/build_image_data.py

有關運行轉換腳本的說明,請訪問:

github.com/tensorflow/models/blob/master/research/inception/README.md#how-to-construct-a-new-dataset-for-retraining

運行轉換后,您可以使用/復制初始/模型使用的圖像預處理管道。

github.com/tensorflow/models/blob/master/research/inception/inception/image_processing.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM