0

I have a big issue with my CNN TensorFlow model, it seems to not be very good at its job, and I think it's not the model's fault but rather that the tensors being sent don't have the digits centred.

Here is a picture of a 6 which the model predicted as an 8

So, the question: Is there a library in python I can use to detect the digits in the cells rather than the current manual method?

GS343597
  • 13
  • 3
  • What kind of tensorflow model are you using to detect this? What was it trained on? – Nick ODell Nov 20 '22 at 21:36
  • @NickODell sorry for not mentioning that, it's trained on the MNIST handwritten digit dataset and I have a saved tensorflow keras model in the local directory. Do you think the issue is that the printed digits look different to the handwritten digits and if so would I have to train the model on more printed digits as well as handwritten? – GS343597 Nov 20 '22 at 21:41
  • That's probably the ideal fix, but there are other approaches you could take which are potentially less work. e.g. data augmentation, using neural network structures which are less sensitive to moving the image around. More specifically, what kind of keras model did you train? – Nick ODell Nov 20 '22 at 21:44
  • @NickODell Right. I think I remembering seeing data augmentation before but it slipped my mind - I'll definitely look into that. I don't fully understand the question of what kind of keras model as I'm quite a beginner. I guess it's a CNN? - I've done this in the model definition if this helps: model = keras.Sequential( and then I have a bunch of layers like Conv2d, Flatten, Dropout etc. Thanks again. – GS343597 Nov 20 '22 at 21:56
  • Mnist used a center-of-mass for pixels to center the digits. How to do that in Python: https://stackoverflow.com/questions/37448873/center-of-mass-of-pixels-in-grayscale-image – Nick ODell Nov 20 '22 at 21:57

1 Answers1

1

Thanks to NickODell's helpful comments, my solution is going to be to find the centre of mass of each image and shift the images to centre them.

Here is the link to the python solution I'm using:

center of mass of pixels in grayscale image

GS343597
  • 13
  • 3