我有一个png文件目录。有一个火车文件夹和测试文件夹。在火车文件夹中,我有10个文件夹作为10个标签[0 -9]。每个文件夹包含该标签的png文件。我想在张量流中加载它们进行训练。我是张量流的新手,我很难完成这件事
我正在使用anaconda(py ver 3.5)
import tensorflow as tf
filename_queue = tf.train.string_input_producer(
tf.train.match_filenames_once("./images/*.jpg"))
image_reader = tf.WholeFileReader()
我尝试过使用它但可以使它工作。它只加载1张图片
答案 0 :(得分:0)
虽然它为我工作。你能运行这个脚本吗? (更新以获得标签)
.permit
档案目录
accountSid = "XXXX"
authToken = "XXXX"
baseUrl = "https://api.twilio.com"
smsUrl = baseUrl & "/2010-04-01/Accounts/" & accountSid & "/SMS/Messages"
' setup the request and authorization
Set http = CreateObject("MSXML2.XMLHTTP.6.0")
http.open "POST", smsUrl, False, accountSid, authToken
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
' message parameters
from = "XXX" ' the number to send the message from
recipient = "XXX" ' the number to send the message to
body = "Sending SMS is easy with Twilio!" ' message contents
Set sendbot=CreateObject(System.Web.HttpUtility)
postData = "From=" & sendbot.URLEncode(from)
postData = postData & "&To=" & sendbot.URLEncode(recipient)
postData = postData & "&Body=" & sendbot.URLEncode(body)
' send the POST data
http.send postData
' optionally write out the response if you need to check if it worked
' Response.Write http.responseText
' clean up
Set http = Nothing
输出:
import tensorflow as tf
filename_queue = tf.train.string_input_producer(
tf.train.match_filenames_once("/home/xxx/Desktop/stackoverflow/images/*/*.png"))
image_reader = tf.WholeFileReader()
key, image_file = image_reader.read(filename_queue)
S = tf.string_split([key],'/')
length = tf.cast(S.dense_shape[1],tf.int32)
# adjust constant value corresponding to your paths if you face issues. It should work for above format.
label = S.values[length-tf.constant(2,dtype=tf.int32)]
label = tf.string_to_number(label,out_type=tf.int32)
image = tf.image.decode_png(image_file)
# Start a new session to show example output.
with tf.Session() as sess:
# Required to get the filename matching to run.
tf.initialize_all_variables().run()
# Coordinate the loading of image files.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in xrange(6):
# Get an image tensor and print its value.
key_val,label_val,image_tensor = sess.run([key,label,image])
print(image_tensor.shape)
print(key_val)
print(label_val)
# Finish off the filename queue coordinator.
coord.request_stop()
coord.join(threads)