You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

机器学习中如何实时可视化训练/测试数据及生成的图像与语音?

机器学习训练实时可视化方案与现有实现

我希望在机器学习训练过程中,实现实时可视化训练与测试数据,同时能实时查看生成的图像、听取生成的语音。下面是我目前已经完成的可视化实现:

现有可视化代码实现

1. GAN训练时的样本可视化代码

batch_size = 100
epochs = 30
init = tf.global_variables_initializer()
samples = []
with tf.Session() as sess:
    sess.run(init)
    for epoch in range(epochs):
        num_batches = mnist.train.num_examples // batch_size
        for i in range(num_batches):
            batch = mnist.train.next_batch(batch_size)
            batch_images = batch[0].reshape((batch_size, 784))
            batch_images = batch_images * 2 -1
            batch_z = np.random.uniform(-1,1,size=(batch_size, 100))
            _ = sess.run(D_trainer, feed_dict={real_images:batch_images, z:batch_z})
            _ = sess.run(G_trainer, feed_dict={z:batch_z})
        print("ON EPOCH {}".format(epoch))
        sample_z = np.random.uniform(-1,1, size=(1, 100))
        gen_samples = sess.run(generator(z, reuse=True), feed_dict={z:sample_z})
        samples.append(gen_samples)
new_samples = []
#saver = tf.train.Saver(var_list=g_vars)
with tf.Session() as sess:
    #saver.restore(sess,"...")
    for x in range(5):
        sample_z = np.random.uniform(-1,1, size=(1, 100))
        gen_samples = sess.run(generator(z, reuse=True), feed_dict={z:sample_z})
        new_samples.append(gen_samples)
plt.imshow(new_samples[0].reshape(28,28))

2. 情感分析实时折线图可视化代码(需在独立终端运行)

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
import time
style.use("ggplot")
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(i):
    pullData = open("twitter-out.txt","r").read()
    lines = pullData.split('\n')
    xar = []
    yar = []
    x = 0
    y = 0
    for l in lines[-200:]:
        x += 1
        if "pos" in l:
            y += 1
        elif "neg" in l:
            y -= 1
        xar.append(x)
        yar.append(y)
    ax1.clear()
    ax1.plot(xar,yar)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()

参考目标效果

我参考了YouTube视频中1:10:23-1:11:03的实时RNN-LSTM生成效果,希望能实现类似的实时可视化功能。

内容的提问来源于stack exchange,提问作者user6751157

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:17:33