paulgavrikov / visualkeras

Visualkeras is a Python package to help visualize Keras (either standalone or included in TensorFlow) neural network architectures. It allows easy styling to fit most needs. This module supports layered style architecture generation which is great for CNNs (Convolutional Neural Networks), and a graph style architecture, which works great for most models including plain feed-forward networks.
MIT License
582 stars 67 forks source link

[BUG] Pillow 10.3.0 removed getsize() function so legend parameter do not work now #56

Closed EmilienLH closed 4 months ago

EmilienLH commented 4 months ago

Describe the bug The title essentially explains it. Since Pillow was upgraded to version 10.x, the getsize() function has been removed. This raises an error when attempting to use the legend=True parameter, as it makes a call to getsize().

Minimal Code To Reproduce

import visualkeras
from PIL import ImageFont
font = ImageFont.truetype('/usr/share/fonts/truetype/Lato-Regular.ttf', 32)

visualkeras.layered_view(model, to_file='model.png', legend=True, font=font).show() # write to disk

Expected behavior The ability to call the legend parameter without encountering any errors.

Screenshots image

Environment (please complete the following information):

Additional context I've read that this issue can be easily fixed by using either getbbox() or getlength() for Pillow 10.x.x. However, I'm unsure how extensively the code needs to be modified to fully resolve it.

edoardo-tam commented 4 months ago

As far as I can see, themaster branch was updated three months ago to fix this problem. There are two things you can do to solve your issue:

  1. Update the library using: pip install git+https://github.com/paulgavrikov/visualkeras
  2. Downgrade the Pillow version to 9.5.0 pip install Pillow<=9.5.0
Soontosh commented 4 months ago

@edoardo-tam's answer is correct, marking this as resolved. (will be updating pypi soon)