t0m-R commited on
Commit
4d00fc9
·
1 Parent(s): 0b9587e

Upload ViT-B/32 SEM classification model

Browse files
Files changed (4) hide show
  1. README.md +78 -3
  2. config.json +48 -0
  3. model.safetensors +3 -0
  4. preprocessor_config.json +36 -0
README.md CHANGED
@@ -1,3 +1,78 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language: en
4
+ tags:
5
+ - image-classification
6
+ - vision-transformer
7
+ - pytorch
8
+ - sem
9
+ - materials-science
10
+ - nffa-di
11
+ base_model: google/vit-base-patch32-224-in21k
12
+ pipeline_tag: image-classification
13
+ ---
14
+
15
+ # Vision Transformer for SEM Image Classification
16
+
17
+ 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].
18
+
19
+ 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.
20
+
21
+
22
+ ## Model Description
23
+
24
+ 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:
25
+
26
+ 1. Porous Sponge
27
+ 2. Patterned Surface
28
+ 3. Particles
29
+ 4. Films and Coated Surface
30
+ 5. Powder
31
+ 6. Tips
32
+ 7. Nanowires
33
+ 8. Biological
34
+ 9. MEMS devices and electrodes
35
+ 10. Fibres
36
+
37
+ ## How to Use
38
+ 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.
39
+
40
+ ```python
41
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
42
+ from PIL import Image
43
+ import torch
44
+
45
+ # Load the model and image processor from the Hub
46
+ model_name = "t0m-R/vit-sem-classification"
47
+ image_processor = AutoImageProcessor.from_pretrained(model_name)
48
+ model = AutoModelForImageClassification.from_pretrained(model_name)
49
+
50
+ # Load and preprocess the image
51
+ image_path = "path/to/your/sem_image.jpg"
52
+ try:
53
+ image = Image.open(image_path).convert("RGB")
54
+
55
+ # Prepare the image for the model
56
+ inputs = image_processor(images=image, return_tensors="pt")
57
+
58
+ # Run inference
59
+ with torch.no_grad():
60
+ logits = model(**inputs).logits
61
+ predicted_label_id = logits.argmax(-1).item()
62
+ predicted_label = model.config.id2label[predicted_label_id]
63
+
64
+ print(f"Predicted Label: {predicted_label}")
65
+
66
+ except FileNotFoundError:
67
+ print(f"Error: The file at {image_path} was not found.")
68
+ ```
69
+
70
+ ## Training Data
71
+
72
+ This model was fine-tuned on the SEM Majority dataset, the first annotated set of scanning electron microscopy images for nanoscience.
73
+
74
+ 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.
75
+
76
+ The dataset is publicly available at: https://doi.org/10.23728/b2share.e344a8afef08463a855ada08aadbf352
77
+
78
+ [1] Aversa, Rossella, et al. "The first annotated set of scanning electron microscopy images for nanoscience." Scientific data 5.1 (2018): 1-10.
config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "google/vit-base-patch32-224-in21k",
3
+ "architectures": [
4
+ "ViTForImageClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.0,
7
+ "encoder_stride": 16,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.0,
10
+ "hidden_size": 768,
11
+ "id2label": {
12
+ "0": "Porous_Sponge",
13
+ "1": "Patterned_surface",
14
+ "2": "Particles",
15
+ "3": "Films_Coated_Surface",
16
+ "4": "Powder",
17
+ "5": "Tips",
18
+ "6": "Nanowires",
19
+ "7": "Biological",
20
+ "8": "MEMS_devices_and_electrodes",
21
+ "9": "Fibres"
22
+ },
23
+ "image_size": 224,
24
+ "initializer_range": 0.02,
25
+ "intermediate_size": 3072,
26
+ "label2id": {
27
+ "Porous_Sponge": "0",
28
+ "Patterned_surface": "1",
29
+ "Particles": "2",
30
+ "Films_Coated_Surface": "3",
31
+ "Powder": "4",
32
+ "Tips": "5",
33
+ "Nanowires": "6",
34
+ "Biological": "7",
35
+ "MEMS_devices_and_electrodes": "8",
36
+ "Fibres": "9"
37
+ },
38
+ "layer_norm_eps": 1e-12,
39
+ "model_type": "vit",
40
+ "num_attention_heads": 12,
41
+ "num_channels": 3,
42
+ "num_hidden_layers": 12,
43
+ "patch_size": 32,
44
+ "problem_type": "single_label_classification",
45
+ "qkv_bias": true,
46
+ "torch_dtype": "float32",
47
+ "transformers_version": "4.41.2"
48
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37b6f1dfa2a42d99e78e875ef14f3efd8fe8d6f9f7bb72b84c9866cb13cc8125
3
+ size 349874904
preprocessor_config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_valid_processor_keys": [
3
+ "images",
4
+ "do_resize",
5
+ "size",
6
+ "resample",
7
+ "do_rescale",
8
+ "rescale_factor",
9
+ "do_normalize",
10
+ "image_mean",
11
+ "image_std",
12
+ "return_tensors",
13
+ "data_format",
14
+ "input_data_format"
15
+ ],
16
+ "do_normalize": true,
17
+ "do_rescale": true,
18
+ "do_resize": true,
19
+ "image_mean": [
20
+ 0.5,
21
+ 0.5,
22
+ 0.5
23
+ ],
24
+ "image_processor_type": "ViTImageProcessor",
25
+ "image_std": [
26
+ 0.5,
27
+ 0.5,
28
+ 0.5
29
+ ],
30
+ "resample": 2,
31
+ "rescale_factor": 0.00392156862745098,
32
+ "size": {
33
+ "height": 224,
34
+ "width": 224
35
+ }
36
+ }