我试图设置批处理大小并运行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")