PIL ImageFont Compatibility Issues in Visualkeras for Neural Network Visualization with Legends [BUG]
004Ajay opened this issue · comments
I got an error while trying to visualize the neural network with legends, using the same lines of code from the main readme, here
Code:
from PIL import ImageFont
font = ImageFont.truetype("arial.ttf", 32) # using comic sans is strictly prohibited!
visualkeras.layered_view(model, legend=True, font=font)
Error:
AttributeError Traceback (most recent call last)
Cell In[7], line 4
1 from PIL import ImageFont
3 font = ImageFont.truetype("arial.ttf", 32) # using comic sans is strictly prohibited!
----> 4 visualkeras.layered_view(model, legend=True, font=font)
File c:\Users\..\Python310\lib\site-packages\visualkeras\layered.py:194, in layered_view(model, to_file, min_z, min_xy, max_z, max_xy, scale_z, scale_xy, type_ignore, index_ignore, color_map, one_dim_orientation, background_fill, draw_volume, padding, spacing, draw_funnel, shade_step, legend, font, font_color)
191 if font is None:
192 font = ImageFont.load_default()
--> 194 text_height = font.getsize("Ag")[1]
195 cube_size = text_height
197 de = 0
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
I found that in Pillow 10.0.0 they have removed the ImageFont.getsize()
and suggested to use ImageFont.getbbox()
or ImageFont.getlength()
, when i tried using the getbbox()
a little legend is appearing, but we need the complete legend right?
Environment:
- OS: [e.g. Windows 11]
- Python [e.g. Python 3.10.11]
Stale issue message