我是tensorflow的新手,我正在嘗試創建堆疊稀疏降噪自動編碼器模型。我已經找到了一種方法來加載我的訓練(和測試)集,通過這裏和github的例子,但我不能用它們作爲張量來執行所需的乘法等等(此代碼僅用於加載圖像)如何在張量流中實現RGB圖像張量?
import tensorflow as tf
import glob
import numpy as np
from PIL import Image as im
im_list = []
#LOAD ALL SETS
training_set = []
training_set = glob.glob("folder/training_set/*.jpg")
testing_set = []
testing_set = glob.glob("folder/corrupted/*.jpg")
# testing my code only for the training set
filename_queue = tf.train.string_input_producer(training_set)
reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)
#data = tf.image.decode_jpeg(value)
data = tf.decode_raw(value, tf.uint8)
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
#sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range (196):
print i
m_key = sess.run([key,data])
im_list.append(m_key[1])
coord.request_stop()
coord.join(threads)
通過使用此代碼,我設法將所有圖像保存爲包含數據的uint8數組列表,但其大小從〜800到〜1000。我的圖片大小爲32x32x3,因此缺少一些東西。
我想他們另一種方式是:
filename_queue = tf.train.string_input_producer(training_set)
image_reader = tf.WholeFileReader()
_, image_file = image_reader.read(filename_queue)
imagee = tf.image.decode_jpeg(image_file)
#tf.cast(imagee, tf.float32)
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
image = sess.run(imagee)
imaginar = image.astype(np.float32)
#train_step.run(feed_dict={x: imaginar, y_: imaginar_test})
coord.request_stop()
coord.join(threads)
和IM嘗試計算
y = tf.matmul(x,W) + b
h_x_s = tf.sigmoid(y)
h_x = tf.matmul(h_x_s,W_) + b_
y_xi = tf.sigmoid(h_x)
這樣,我的圖片是32x32x3 numpy的陣列,但我不能找到一種方法,將其保存爲張量所以tf.matmul的作品。我總是得到關於我的數組的非擬合形狀的錯誤。
# VARIABLES
x= tf.placeholder(tf.float32,[32, 32, 3])
y_ = tf.placeholder(tf.float32,[32, 32, 3])
W = tf.Variable(tf.zeros([32,32,3]))
b = tf.Variable(tf.zeros([32,32,3]))
W_ = tf.Variable(tf.zeros([32,32,3]))
b_= tf.Variable(tf.zeros([32,32,3]))
(不成功的嘗試)
我應該如何加載(和解碼)我的圖片,並應我的變量和佔位符是什麼尺寸?任何幫助將非常感激!
謝謝:)