这是我的代码
以tf.Session()作为会话:
sess.run(tf.global_variables_initializer(), feed_dict={keep_prob : 0.9})
for epoch in range(n_epochs):
# Random shuffling
np.random.shuffle(train_total_data)
train_data_ = train_total_data[:, :-mnist_data.NUM_LABELS]
# Loop over all batches
for i in range(total_batch):
# Compute the offset of the current minibatch in the data.
offset = (i * batch_size) % (n_samples)
batch_xs_input = train_data_[offset:(offset + batch_size), :]
batch_xs_target = batch_xs_input
# add salt & pepper noise
if ADD_NOISE:
batch_xs_input = batch_xs_input * np.random.randint(2, size=batch_xs_input.shape)
batch_xs_input += np.random.randint(2, size=batch_xs_input.shape)
_, tot_loss, loss_likelihood, loss_divergence = sess.run(
(train_op, loss, neg_marginal_likelihood, KL_divergence),
feed_dict={x_hat: batch_xs_input, x: batch_xs_target, keep_prob : 0.9})
# print cost every epoch
print("epoch %d: L_tot %03.2f L_likelihood %03.2f L_divergence %03.2f" % (epoch, tot_loss, loss_likelihood, loss_divergence))
# if minimum loss is updated or final epoch, plot results
if min_tot_loss > tot_loss or epoch+1 == n_epochs:
min_tot_loss = tot_loss
# Plot for reproduce performance
if PRR:
y_PRR = sess.run(y, feed_dict={x_hat: x_PRR, keep_prob : 1})
y_PRR_img = y_PRR.reshape(PRR.n_tot_imgs, IMAGE_SIZE_MNIST, IMAGE_SIZE_MNIST)
PRR.save_images(y_PRR_img, name="/PRR_epoch_%02d" %(epoch) + ".jpg")
# Plot for manifold learning result
if PMLR and dim_z == 2:
y_PMLR = sess.run(decoded, feed_dict={z_in: PMLR.z, keep_prob : 1})
y_PMLR_img = y_PMLR.reshape(PMLR.n_tot_imgs, IMAGE_SIZE_MNIST, IMAGE_SIZE_MNIST)
PMLR.save_images(y_PMLR_img, name="/PMLR_epoch_%02d" % (epoch) + ".jpg")
# plot distribution of labeled images
z_PMLR = sess.run(z, feed_dict={x_hat: x_PMLR, keep_prob : 1})
PMLR.save_scattered_image(z_PMLR,id_PMLR, name="/PMLR_map_epoch_%02d" % (epoch) + ".jpg")
它是从此仓库中提取的: https://github.com/hwalsuklee/tensorflow-mnist-VAE
我想生成一个像这样的视频:https://www.youtube.com/watch?v=Sc7RiNgHHaE 在10:18
所以我要在设定的时间间隔内打印演示图像吗? 另外,我将如何保存np数组并对解码器进行编码? 接下来,我将如何训练许多图像? 另外,我不知道如何保存模型并将其重新用于编码新的未经训练的图像。