Saiteja commited on
Commit
0a075d8
1 Parent(s): 92c1007
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import ViTImageProcessor, AutoFeatureExtractor, AutoModelForImageClassification
3
+ import gradio as gr
4
+
5
+ image_processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
6
+
7
+ extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
8
+ model = AutoModelForImageClassification.from_pretrained("saved_model_files")
9
+
10
+ labels = ['angular_leaf_spot', 'bean_rust', 'healthy']
11
+
12
+ def classify(image):
13
+ features = image_processor(image, return_tensors='pt')
14
+ logits = model(features["pixel_values"])[-1]
15
+ probability = torch.nn.functional.softmax(logits, dim=-1)
16
+ probs = probability[0].detach().numpy()
17
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
18
+ print(confidences)
19
+ return confidences
20
+
21
+
22
+ theme = gr.themes.Soft(
23
+ primary_hue="green",
24
+ secondary_hue="green",
25
+ neutral_hue="green",
26
+ ).set(
27
+ block_background_fill_dark='*body_background_fill',
28
+ button_border_width='*block_label_border_width',
29
+ button_border_width_dark='*checkbox_label_border_width'
30
+ )
31
+
32
+ with gr.Blocks(theme=theme) as demo:
33
+
34
+ inference = gr.Interface(fn=classify, inputs="image", outputs="label",
35
+ title="Plant leaves Classification",
36
+ description="Classify the leaves b uploading their image",
37
+ examples=["images/1.png","images/2.png", "images/3.png"])
38
+
39
+ demo.launch(share=True)
images/1.png ADDED
images/2.png ADDED
images/3.png ADDED
notebook.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ transformers==4.25.1
3
+ gradio
saved_model_files/config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "google/vit-base-patch16-224",
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": "angular_leaf_spot",
13
+ "1": "bean_rust",
14
+ "2": "healthy"
15
+ },
16
+ "image_size": 224,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "label2id": {
20
+ "angular_leaf_spot": "0",
21
+ "bean_rust": "1",
22
+ "healthy": "2"
23
+ },
24
+ "layer_norm_eps": 1e-12,
25
+ "model_type": "vit",
26
+ "num_attention_heads": 12,
27
+ "num_channels": 3,
28
+ "num_hidden_layers": 12,
29
+ "patch_size": 16,
30
+ "problem_type": "single_label_classification",
31
+ "qkv_bias": true,
32
+ "torch_dtype": "float32",
33
+ "transformers_version": "4.28.1"
34
+ }
saved_model_files/preprocessor_config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "do_rescale": true,
4
+ "do_resize": true,
5
+ "image_mean": [
6
+ 0.5,
7
+ 0.5,
8
+ 0.5
9
+ ],
10
+ "image_processor_type": "ViTImageProcessor",
11
+ "image_std": [
12
+ 0.5,
13
+ 0.5,
14
+ 0.5
15
+ ],
16
+ "resample": 2,
17
+ "rescale_factor": 0.00392156862745098,
18
+ "size": {
19
+ "height": 224,
20
+ "width": 224
21
+ }
22
+ }
saved_model_files/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6fa2eede4696254ccbe431ab81f3a02bdf28702b1b8b6a33113181ba7567803
3
+ size 343271789