1

I have built a model using keras and I can visualize it using keras visualizer, but I would like to change legend font size as it is too small in the resulting visualization. The code:

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)

The error I get when applying the third line in the code above:

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

Is there a way to change legend font size while visualizing CNN layers using keras visualizer? Thank you!

Kenan Morani
  • 141
  • 1
  • 9

1 Answers1

1

YOU HAVE to specify the path of the font . for example in my case i used hack font located in my home directory

font = ImageFont.truetype("/home/zied/fonts/Hack/Hack-Regular.ttf", 42, encoding="unic")

i tested it and it works

sbabti zied
  • 784
  • 5
  • 17