Vision Transformer for SEM Image Classification
This is a fine-tuned Vision Transformer (ViT-B/32) model for classifying Scanning Electron Microscopy (SEM) images into 10 distinct categories of nanostructures [1].
This model was developed as part of the NFFA-DI (Nano Foundries and Fine Analysis Digital Infrastructure) project, funded by the European Union's NextGenerationEU program.
Model Description
The model is based on the google/vit-base-patch32-224-in21k checkpoint and has been fine-tuned for a 10-class image classification task on SEM images. The 10 categories cover a wide range of nanostructures:
- Porous Sponge
- Patterned Surface
- Particles
- Films and Coated Surface
- Powder
- Tips
- Nanowires
- Biological
- MEMS devices and electrodes
- Fibres
How to Use
The following Python code shows how to load the model and its processor from the Hub and use it to classify a local SEM image.
1from transformers import AutoImageProcessor, AutoModelForImageClassification
2from PIL import Image
3import torch
4
5# Load the model and image processor from the Hub
6model_name = "t0m-R/vit-sem-classification"
7image_processor = AutoImageProcessor.from_pretrained(model_name)
8model = AutoModelForImageClassification.from_pretrained(model_name)
9
10# Load and preprocess the image
11image_path = "path/to/your/sem_image.jpg"
12try:
13 image = Image.open(image_path).convert("RGB")
14
15 # Prepare the image for the model
16 inputs = image_processor(images=image, return_tensors="pt")
17
18 # Run inference
19 with torch.no_grad():
20 logits = model(**inputs).logits
21 predicted_label_id = logits.argmax(-1).item()
22 predicted_label = model.config.id2label[predicted_label_id]
23
24 print(f"Predicted Label: {predicted_label}")
25
26except FileNotFoundError:
27 print(f"Error: The file at {image_path} was not found.")
Training Data
This model was fine-tuned on the SEM Majority dataset, the first annotated set of scanning electron microscopy images for nanoscience.
The dataset consists of 25,537 SEM images manually classified into 10 categories. The classification labels were verified by a group of nanoscientists, and only images validated by the majority of the group were included in the dataset.
[1] Aversa, Rossella, et al. "The first annotated set of scanning electron microscopy images for nanoscience." Scientific data 5.1 (2018): 1-10.