我已经使用keras构建了一个模型,我可以使用keras可视化工具将其可视化,但我想更改图例字体大小,因为它在结果可视化中太小。代码:
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)当我应用上面代码中的第三行时,我得到了错误:
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图层时改变图例字体大小?谢谢!
发布于 2021-10-09 10:29:41
您必须指定字体的路径。例如,在我的示例中,我使用位于我的主目录中的hack字体
font = ImageFont.truetype("/home/zied/fonts/Hack/Hack-Regular.ttf", 42, encoding="unic")我测试了一下,它正常工作。
https://stackoverflow.com/questions/69505800
复制相似问题