Search

Geek Girl Joy

Artificial Intelligence, Simulations & Software

Month

April 2020

OCR 2 – The MNIST Database

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”

~Hippocrates… (allegedly)

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:

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.

OCR 2 Wallpaper
OCR 2 Wallpaper

If you’d like the wallpaper with the feature image text here’s that version.

OCR 2 Wallpaper (with text)
OCR 2 Wallpaper (with text)

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.

Our Method

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…

Wikipedia says:

“It’s a large database of handwritten digits that is commonly used for training various image processing systems.[1][2]”

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.[5] 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.[5]”

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. ๐Ÿ˜›

500 random 1337 MNIST images.
500 random 1337 MNIST images

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/

Continue reading “OCR 2 – The MNIST Database”

Are Makeshift Masks Safe?

Last week I took a “mental day” off from my blog because I was feeling like many of you and I’m not saying that crying is an effective use of my personal reserves of water and electrolytes long term… just that sometimes it just feels really good! ๐Ÿ˜›

I was able to upload my simulation code that I mentioned in my last post to GitHub so it wasn’t like I got nothing accomplished!

Also, it’s nice to see it was cloned a few times leading me to hope that it is helping people, though we’ll discuss the simulation later in this post. ๐Ÿ™‚

In unrelated but relevant news about some “notable playthroughs” that ended in “game overs” in the the last couple weeks.

There comes a time in life when even the gambling mavericks among us knows when to “fold em” and “cash out”, after all the dealin’ is done… sadly we lost both Kenny Rodgers and Bill Withers just ten days apart! ๐Ÿ˜ฆ

And I know, I know, I know, I…,ย  I know, I know! Hey, I oughta this leave the young topic alone!

It’s just that, ain’t no sunshine when their gone, only darkness every day… and as the old adage goes “death comes in threes” so, I really started to worry… about Betty White! ๐Ÿ˜›

Well, that is before I remembered she’s probably immortal and logic willing, will almost certainly outlast us all!

Gallows humor aside, I know a lot of you are here just for the art and maybe a few laughs if I could ever manage to write something funny, so… with that in mind here’s today’s edition of Joy Finger Paints.

Joy Survives Post-Apocalyptia Image Set:

“But.. I’m just here for the code!”

Look…

I’ll totally admit that over the years I’ve maybe played a little too much Fallout and 7 Days to Die but I swear I don’t just play apocalyptic games, I just happen to enjoy them! ๐Ÿ˜›

And… as a stereotypical totally a self-absorbed millennial…

I egotistically had to make a set of post-apocalyptic posters of myself enjoying this spring 2020’s latest in high fashion!

In fact… here’s a few “geek sneak peeks” from my upcoming spring/summer lookbook.

The whole collection is made from tyvek and acetate for his or her pleasure!

Note the zombie resistant face shield for that extra level of protection when you can’t avoid adventuring through crowds of infected!

These thumbnails link to my Patreon where you can view and download them for free.

Each fabulous look depicts a variety of different scenarios that make up the “post-apocalyptic” genera.

You can tell they are different because the colors change! ๐Ÿ˜›

Pretty sure one of them could take place in the post apocalypticย  Rick and Morty episode Rickmancing the Stone.

Hmmm… now that I think about it though, the images could depict the various stages of my descent (not the game, though oddly in that case a virus is still involved) into the clutches of the zombie virus… Oh wow! I just realized that I am one of the Hazmat Zombies in 7 Days to Die… huh, looks like I made it between 5 to 8 days depending on if you include the blue pix! ๐Ÿ˜›

 

 

Now if you are wondering why I only have the thumbnails here instead of the full images, it’s basically because Patreon offers me unlimited storage (more or less)ย  whereas I have a finite storage amount on my blog and I feel the images have a certain charm close up, soย  I didn’t resize them down from 1920 x 2300 px (~2.8 MB each).

Which is your favorite? Leave a comment and let me know.

Now to more consequential affairs!

An โบ-๐šถ, “Alpha” to “Omicron”… April Adage

My atrocious affectations aside, there are ardent appeals for appropriations of PPE because no matter how assiduous Alan Alda’s auroral attempts are to agilely assuage the afflicted and arrest the arduous apocalyptic antecedent (#AnnihilateTheArc), the aforesaid aftermath is antipodal to an aspired aftermost, although… assorted avowal assertions are advanced that absent the accoutrements, they will accomplish our ambition to attack, anull, abolish and abrogate the affliction!

As much, according to alleged accounts, all anterior aid attendants are apparently anticipating the assumptive acquisition of the ailment and await apprehensively the AbEnd of, albeit abide, the advancing abstinence of abatement appliance, articles and apparatus.

Alright, all appurtenances advised… I’m not saying that’s going to happen and it probably wont this time (most places, they did say 3M had to produce for domestic use first and besides, weren’t some of those claims of lack of PPE debunked? Not saying all were but… perhaps it’s not as bad as some claims have suggested?), but that is enough of a reason to treat this and all future pandemics seriously!

Dang, er… I mean, abhorrence! I should have aforesaid “accept and administer the all-over-anguish as acute admonishment against all approaching adversity!” ๐Ÿ˜›

Absolutely astonishing! I acknowledge and I am aware that aloof arrogant arguments are audacious abuses of my alienated admirers allotment of time in the annals of anthology who are altogether accustomed to an assured amount of assertive acumen on my account, as such… I am now going to abandon my “a” aligned address and antics in accommodation of alacrity… admitting as much that, arguably I could act abundantly to advance that aesthetic if my appetite allowed me the agency and abandon to be adrift.

Okay, ancillary absurdity aside… ๐Ÿ˜›

Are Makeshift Masks… Safe?

Whether you are struggling to escape Raccoon City and face countless hoards of infected or just need to get through the pandemic du jour you may find the need to rely on makeshift personal protective equipment like cloth masks to ensure your personal safety.

Also, everyone seems to forget about eye covering but that’s out of the scope of today’s discussion. ๐Ÿ˜›

And… provided I didn’t delete any words prior to this point (added a little padding here and there) I should be just over one thousand words meaning that the censorship bot has probably stopped eavesdropping and left the room and we can now speak freely.

How can we be sure (more or less) that when we’re told to use fabric masks that it isn’t just a way for “the authorities” to control public fear?

Quite honestly, I’ve seen some terribly half baked recommendations such as “just cover your mouth and nose with a bandana or t-shirt”, which if only a single layer, I can basically prove offers almost no protection to you!

But like me you might also be asking… what about my Uptown Girls “sheets of Egyptian cotton”, would they be better than a t-shirt?

What if we used multiple layers, would that be better (it is) and if so, could we figure out how many layers would (more or less) provide “sufficient” protection?

Well, I could rely on my thousands of adoring Patrons to fund real world materials safety research but I feel like their hard earned cash is best spent supporting my work in other ways!

Besides… the obvious simple solution is to build a simulation! ๐Ÿ˜›

Continue reading “Are Makeshift Masks Safe?”

Blog at WordPress.com.

Up ↑

%d bloggers like this: