最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Store images instead of showing in a server - Stack Overflow

programmeradmin0浏览0评论

I am running the code found on this site in my server and I would like to store images instead of showing them since I have connected remotely with an ssh connection to my server via an SSH connection.

The code is for instance this one:

skip_tokens = [1]  # skip the special token for the start of the text <s>
inp = TextTokenInput(
  eval_prompt, 
  tokenizer,
  skip_tokens=skip_tokens,
)

target = "playing guitar, hiking, and spending time with his family."
attr_res = llm_attr.attribute(inp, target=target, skip_tokens=skip_tokens)
attr_res.plot_token_attr(show=True)

How to store the files locally instead of showing them?

I am running the code found on this site in my server and I would like to store images instead of showing them since I have connected remotely with an ssh connection to my server via an SSH connection.

The code is for instance this one:

skip_tokens = [1]  # skip the special token for the start of the text <s>
inp = TextTokenInput(
  eval_prompt, 
  tokenizer,
  skip_tokens=skip_tokens,
)

target = "playing guitar, hiking, and spending time with his family."
attr_res = llm_attr.attribute(inp, target=target, skip_tokens=skip_tokens)
attr_res.plot_token_attr(show=True)

How to store the files locally instead of showing them?

Share Improve this question edited Apr 4 at 23:40 desertnaut 60.5k32 gold badges155 silver badges182 bronze badges asked Mar 11 at 14:50 Jose RamonJose Ramon 5,39026 gold badges85 silver badges162 bronze badges 1
  • did you check documentation if it has function to save/write it in file? If it doesn't have function to save it then it may need to see if it gives access to varaibles with images and them save them. maybe it need to see source code for plot_token_attr() – furas Commented Mar 11 at 15:24
Add a comment  | 

1 Answer 1

Reset to default 1

I can't test it but ...

I checked source code and it uses matplotlib for this.

If you remove show=True then it shouldn't show it but it should only get fig, ax.

I think you could use matplotlib.pyplot.savefig(filename) to save it in file.

import matplotlib.pyplot as plt

# ... code  ...

attr_res.plot_token_attr()  # without `show=True
plt.savefig("output.png")
#plt.show()  # eventually show it after saving

Probably you can also use fig for this

fig, ax = attr_res.plot_token_attr()  # without `show=True
fig.savefig("output.png")
发布评论

评论列表(0)

  1. 暂无评论