gpt4 book ai didi

python - 如何在远程机器上保存实时数据图?

转载 作者:太空狗 更新时间:2023-10-29 20:24:58 26 4
gpt4 key购买 nike

我想通过 sshing 和检查图表来了解我的模型在训练(即实时数据方式)时的表现。

使用 animation.FuncAnimation 每次它在我的本地机器上更新时,我都能够保存(并覆盖)一个帧,如下所示:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def animate(i):
fig.clf()

plt.suptitle('Title here')

# actually parse model outputs and plot
values = np.random.random_integers(0, 100, (100,))
plt.plot(np.arange(len(values)), values, label='random')
plt.ylabel('demo data')
plt.grid()


plt.legend()
plt.xlabel('Epochs')
fig.savefig('Figure.png')


fig = plt.figure()
ani = animation.FuncAnimation(fig, animate, interval=10*60*1000)
plt.show()

在本地机器上使用它很好,因为 plt.show 调用了 $DISPLAY。但是,当在远程服务器上运行时(当然是通过 ssh),因为没有显示,我得到了 RuntimeError: Invalid DISPLAY variable。当通过 matplotlib.use('svg') 使用其他后端时,例如 svg。脚本在没有实际保存任何图像的情况下退出。

此外,我决定在 animate 函数中使用 plt.show()fig.savefig('Figure.png')是因为在调用 FuncAnimation 之后没有 plt.show() 函数,它不会在给定时间间隔后运行 animate。我试着用 plt.savefig 代替。

关于 fig.savefig('Figure.png'),在 animate 函数之外执行此操作会导致出现空白图像。我猜是因为我在 animate 函数开始时清除了图像。

所以,我的问题是:有没有办法像这样通过 ssh 使用 animation(或 FuncAnimation)保 stub 据实时数据生成的图形,直到发生某些事件(或也许是超时)?

最佳答案

作为网络服务器建议的替代方案,您可以使用 watchn 秒运行一次 scp 并将 png 复制到您的本地计算机.

类似于:

watch -n 5 scp user@remote:/path/to.png ./

每 5 秒复制一次文件。

或者使用rsync 只在实际改变时才复制。 (还有一些实用程序会在文件更改时使用 scprsync 将其复制到本地计算机。)

关于python - 如何在远程机器上保存实时数据图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49946830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com