首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在可视化Keras模型时更改图例字体大小时出现错误?

为什么在可视化Keras模型时更改图例字体大小时出现错误?
EN

Stack Overflow用户
提问于 2021-10-09 10:20:25
回答 1查看 88关注 0票数 1

我已经使用keras构建了一个模型,我可以使用keras可视化工具将其可视化,但我想更改图例字体大小,因为它在结果可视化中太小。代码:

代码语言:javascript
复制
import visualkeras
from PIL import ImageFont
font = ImageFont.truetype("arial.ttf", 42, encoding="unic")
visualkeras.layered_view(model, spacing=5, font=font, legend=True, color_map=color_map)

当我应用上面代码中的第三行时,我得到了错误:

代码语言:javascript
复制
font = ImageFont.truetype("arial.ttf", 42, encoding="unic")
Traceback (most recent call last):

      File "<ipython-input-58-cde9b5409d9c>", line 1, in <module>
        font = ImageFont.truetype("arial.ttf", 42, encoding="unic")
    
      File "/home/idu/.local/lib/python3.6/site-packages/PIL/ImageFont.py", line 855, in truetype
        return freetype(font)
    
      File "/home/idu/.local/lib/python3.6/site-packages/PIL/ImageFont.py", line 852, in freetype
        return FreeTypeFont(font, size, index, encoding, layout_engine)
    
      File "/home/idu/.local/lib/python3.6/site-packages/PIL/ImageFont.py", line 212, in __init__
        font, size, index, encoding, layout_engine=layout_engine
    
    OSError: cannot open resource

有没有办法在使用keras可视化工具可视化CNN图层时改变图例字体大小?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2021-10-09 10:29:41

您必须指定字体的路径。例如,在我的示例中,我使用位于我的主目录中的hack字体

代码语言:javascript
复制
font = ImageFont.truetype("/home/zied/fonts/Hack/Hack-Regular.ttf", 42, encoding="unic")

我测试了一下,它正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69505800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档