konneker commited on
Commit
001889d
1 Parent(s): 63aa6d0

init repo from colab

Browse files
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
3
+ import gradio as gr
4
+
5
+ description = "Example bean leaf health classification app using a fine-tuned ViT model"
6
+ title_string = "What's up with my leaf?"
7
+
8
+ dataset = datasets.load_dataset("beans")
9
+
10
+ extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
11
+ model = AutoModelForImageClassification.from_pretrained("saved_model_files")
12
+
13
+ labels = dataset['train'].features['labels'].names
14
+
15
+ def classify(im):
16
+ features = extractor(im, return_tensors='pt')
17
+ encoding = model(**features)
18
+ logits = torch.nn.functional.softmax(encoding.logits, dim=-1)
19
+ probability = torch.nn.functional.softmax(logits, dim=-1)
20
+ probs = probability[0].detach().numpy()
21
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
22
+ return confidences
23
+
24
+
25
+ examples = [dataset['test'][0]['image_file_path']]
26
+
27
+ interface = gr.Interface(
28
+ classify,
29
+ gr.inputs.Image(),
30
+ gr.outputs.Label(num_top_classes=3),
31
+ description=description,
32
+ #examples=examples,
33
+ title = title_string
34
+
35
+ )
36
+
37
+ interface.launch(debug=True, share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ torch
2
+ transformers
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.22.1"
34
+ }
saved_model_files/preprocessor_config.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "do_resize": true,
4
+ "feature_extractor_type": "ViTFeatureExtractor",
5
+ "image_mean": [
6
+ 0.5,
7
+ 0.5,
8
+ 0.5
9
+ ],
10
+ "image_std": [
11
+ 0.5,
12
+ 0.5,
13
+ 0.5
14
+ ],
15
+ "resample": 2,
16
+ "size": 224
17
+ }
saved_model_files/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be424e293b48d63458d0d0854f192b92306e693945e8b12afddb5236f210cbf3
3
+ size 343270065
saved_model_files/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4459a2df747dda54a356d9f6a19968ebe41107b88ad0663123afefe789aa58b6
3
+ size 3375