我試圖設置批處理大小並運行Autoencoder程序,因爲沒有足夠的內存來使用完整批處理。所以我試圖使用tf.train.batch
。但由於函數的參數是一個張量,我試圖用tf.convert_to_tensor
將np數組轉換爲張量。但是內存超過2GB,無法變成張量。我怎樣才能用小批量培訓?下面是 是我的代碼。在python tensorflow中劃分批處理
N_img=47000000
batch_size=100
X_train = np.zeros(shape=(N_img, Freq_LEN, LOOK_LEN, 1), dtype='float32')
x = tf.placeholder(tf.float32, [None, FRM_LEN/2,FRM_LEN/2,1]) #FRM_LEN=256
y = tf.placeholder(tf.float32, [None, FRM_LEN/2,FRM_LEN/2,1])
X_train=tf.convert_to_tensor(X_train)
X_train_batch= tf.train.batch(X_train,batch_size=batch_size)
print("Start training..")
for step in range(n_iters):
sess.run(optm, feed_dict={x: X_train_batch, y: X_train_batch, keepprob: 0.7})
if step % 100 == 0:
print(step,sess.run(cost, feed_dict={x: X_train_batch, y: X_train_batch, keepprob: 1}))
print("finish training")