TextRecognitionDataGenerator icon indicating copy to clipboard operation
TextRecognitionDataGenerator copied to clipboard

Getting handwritten model to work in Python

Open ecatkins opened this issue 6 years ago • 3 comments

Just some things I have observed trying to get the handwritten model to work in Python (after pip install). I am happy to make a pull request if these are desired changes

  1. The model in the GitHub repo isn't installed as part of the pypi package. I git cloned and copied and pasted the handwritten_model directory across, maybe just a note in the Readme to do this?

  2. I had to change the path references to the model, to make them work not matter where you were running the code from i.e.

cd = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(cd, os.path.join("handwritten_model", "translation.pkl")), "rb") as file:
    translation = pickle.load(file)
  1. I was getting the error TypeError: argument 1 must be read-only bytes-like object, not memoryview when trying to generate text. I changed some of the code in the generate method, see below. I have no idea why this seems to work for me and not the existing code base?? But I've had the same error (with the same fix) across both Linux and Mac
 s, (width, height) = canvas.print_to_buffer()
 image = Image.frombytes(
                "RGBA", (width, height), s
            )

ecatkins avatar Sep 04 '19 14:09 ecatkins

1 & 2: This is not an often used feature and I can't test it in Travis. Clearly I broke it when I created the PyPi package.

3: Could you run pip3 freeze and post the results? I am not able to reproduce it on my side.

I'll try to address these issues shortly, thank you for opening an issue.

Belval avatar Sep 04 '19 14:09 Belval

Apologies, I'm just working in my all purpose environment, so I've dumped the whole thing in a text file below.

I imagine the important ones are:

matplotlib==3.1.1
tensorflow==1.14.0
Pillow==6.1.0

trdg_requirements.txt

ecatkins avatar Sep 04 '19 19:09 ecatkins

Thanks @ecatkins for your findings. I made a pull request for this: https://github.com/Belval/TextRecognitionDataGenerator/pull/117. I also added compatibility for TF 1.15 and fix for getting the handwritten text output (no image mask was found). Regards

nicolasmetallo avatar Feb 04 '20 16:02 nicolasmetallo