I know I probably haven’t been posting as frequently as many of you would like or even at my normal quality because… well, like for many of you, this year has just sucked!
Someone I’ve known my whole life died recently, not from the virus though it didn’t help things.
She went in for a “routine” procedure where they needed to use general anesthesia and there were “complications” during the procedure. Something to do with her heart but if I’m being honest, I don’t know all the details at this time.
Also, I’m not sure how by anyone’s definition anything involving anesthesia is routine?
An ambulance was called and she was rushed to the hospital, long story short, despite being otherwise fine when she went in, she never woke up from her coma. 😥
The hospital is/was on lock down like everyone else and so friends and family were unable to visit her before she died.
Her family intends to sue the Dr. for malpractice, personally… I think they should!
To add insult to injury, she was cremated without a funeral due to the whole pandemic social distancing BS that I’m just about ready to tell the government to go fuck itself over! 😦
I’m sorry, do my harsh words offend you? SHE DIED ALONE! That offends me!
Going forward, my advice… any procedure where they need to administer general anesthesia to you… or maybe any procedure at all… make sure it’s in a hospital or hospital adjacent (NOT A CLINIC) because those minutes waiting for an ambulance really do mean your life!
And if your doctor is like, “No worries this is routine… I’ve done this a thousand times”, maybe think carefully before putting your trust in that person.
Yes, we want doctors that are confident in their ability to treat us but make sure that it is confidence and not complacent hubris!
Further, no procedure is truly “routine” and a doctor, of all people, should know that and act accordingly!
“Primum non nocere”
Regardless of the historical veracity of that quote, does the spirit of that principle still not apply?
Look, I’m not saying this to detract from the important life saving work doctors and medical workers do every day, it’s just that this is part of what’s going on in my life right now (and for many of you as well) and I’m sharing because I guess that’s what you do when you have a blog.
Additionally, less close to home, though still another terrible loss, John Horton Conway, notable math hero to geeks and nerds alike died as a result of complications from his contracting the Covid-19 virus. 😦
I’ve previously written a little about Conway’s work in my ancestor simulations series of posts.
Mysterious Game of Life Posts:
- Ancestor Simulations Conway’s Mysterious Game Of Life
- Ancestor Simulations Conway’s Mysterious Rules For Life
- Ancestor Simulations Building Conway’s Mysterious Game
- Ancestor Simulations Playing Conway’s Mysterious Game
But that only scratches the surface of his work and famously Conway’s Game of Life was perhaps his least favorite but most well known work among non-mathematicians and it would both amuse and bug him if I only mentioned his game of life here so I’m not going to list his other accomplishments.
I’ll have a little chuckle off camera on his behalf. 😛
He really was a math genius and you would learn a lot of interesting, not to mention surreal… but I’ve said too much, ideas by reading about his accomplishments, which I encourage you to do!
In any case, people I know and admire need to stop dying because its killing me… not to mention my ratings and readership because I keep talking about it! 😛
I may have a terribly dark sense of humor at times, but going forward I demand strict adherence from all of you to the Oasis Doctrine! 😥
Oh, and speaking of pretentious art…
The OCR 2 Wallpaper
The original OCR didn’t exactly have a wallpaper but I did create an image/logo to go along with the project and its blog posts:
For the reason you might think I made it look like an eye… because it looks like an non-evil Hal 9000! 😛
Also, I like the idea of depicting a robotic eye in relation to AI and neural networks because, even though I am not superstitious in any way, it carries some of the symbology of Illuminati, “The gaze of the Beholder”, “The Eye of Providence”, “The Evil Eye”, The Eye of Horus, The Eye of Ra, Eye of newt and needle… sorry. 😛
In this case, the eye of a robot invokes a sense of literal “Deus ex machina” (God from the machine) and it illustrates some peoples fears of “The Singularity” and of the possibility of an intelligence that is so much greater than our own that it calls in to question our ability to even comprehend it… hmmm… is that too lovecraftian? 😛
Anyway, because I enjoy the thought provoking symbology (maybe it’s just me), I wanted to keep the same concept of the robot eye but update it to look a little less like a simple cartoon to subtly imply it’s a more advanced version of OCR but that it still fundamentally does the same thing, which is most of the reasoning behind this wallpaper.
In any case, I hope you enjoy it.
If you’d like the wallpaper with the feature image text here’s that version.
So I guess having shared a few of the recent tragedies in my personal life and a couple of wallpapers, we should probably get mogating and talk about the point of today’s post!
We’re going to look at doing hand-written number (0-9) Optical Character Recognition using the MNIST database.
OCR 2 – The MNIST Dataset with PHP and FANN
I was recently contacted by a full-stack developer who wanted advice on creating his own OCR system for “stickers on internal vehicles”.
I think he means, some kind of warehouse robots?
He had seen my OCR ANN and seemingly preferred to work with PHP over Python, which if I’m being honest… I can’t exactly argue with!
PHP is C++ for the web and powers like almost 80-90% of the internet so it should come as no surprise to anyone (even though it does) that there are people who want to use it to build bots! 😛
But, if you would rather work with a different language there is a better than decent chance FANN has bindings for it so you should be able to use the ANN’s even if you are not using PHP.
So anyway, he gave me a dollar for my advice through Patreon and we had a brief conversation over messaging where I offered him a few suggestions and walked him through getting started.
Ultimately, because he lacks an AI/ML background and/or a sufficient familiarity with an AI/ML workflow he wasn’t very confident about proceeding so I recommended he follow my existing tutorials which should help him learn the basics of how to proceed.
Now here’s the thing, even among people who like my content and value my efforts, few people are generous enough to give me money for my advice and when they do, I genuinely appreciate it! 🙂
So, as a thank you I want to offer another (more complete) example of how to use a neural network to do OCR.
If he followed my advice, he should be fairly close to being ready for a more complete real world OCR ANN example (assuming he is still reading 😛 ) but if not, his loss is still your gain!
Today’s code implements OCR using the MNIST dataset and I demonstrate a basic form of pooling (though the stride is not adjustable as is) and I show convolutions using the GD image library, image convolution function and include 17 demonstration kernel matrices that you can experiment with, though not all are relevant or necessary for this project.
This is still very basic but everything you need to get started experimenting with OCR is here.
Having said that, in all honesty, to accomplish your goal requires building your own dataset and modifying the code I present here to meet your needs.
Neither are exactly hard but will require significant time and dedication to testing and refining your processes.
Obviously that’s not something I can cover in a single post or even assist you with for only a dollar, but since so few people show me the kindness and consideration you have, at a time of shrinking economies no less, I wanted to offer you this working OCR prototype to help you along your way.
1. Download the MNIST dataset (link below, but it’s in the GitHub repo too).
2. Unpack/Export the data from the files to images and labels.
(technically we could even skip the images and go directly to a training file but I think it’s nice to have the images and labels in a human viewable format)
3. Create training and test data from images and labels.
4. Train the network.
5. Test the network.
The MNIST Dataset
MNIST stands for Modified National Institute of Standards and Technology database.
And since I’m still recovering from last nights food poisoning due to the Chicken à la Nauseam we’re just going to use Wikipedia’s introduction to MNIST.
It’s easily as good as anything I could write and doesn’t require me actually write it so…
“It’s a large database of handwritten digits that is commonly used for training various image processing systems.”
It also says:
“It was created by “re-mixing” the samples from NIST’s original datasets. The creators felt that since NIST’s training dataset was taken from American Census Bureau employees, while the testing dataset was taken from American high school students, it was not well-suited for machine learning experiments. Furthermore, the black and white images from NIST were normalized to fit into a 28×28 pixel bounding box and anti-aliased, which introduced grayscale levels.”
Here’s 500 pseudo-random MNIST sample images:
I randomly selected 500 1’s, 3’s and 7’s and composited them into this 1337 animation. 😛
Seriously though, today we will be training a bot to identify which hand-written number (0-9) each 28×28 px image contains and then test the bot using images it hasn’t previously seen.
Our bot will learn using all 60K labeled training images and we’ll test it using the 10,000 labeled test images.
Here’s the wiki article if you would like to learn more about the database.
MNIST WIKI: https://en.wikipedia.org/wiki/MNIST_database
And as I said above, I’ve included the database in the GitHub repo but you can download it again from the original source if you prefer.
Original MNIST Download: http://yann.lecun.com/exdb/mnist/