Yunpeng-26's picture
Upload 3 files
fb749d0 verified
|
Raw History Blame Contribute Delete
6.05 kB
metadata
title: AI-Powered Image Classification
emoji: 🖼️
colorFrom: blue
colorTo: indigo
sdk: static
app_file: index.html
pinned: false
models:
  - Xenova/resnet-18
  - Xenova/vit-base-patch16-224
  - Xenova/clip-vit-base-patch32

AI-Powered Image Classification

Open the demo · Student guide · Download the guide PDF

A small teaching mini-lab for a Creative Technology / introductory AI course.

The project shows how a pretrained model can turn image classification into a capability that can be used directly inside an application. Students do not need to train a neural network for the baseline task.

The learning story

  1. Choose one of 100 examples (four are shown at random), or upload an image.
  2. Choose a browser-compatible classifier: ResNet-18, ViT-B/16, or CLIP.
  3. Inspect the predicted labels and confidence scores.
  4. Keep the image fixed and switch models to compare decisions.
  5. For CLIP, change the candidate labels and observe how the result changes.
  6. Use the comparison log to discuss changes in the top label, score, and runtime.

Model and data

  • Task: image classification
  • Fixed label space: ImageNet-1K for ResNet and ViT
  • Flexible label space: user-supplied candidate descriptions for CLIP
  • Example bank: 100 local images, shown four at a time in the original two-by-two gallery. Shuffle draws another four from the same bank.
  • Image mix: 29 animals, 29 transport examples, 30 foods, and 12 other examples. These are teaching examples, not a labeled ImageNet benchmark or an accuracy test set.
  • Sources: the original 30 examples are retained; the 70 new CC0 photographs and the 22 earlier CC0 photographs are documented under Image sources below.
Classifier Hugging Face model What to explore
ResNet-18 Xenova/resnet-18 Recommended starting point: a compact CNN with 1,000 ImageNet labels
ViT-B/16 Xenova/vit-base-patch16-224 Compare a Vision Transformer with the CNN on the same image
CLIP ViT-B/32 Xenova/clip-vit-base-patch32 Rank your own candidate descriptions using a vision-language model

For CLIP, enter 2-20 short candidate descriptions separated by commas or new lines. Include a description of the object you want to test: CLIP ranks only the candidates you provide. Its scores should not be interpreted as directly comparable with ResNet or ViT scores.

Top-k controls how many labels appear in the result table. Each successful run also records its image, model, top prediction, score, and elapsed time in the comparison log, which keeps the latest 12 runs for the current page session.

All three models are already trained. This demo performs inference only; no training code or GPU server is required.

One project, one demo

  • index.html — page structure and teaching flow
  • style.css — presentation
  • app.js — interaction, image handling, and result rendering
  • classifier.js — the online Hugging Face model call
  • examples/ — 100 example images
  • how-to-start.html / how-to-start.pdf — the existing student guide for duplicating, editing, testing, and submitting a Space

Runtime

The Space is static. classifier.js imports Transformers.js from jsDelivr and creates a pipeline with a Hugging Face model ID. The first run for each model downloads its quantized model files from Hugging Face into the browser cache; later runs can reuse that cache. The selected image is processed in the browser and is not uploaded to an inference server.

This is the same online model-loading pattern used by the reference object-detection Space, with the task and models changed to image classification.

Reference object-detection Space: https://huggingface.co/spaces/wr92-course/test

Student assignment

Students can duplicate this Space as a working starting point, then build their own AI mini app. They may extend image classification or adapt the project to a different AI task. A submission should make the app's purpose, input, output, and AI model or service easy to understand and demonstrate at least one working example.

In the App tab, select How to Start for the browser-based steps to create an account, explore the demo, duplicate the Space, edit files, build an app, explain it, and submit a public Space URL. Students are not required to train an AI model from scratch.

Higher-scoring work should deepen the selected AI task: compare or replace models, change label spaces, test another image domain, study failure cases, or improve speed and evaluation.

Classroom check before use

Before presenting, verify that:

  • every image in the 100-example bank can be selected through Shuffle;
  • Shuffle changes the four visible examples drawn from the 100-image bank;
  • an uploaded image can be classified;
  • ResNet-18 and ViT-B/16 return ImageNet labels;
  • CLIP responds to changes in candidate labels;
  • the top-k slider changes the number of displayed predictions;
  • the score bars and comparison log update after every successful run;
  • the first uncached run shows download progress;
  • the student guide opens and its PDF download works;
  • the page works at a narrow/mobile width.

Local preview

Run a local web server in this folder, for example:

python -m http.server 7860

Then open http://localhost:7860. Opening index.html directly with file:// may block module loading.

Image sources

The original 30 images remain unchanged. The 70 newly added images are CC0 photographs from Wikimedia Commons. See the complete source and license list for all 92 CC0 photographs in the 100-image bank.