add files from colab
Browse files- app.py +36 -0
- requirements.txt +2 -0
- saved_model_files/config.json +34 -0
- saved_model_files/preprocessor_config.json +17 -0
- saved_model_files/pytorch_model.bin +3 -0
- saved_model_files/training_args.bin +3 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
3 |
+
|
4 |
+
dataset = datasets.load_dataset('beans')
|
5 |
+
|
6 |
+
extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
|
7 |
+
model = AutoModelForImageClassification.from_pretrained("saved_model_files")
|
8 |
+
|
9 |
+
labels = dataset['train'].features['labels'].names
|
10 |
+
|
11 |
+
def classify(im):
|
12 |
+
features = feature_extractor(im, return_tensors='pt')
|
13 |
+
logits = model(features["pixel_values"])[-1]
|
14 |
+
probability = torch.nn.functional.softmax(logits, dim=-1)
|
15 |
+
probs = probability[0].detach().numpy()
|
16 |
+
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|
17 |
+
return confidences
|
18 |
+
|
19 |
+
import gradio as gr
|
20 |
+
|
21 |
+
interface = gr.Interface(fn=classify, inputs="image", outputs="label",
|
22 |
+
examples=[
|
23 |
+
["https://images.unsplash.com/photo-1550147760-44c9966d6bc7?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Nnx8bGVhZnxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60"],
|
24 |
+
["https://images.unsplash.com/photo-1525498128493-380d1990a112?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTd8fGxlYWZ8ZW58MHx8MHx8&auto=format&fit=crop&w=800&q=60"],
|
25 |
+
["https://apps.lucidcentral.org/pppw_v10/images/entities/bean_angular_leaf_spot_216/angularspot1.jpg"],
|
26 |
+
["https://extension.umn.edu/sites/extension.umn.edu/files/beans-viral-diseases-2.jpg"],
|
27 |
+
["http://1.bp.blogspot.com/-CcMICF_A1CI/UHKSvTV2k2I/AAAAAAAAHI0/TlFMGU8RpYQ/s1600/DSCF9698.JPG"],
|
28 |
+
["https://www.garden.eco/wp-content/uploads/2017/12/bean-leaves.jpg"],
|
29 |
+
["https://apps.lucidcentral.org/pppw_v10/images/entities/bean_angular_leaf_spot_216/angularspot1.jpg"]
|
30 |
+
|
31 |
+
|
32 |
+
],
|
33 |
+
title="🍃 Bean Leaf Image Classification",
|
34 |
+
description="Based on a leaf image, the goal is to predict the disease type (Angular Leaf Spot and Bean Rust), if any.",)
|
35 |
+
|
36 |
+
interface.launch(debug=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:a8a00185935123b602150d9bb505a0d51eca2e815f1bb6e461973be2d2d653a6
|
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:d735a4e0301637cf2a8dbfb9b3200d5380d1151359b09e51fa21a9ac5e53a434
|
3 |
+
size 3375
|