Category: Updates

  • Ashryver V1 Painting Classifier: Release Summary

    Ashryver V1 Painting Classifier: Release Summary

    Today, I finally finished setting up the Ashryver V1 Painting Classifier, my latest interactive web-based model, and placed a live embed on the AI, ML, and Web Projects page. You can now interact with the model right from your browser, and upload any painting you choose for the model to make predictions. Although the embed is a little small, and the formatting is still on the uneven side due to WordPress’s lack of flexibility, I hope to have these issues sorted out soon. Besides, my ultimate plan (perhaps once the final, non-prototype Ashryver V2 model comes out) is to place an active HuggingFace API instance of the model on one of my websites. I’ll have to wait until HuggingFace and Gradio sort out a CORS issue first, though, as there have been known issues across all platforms for the past few weeks.

    In this post, I’ll provide a brief summary of the training process, the overall model performance, and my future goals now that this project is “finished”.

    The Training Process

    I started working on the Ashryver V1 model about a week ago. I used the fast.ai foundational framework for this project, moving away from the clunky and cumbersome Tensorflow libraries I had been familiar with before. fast.ai is just an upper layer of Pytorch, which is the latest and most efficient machine learning library. I was blown away by how easy it is to instantly create and train a deep learning model; all it takes is just a few different code cells and some DataBlocks.

    As a brief reminder, this Ashryver V1 model is a painting classifier trained on images of 20 different Impressionistic and modern artists; I aimed for about 300-400 images per artist, yielding a total dataset of about 2,700 images (about 500 of which were split off for validation). Although this is a relatively modest dataset size, it ended up doing the job very well. I did have to go through several training runs to get the accuracy above its initial poor score of 0.60, but things turned out well in the end.

    At first I was using the resnet34 model, which was rumored to be exceptionally good at classifying paintings. This is one of PyTorch’s pretrained models, and it’s called resnet34 because it has 34 layers in its convolutional neural network. This worked out okay, but generally you want to be achieving higher than 0.60 validation accuracy for a classification model. So I decided to switch to the resnet50 model, which prefers an image size of 224 x 224 pixels and has 50 layers in its CNN. This model performed substantially better, first achieving an accuracy of 0.77 on the initial 1800-image dataset, and then 0.89 on the final 2700-image dataset.

    Once you have your data in the artist folders, this is all you need to do to train your model -- just two simple code cells.
    
    # Create the Datablock
    dls = DataBlock(
        blocks=(ImageBlock, CategoryBlock), 
        get_items=get_image_files, 
        splitter=RandomSplitter(valid_pct=0.2, seed=42), # split 20% of the data off for validation
        get_y=parent_label,
        item_tfms=[Resize(448, method='squish')]
    ).dataloaders(painting_data_updated, bs=32)
    
    dls.show_batch(max_n=20) # show a sample of 20 images that the model will be trained upon
    
    # Train the resnet50 model
    learn = vision_learner(dls, resnet50, metrics=error_rate)
    learn.fine_tune(4) # train for 4 epochs
    

    The Production Process

    Once I finished training the model and was satisfied with the result, I moved onto the production process. In the previous blog post, I touched on the difficulties I was having with HuggingFace in setting up a space for the model; I managed to resolve these issues a few days ago and get moving. The Ashryver V1 model (and any successive models) are running in a HuggingFace space, which I’ve set up and named ‘erilea-models’ to embody the fictional continent of Erilea. This space behaves somewhat like a GitHub repository, which you can clone down to your computer to add code and add models that can be represented using HuggingFace’s UI. All I had to do with this repository was drop in my pre-trained model in the form of a PKL file, and then call that file to make predictions using a simple notebook. That notebook then launched a Gradio interface (essentially what creates the graphical UI you see on the space itself) that allowed the model to make live predictions.

    This way, you don’t have to clone down the entire repository and install a bunch of insane packages to play around with the model. You can just go to the HuggingFace space (which I’ve made public), upload your own images, and have it make predictions. There’s actually even more I could do with this model, like using the Gradio API to place it on one of my own websites and use some custom JavaScript to make it look a bit different. However, the current HuggingFace solution works perfectly fine for this V1 model; I may consider switching to a more advanced API solution for V2.

    Next Steps

    Speaking of V2, let’s take a final look at my next steps for the Ashryver model. I’d like to improve the model’s reliability on Matisse paintings; right now it continually misclassifies Matisse’s tape drawing The Bees. I’m not sure how to deal with this one, as it isn’t a “painting” in the traditional sense, but users might still want to predict with that image. There have also been some isolated issues with other artists, where incorrect predictions crop up every so often.

    For V2, my plan is to find some way to deal with the ridiculous watermarked images or those that contain overlaid text in the training process, as these really seem to be sabotaging the model. I also would like to add a bit more data if possible, maybe for certain artists only, so the model can get a more comprehensive view of what’s going on. I may also add some additional artist categories (although this is optional), and I would definitely like to add a “sister” model that is designed to recognize the artistic era or period of a painting, and use that model to make “backup predictions” of a painting’s era in addition to the artist, in case you give the model a painting that it’s not familiar with. These enhancements should make the Ashryver model much smarter overall as a painting classifier; once I get these improvements done, I should be ready to move onto Unit 3 of the fast.ai Practical Deep Learning course.

    Don’t forget to check out the model on HuggingFace, or go to the AI, ML & Web Projects page to play around with the widget. Stay tuned for more updates!

  • Deep Learning Debacle: Deploying the Ashryver V1 Model (Painting Classifier)

    Deep Learning Debacle: Deploying the Ashryver V1 Model (Painting Classifier)

    Today (and this entire week) has been quite the adventure when it comes to deep learning AI models. I finally got off the ground on my latest project, the Ashryver model (the easy-to-remember codename for the 20-artist painting classifier). After building it locally with Jupyter Notebooks and Kaggle, I advanced to the next unit in the fast.ai Practical Deep Learning course, and started attempting to deploy it on a HuggingFace/Gradio space…

    …and promptly entered into a world of calamity.

    Creating an account on HuggingFace and setting up a space was pretty easy. But that was just the tip of the iceberg, as you might imagine. After that I had to figure out a way to set up an API key, clone HuggingFace’s Github-adjacent-but-not-really-Github repository down to my computer, add my pickle files for the Ashryver model, and deal with all the humongous files and conflicts. This quickly spiraled into hell. First of all, the API keys kept getting “into a stuck state” when attempting to commit changes to HuggingFace; apparently HuggingFace had deprecated a core feature that allowed users to authenticate with their HuggingFace password back in 2023, and you now had to use your cryptic API key. So I was forced to generate the in-universe “aelin” API key and use that, which fortunately worked.

    However, that wasn’t the end of the troubles. I then encountered issues committing any changes at all to HuggingFace, due to binary file limitations and Git LFS complications. At this point I was engaging in a lengthy back-and-forth conversation with Google Gemini, trying to figure out the best course of action for what I was facing. Every time I tried to turn on LFS or add the files, pushing any staged files would just lead to more and more errors. Eventually I just gave up and followed two core pieces of ML management advice: never upload your .PKL files or dataset files to source control because they can be a target for malware and bloat your repo. For now, I’m just leaving them untracked on my laptop, and not committing them to HuggingFace. After all, the model will be able to run live; users shouldn’t need to poke around in the source code this time.

    Speaking of poking around in the source code and my future plans for the Ashryver architecture, let’s dig into those topics now…

    Future Plans, Links, and Naming Conventions

    The current state of the HuggingFace space, displaying all model files

    Click to view the current HuggingFace space, which is still very work-in-progress.

    You may have noticed the rather unconventional name of the space itself, erilea-models, and the interesting name for the painting-classifier model architecture, Ashryver. If you’ve really been poking around in the Files section of the HuggingFace space, you may have noticed references to an “Aelin” or “Sam Cortland”. If you’re really receptive, you may have made the proper neural network connections and surmised that these are characters from a fictional series.

    If so, congratulations. To make things more interesting, and detract from the tradition of naming repositories and models boring things “like Testing Area 1 and Deep Learning Architecture System Version 1”, I decided to spice things up and give this space and its models some creative names. These are not so much “original” as “easy-to-remember”, which makes it more convenient to key in GitHub commands when all your filenames and model names are simple names. I plan on naming each successive model I release after a different character, improving upon each one with clear version numbers.

    As for my plans at the moment, I intend to continue working on getting the Ashryver V1 model into production. When that’s done, you’ll be able to go directly to that HuggingFace space (linked above), upload your own paintings, and have the model instantly make predictions. Right now, although the model has consistently been getting 0.89 accuracy on test runs, it still makes the occasional error when it comes to Henri Matisse’s paintings and tape drawings. This is an issue I plan to correct in Ashryver V2, which is where I might also introduce more artist categories. For now, though, all my time is probably going to be spent on getting Ashryver V1 into production.

    What all this means is that users will no longer have to clone cumbersome GitHub repositories and figure out ways to get my code to work on their very different machine, which sounds like a recipe for disaster. I’m planning on uploading my past models into that same HuggingFace space as well, or maybe a different one to improve organization. I’ll at least put the CIFAR Image Classifier on there, and maybe even the QuickDraw model if I can get it to work. After that, I intend to work on some more computer vision models, deep learning projects, and put something even more substantive than Ashryver out on the web.

    I’ll probably put up links to my various HuggingFace spaces eventually on this website, and they will serve as the “showcase sites” or portfolio pieces for the various AI models. This is what I’ve been working up to for quite a while, and it’s good that I’ve finally started working on a way to get these models into production.

    Well, that’s all for now on the deep learning front. Stay tuned for more calamitous updates!

  • Site Update: New Creative Works, Comments, and Inspirations

    I made some major changes to this website’s content and aesthetics this week, which you may or may not have noticed. First, I modified some of the fonts that are used, and installed a new minimalistic font that I felt went a bit better with the site’s theme. That font is now used on some of the page headings and titles across the website. Second, I completely revamped the Short Stories & Poetry page to better showcase my various poems and stories in a grid layout. Each piece has its own Inspirations & Comments section, where I attempt to convey what led me to compose the piece, and the meaning behind it.

    I’m still working on adding more of my poetry and short stories, but I have a semi-comprehensive list on the Short Stories & Poetry home page. In fact, I’m working on a rather unusual coming-of-age short story right now; it might be the submission for the 2027 Scholastic Art & Writing awards. Once that’s done, I’ll attempt to upload it to the website, and attach some comments. I’m contemplating adding a background-header sort of picture to the short stories & poetry page, similar to the large one on the homepage. However, I’d like the text to be overlaid upon the background image, and thus far, I haven’t found a way to do that with clunky WordPress.

    I’ve also made some minor tweaks to the Musical Works page, changing the names of some tabs and linking some of the most recent compositions. As a quick note, it is now possible for people to fill out the site’s Contact form to obtain copies of the scores; there is a one-page preview image available for some of the more recent pieces and a button to get to the Contact form. I don’t plan on charging money for the scores; this is just a mechanism to prevent bots (or people) from coming on and scamming the scores to a wide variety of unauthorized individuals.

    Deep Learning Course: Finally, Some Progress

    A code cell and output from the fast.ai painting classifier, displaying some sample photos that will be used to train the model.

    After about a week of screaming and coming close to quitting the entire course, I finally started making some progress on the fast.ai Practical Deep Learning for Coders course. Yesterday, I finished training the first major project, which is a painting classifier designed to identify the artist of a given painting image. Right now, I’m training it on the works of twenty different Impressionistic artists, with some more modern painters also included. I’m amazed at how much easier it is to use PyTorch to create a classifier than Tensorflow; all you need to do is pull down your images, create a DataBlock, and initiate your learner.

    The reason why I was getting so blocked on this model before was the stupid DuckDuckGo search issues, combined with issues with Kaggle. This sort of classifier relies on pulling down batch images from the DuckDuckGo search API, which is flaky at best and catastrophically time-consuming at worst. So why am I using DuckDuckGo, of all search APIs? Because Microsoft has gone bad and locked their Bing Search API behind a paywall. In a similar way, Google’s search system requires several different API keys, extensive verification, and massive amounts of credentials that make no sense for a small project like this one.

    At first, I thought I was going to have to quit out of this project and find a different data setup that didn’t rely on DuckDuckGo. But then, on Monday morning, I “magically” stopped getting 403 Ratelimit errors, and started downloading images as normal. So I jumped on the opportunity and immediately trained the model to completion with all 4,000 images; after doing some brief testing, it looked like the model was actually pretty good. I’m going to obtain some empirical data on the model’s performance–accuracy, loss, and others–shortly, and use that data to experiment with some different model architectures and data configurations.

    I also did some minor refactoring of the model’s code, which is now available in my official fast.ai course repository on GitHub (though I don’t recommend doing anything with it yet, as it’s still very preliminary, and the repo is still a mess). In unit 2 of the fast.ai deep learning course, I aim to release this painting classifier via a web API so you can interact with it directly; when that’s done I won’t have to deal with muddled GitHub repositories, local files, and broken Kaggle runtimes because the model is released into production already.

    Well, that concludes this regular site update. Stay tuned for further news on AI projects and creative pieces!

  • Update: New ML Courses and Deep Learning Exploration

    Update: New ML Courses and Deep Learning Exploration

    Subscribe to continue reading

    Subscribe to get access to the rest of this post and other subscriber-only content.