Share your work here ✅

I created an implementation of Andrej Karpathy’s micrograd demo running inside the browser in pyscript. This trains a mini neural net inside the browser using his micrograd library.

This page allows you to run it interactively like you can with a Jupyter notebook, except this is running inside of your browser.
https://matdmiller.github.io/fastai-huggingface-sample-web-app1/pyscript-micrograd-demo.html
This page automatically runs the entire script and displays the training graphic at the end when it’s done. I wanted to test running this demo on my iPhone, but couldn’t run the Jupyter/REPL cells on my iPhone because I can’t click Shift+Enter to run them so this just automatically runs the entire script. Amazingly, it works!
https://matdmiller.github.io/fastai-huggingface-sample-web-app1/pyscript-micrograd-demo-autorun.html
More epochs yields better (100% accuracy) accuracy, but the speed/performance of this is not great, so I cut it down to 20 epochs so it finishes faster.


Repo is here if you want to look:

16 Likes

If you share this on twitter and post a link here, I’ll retweet it and make sure Karpathy sees :slight_smile:

10 Likes

Wow! amazing work! it took a couple minutes to run on my 12 year old macbook air running linux (in Chromium) … amazing to see this running in a browser.

2 Likes

Really awesome stuff

1 Like

Awesome, thanks Jeremy! Here’s the link to the tweet:

2 Likes

Seasonal Mood

For this first project, I wanted to try something a bit more abstract than just objects. Here, I train a model to classify the four seasons from images obtained from Duck Duck Go:

  • Spring
  • Summer
  • Fall
  • Winter

In terms of hyperparamaters, here are some adjustments that seemed helpful:

  • Architecture: I tried resnet18, resnet34, resnet50 and resnet101. With smaller training sets of 100-200 images/season, the smaller architectures outpreformed the larger ones—as high as 90-95% accuracy. I pursume this might in part be due to overtraining. Additionally, the smaller sets of images are likely have been more homogeneous than the larger training sets. For the final model I used resnet101 and 750 images/season with resulting accurcay of 80-85%.

  • Number of Pictures: 150 training images/season were initially used. These trained very well. As I increased the training sizes, performance dropped. I believe that this is because the larger training sets were much more diverse. I could verify this by looking manually at the DDG search results: later images diverged significantly from earlier images. For the final model, I used 750 training images/season. These larger training sets did not perform as well. Hopefully, the larger and more diverse training sets will perform better In the Wild, with real test data.

  • Image Size: 400 size images performed better than 300 size images

  • Transformations: squish outperformed crop

  • Training Epochs: 5 training epochs with resnet101 showed continued reduction in both training and validation losses

Gradio and HuggingFace to Create the App

10 Likes

Cool HF demo. I noticed that the inference can take a really long time (upwards of 20 seconds). Do you have a sense of why that is? Is it on account of the model being large (i.e. fine-tuned off resnet101) or are the sample images large or is there something else going on? Curious if there are some tips on how to keep that inference time low.

1 Like

I’ve noticed the lag as well. Moreover, it’s quite variable. Picture size, network/server load at HuggingFace, not sure. It is free. I would guess the paid models perform better. Frankly, I had never heard of either Gradio or HuggingFace till yesterday reading through the forums. Very cool

1 Like

My Chosen Problem Statement: A lot of people tend to confuse apes for monkeys.

Example: Monke Never forget’s

Therefore, I have decided to tackle this very important issue by creating an “Ape vs. Monkey” classifier.

Plan:

  1. Build a baseline model using Lesson 1’s code.
  2. Gradually improve it using all the tricks in the fast.ai book.
  3. Create a live demo using Streamlit & deploy to Hugging Face Spaces.

Stay tuned…

1 Like

It’s running on CPU, not GPU, and a ResNet101 is a really big model to be running on GPU, especially with such large images!

Generally I’d try to get 224x224 pixel images with ResNet34 working for reasonable CPU latency.

6 Likes

I wrote up my attempt at training a model to recognise my very cute (but not particularly intelligent) cat, Mr Blupus.

I ran into exactly the problem with validation data that Jeremy describes in chapter one, where my model was ‘cheating’ by learning to recognise my house (i.e. the photo backgrounds) and not my cat.

I reran the experiment with a held-out test set and surprisingly the model still did pretty well. I’m not sure if I did something wrong with how I calculated the accuracy using the test set, but in any case it was a useful lesson to have experienced in a practical way. (Thanks for the help with the final step, @FraPochetti and to those in the delft-fastai study group who encouraged me to collect a held-out test set.)

9 Likes

That’s a very good name for a not very intelligent cat. Did you know about its limited intellect before you named it?..

2 Likes

All we knew that he was soft when we ‘rescued’ him off the street. He was initially called ‘minicat’ because he was so tiny, but his true character soon revealed itself.

3 Likes

Great writeup man.
Quick suggestion.
You do the following:

accuracy = (gts == preds.argmax(dim=1))
sum([1 for item in accuracy if item]) / len(preds)

Turns out accuracy is a tensor of Booleans, e.g. True or False so you don’t need the list comprehension to check whether you have a 1 or not.

You can just do

accuracy = (gts == preds.argmax(dim=1))
sum(accuracy) / len(preds)
4 Likes

Hi all,

Looking to build, and then share, a recommendation system on this forum using the collaborative filtering packages available in fastai. However, I’m seeking your help to collect the necessary data.

The purpose of the recommendation system is to recommend travel destinations based on individual user profiles. The drive to develop such a model stems from the fact that my fiance and I are getting married at the end of the year, and we’re unsure where we’d like to go for our honey moon. The recommendation system will therefore provide a list of country recommendations based on our individual user profiles.

If you’re interested in helping out collect the necessary data, please fill out this survey, and share with others as well, if possible: Travel Destination Rating Survey | SurveyPlanet

Assuming enough survey results come through, I’ll share the recommendation system on this page once complete :slight_smile:

Thanks all!

1 Like

Backstory :slight_smile:

My kid and I keep on surfing the internet for various dinosaurs and their features and habitats and nesting patterns.
He also builds dinos from his lego blocks and building blocks, occasionally does drawing of them.
Recently he is working on building a Jurassic world with all his toys.

I thought it will be fun to build a prehistoric dinosaur identifier for this week’s homework for him to play around with.

I used seresnext50 model and fine-tuned it for 20 epochs.
I was able to achieve 0.248869 error rate. Blog post for more detailed analysis is under construction.

Hope you enjoy it. :grin:

17 Likes

I wonder if you can use something like a saliency map to figure out exactly what the model is learning or is there anything better out there?

1 Like

Had to look up what that is. That’s an interesting idea. No idea how I’d implement that with fastai, however. From what I remember of the course and the library, there are some helper functions built into fastai that will at least allow me to determine which examples it found hardest to determine. That might be a start in this general direction of looking under the hood.

4 Likes

you can quickly try out using the interpretation object helpers.

5 Likes

Search for ‘gradcam’ in the book.

6 Likes