carolreis / mathreader

An API that recognizes handwritten mathematical expressions through the use of a Convolutional Neural Network, to facilitate the input ofmathematical notation in computational devices.
GNU General Public License v3.0
23 stars 4 forks source link

Input image dimension requirements unclear #2

Open 32-git opened 1 week ago

32-git commented 1 week ago

Hi. I am using this repo as a part of my project. And I am currently having a problem with the dimensions of the image I pass to the HME recognizer.

If I use the original image size, I get the following error: Exception: Kernel shape must have the same length as input, but received kernel of shape (3, 3, 1, 32) and input of shape (None, None, 28, 28, 1).

In my attempts to resize the image, I have to go down to sizes such as 120x120 to avoid getting the above error. But when I go down to that image size, then the handwritten math is barely recognizable.

So instead of constantly guessing, I wanted to know what the actual requirements of the model are regarding image size and whether it would be possible to pass larger images (e.g. 600x600) to the model as well.

Thanks in advance!

carolreis commented 2 days ago

Hi! Just to give you a feedback: I was in a conference these last weeks, I just came back. Within a few days I'll take a look and help you!

carolreis commented 2 days ago

Meanwhile, can you give examples of your images? @32-git

32-git commented 2 days ago

Hi! Thanks for the reply and my apologies if i disturbed you. My images may look something like this

image

or this

image

The width of the image may vary as shown above, based on the browser window size when drawing.

Now I would genuinely appreciate it if you could let me know whether these images are fine. If not, what should I pay attention to when passing the images to the model?

carolreis commented 2 days ago

Hi! Don't worry, it's ok to ask me some help.

I'll try to use your images. Did you take a look carefully at the code I used as example?

I'll let you know my results and see what the problem is

But apparently these images should be fine

32-git commented 2 days ago

Great! If the images should be fine, that's a good start. I have in fact looked at your example code and that's what I based my approach off of:

from mathreader import api
import base64 as b64
import sys

hme_recognizer = api.HME_Recognizer()

def pass_image(image):
  try:
    hme_recognizer.load_image(image)
    expression, img = hme_recognizer.recognize()
    sys.stdout.write(f"{expression}")
  except Exception as e:
    sys.stdout.write(f'Exception: {e}')

try:
  data_url = sys.argv[1]
  header, encoded = data_url.split("base64,", 1)
  pass_image(encoded)

except Exception as err:
  print(f'Exception: {err}')

As I said, the error that I mentioned in my first message is what I receive. Although if it helps I could also paste the entire output I get, which shows all the steps of when the code executes.