Belval / TextRecognitionDataGenerator

A synthetic data generator for text recognition
MIT License
3.24k stars 966 forks source link

Pillow Version #315

Open rtaylo45 opened 1 year ago

rtaylo45 commented 1 year ago

Hello,

So i recently install trdg and was running into this issue when using the text generators:

File ~/Projects/TextRecognitionDataGenerator/trdg/utils.py:148, in get_text_height(image_font, text)
    144 def get_text_height(image_font: ImageFont, text: str) -> int:
    145     """
    146     Get the width of a string when rendered with a given font
    147     """
--> 148     return image_font.getsize(text)[1]

AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

Turns out that Pillow 10 got rid of this method as noted by this tensorflow post. Updating the requirements file to pillow<=9.5.0 fixes the issue.

Thanks, Zack

gigabitamin commented 10 months ago

I had the same issue, and I also resolved it by downgrading the version. I used the following command to install the libraries specified in the requirements.txt file:

pip install -r requirements.txt

The contents of the requirements.txt file were:

pillow>=7.0.0 requests>=2.20.0 opencv-python>=4.2.0.32 tqdm>=4.23.0 diffimg==0.2.3 arabic-reshaper==2.1.3 python-bidi==0.4.2 wikipedia>=1.4.0

When I checked my installed Python libraries, the version of pillow was 10.1.0. To resolve the issue, I downgraded it using the command:

pip install pillow==9.5.0

After this, I confirmed that everything was working correctly. During the installation, I received the following message related to the pillow library:

Requirement already satisfied: pillow>=7.0.0 in c:\anaconda3\envs\gigabitamin\lib\site-packages (from -r requirements.txt (line 1)) (10.1.0)

In my case, attempting to install via requirements.txt while pillow was already installed didn't automatically trigger the downgrade. It seems to have caused an issue because the installed version was the problematic latest version.

For situations like this, it would be helpful to have a warning in the installation message, suggesting a downgrade.

rtaylo45 commented 10 months ago

@gigabitamin It looks like they fixed the issue with this PR but its yet to be merged. I assume that this will be merged for future releases and having a warning message might not be necessary.

stweil commented 7 months ago

This issue is fixed in git master, so it can be closed.