Okay, so today I’m gonna walk you through this little project I did – recognizing MLB helmets. Sounds kinda dumb, right? But hear me out, it was a fun way to mess around with some image recognition stuff.

First off, I needed data. Like, a lot of images of MLB helmets. So I started scraping images off Google, various sports websites, even eBay listings. I wrote a quick Python script using Beautiful Soup to automate the process. Man, that took forever. Wrangling all those images and making sure they were somewhat decent quality was a pain. Ended up with a few thousand, which I figured was enough to start with.
Next up, I had to clean up the dataset. You know, remove duplicates, images that weren’t helmets, images that were too blurry, etc. I used a combination of manual checking and some OpenCV scripts to filter out the garbage. This part is super important, ’cause garbage in, garbage out, ya know?
Then came the fun part: labeling. I sorted the images into folders, one for each MLB team. This was totally manual and incredibly tedious. I was watching baseball highlights the whole time to keep me sane. Seriously, this took days.
Okay, dataset prepped. Now for the model. I decided to use TensorFlow/Keras because I’m somewhat familiar with it. I opted for a convolutional neural network (CNN), ’cause that’s what everyone uses for image recognition. I started with a pretty basic model: a few convolutional layers, some max pooling layers, and then a fully connected layer at the end with softmax activation for classification. I initialized the weights randomly.
Training time! I split the data into training, validation, and test sets. I used the validation set to tune the hyperparameters (learning rate, batch size, etc.) and avoid overfitting. I used Adam optimizer and categorical cross-entropy loss function. My GPU was screaming the whole time. After a bunch of epochs, the model started to converge, and the validation accuracy was looking pretty good.

Now, for the real test: the test set. I ran the model on the test images and got a decent accuracy score, like 75% or so. Not perfect, but way better than random guessing. Some teams were easier to recognize than others, probably because their helmets have more distinctive features.
Of course, there were some issues. The model sometimes got confused between similar-looking helmets (like the Yankees and the White Sox). Also, it struggled with images where the helmet was partially obscured or had weird lighting.
To improve the model, I tried a few things. Data augmentation (rotating, scaling, and cropping the images) helped a bit. I also experimented with different CNN architectures, like adding more layers or using pre-trained models (transfer learning). Transfer learning actually gave me the biggest boost in accuracy.
Finally, I wanted to deploy this thing somehow. I mean, what’s the point of having a helmet-recognizing model if you can’t show it off? So I built a simple web app using Flask. You can upload an image of a helmet, and the app will tell you which team it belongs to. It’s not pretty, but it works. I even threw it up on a free Heroku instance.
So yeah, that’s pretty much it. A silly little project, but I learned a lot about image recognition, data wrangling, and model deployment. Plus, now I can impress my friends by identifying MLB helmets with (questionable) accuracy.

- Gathered thousands of MLB helmet images.
- Cleaned and labeled the dataset.
- Built a CNN model using TensorFlow/Keras.
- Trained the model and evaluated its performance.
- Improved the model using data augmentation and transfer learning.
- Deployed the model as a web app using Flask and Heroku.