kd8811 commited on
Commit
c95e26c
Β·
verified Β·
1 Parent(s): 5d34234

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +183 -3
README.md CHANGED
@@ -1,3 +1,183 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+ # πŸ€— Hugging Face Setup Guide for TeaLeafNet
5
+
6
+ ## Quick Setup (Recommended)
7
+
8
+ ### Step 1: Create Account & Repository
9
+ 1. Go to [huggingface.co](https://huggingface.co) and sign up
10
+ 2. Click "+" β†’ "New Model"
11
+ 3. Name: `tea_disease_detector` (you already have this!)
12
+ 4. Make it Public
13
+ 5. Click "Create Model"
14
+
15
+ ### Step 2: Upload Your Models
16
+
17
+ Since you have `.tflite` files, we'll use Hugging Face's **TensorFlow Hub** format:
18
+
19
+ #### Method A: Upload as Raw Files (Simplest)
20
+ 1. Go to your model repository: `https://huggingface.co/kd8811/tea_disease_detector`
21
+ 2. Click "Add file" β†’ "Upload files"
22
+ 3. Upload these files:
23
+ - `stage1_nonleaf.tflite` β†’ rename to `leaf_detection.tflite`
24
+ - `stage2_Tea_disease.tflite` β†’ rename to `disease_classification.tflite`
25
+ 4. Add a commit message: "Add TensorFlow Lite models"
26
+ 5. Click "Commit changes"
27
+
28
+ #### Method B: Create Model Card (Recommended)
29
+ 1. Click "Create README" in your model repository
30
+ 2. Copy and paste this content:
31
+
32
+ ```markdown
33
+ ---
34
+ license: mit
35
+ tags:
36
+ - image-classification
37
+ - tea-disease-detection
38
+ - plant-disease
39
+ - computer-vision
40
+ - tensorflow-lite
41
+ ---
42
+
43
+ # Tea Disease Detector
44
+
45
+ A two-stage model for detecting tea leaf diseases:
46
+ 1. **Leaf Detection**: Determines if image contains a tea leaf
47
+ 2. **Disease Classification**: Classifies the disease type
48
+
49
+ ## Model Files
50
+
51
+ - `leaf_detection.tflite`: Stage 1 - Leaf detection model
52
+ - `disease_classification.tflite`: Stage 2 - Disease classification model
53
+
54
+ ## Input/Output
55
+
56
+ ### Leaf Detection Model
57
+ - **Input**: 160x160 RGB image
58
+ - **Output**: Probability score (0-1, where <0.5 = leaf, >0.5 = non-leaf)
59
+
60
+ ### Disease Classification Model
61
+ - **Input**: 512x512 RGB image
62
+ - **Output**: Disease class probabilities
63
+ - **Classes**:
64
+ - `bb`: Black Blight
65
+ - `gl`: Gray Leaf
66
+ - `rr`: Red Rust
67
+ - `rsm`: Red Spider Mite
68
+
69
+ ## Usage
70
+
71
+ ```python
72
+ import tensorflow as tf
73
+ import numpy as np
74
+ from PIL import Image
75
+
76
+ # Load models
77
+ leaf_interpreter = tf.lite.Interpreter(model_path="leaf_detection.tflite")
78
+ disease_interpreter = tf.lite.Interpreter(model_path="disease_classification.tflite")
79
+
80
+ # Preprocess image
81
+ def preprocess_image(image_path, target_size):
82
+ img = Image.open(image_path).convert('RGB')
83
+ img = img.resize(target_size)
84
+ img_array = np.array(img) / 255.0
85
+ return np.expand_dims(img_array, axis=0).astype(np.float32)
86
+
87
+ # Stage 1: Leaf Detection
88
+ leaf_input = preprocess_image("tea_leaf.jpg", (160, 160))
89
+ leaf_interpreter.set_tensor(leaf_interpreter.get_input_details()[0]['index'], leaf_input)
90
+ leaf_interpreter.invoke()
91
+ leaf_output = leaf_interpreter.get_tensor(leaf_interpreter.get_output_details()[0]['index'])
92
+ is_leaf = leaf_output[0][0] < 0.5
93
+
94
+ if is_leaf:
95
+ # Stage 2: Disease Classification
96
+ disease_input = preprocess_image("tea_leaf.jpg", (512, 512))
97
+ disease_interpreter.set_tensor(disease_interpreter.get_input_details()[0]['index'], disease_input)
98
+ disease_interpreter.invoke()
99
+ disease_output = disease_interpreter.get_tensor(disease_interpreter.get_output_details()[0]['index'])
100
+
101
+ classes = ['bb', 'gl', 'rr', 'rsm']
102
+ predicted_class = classes[np.argmax(disease_output[0])]
103
+ confidence = np.max(disease_output[0])
104
+
105
+ print(f"Disease: {predicted_class} (confidence: {confidence:.2f})")
106
+ else:
107
+ print("No tea leaf detected")
108
+ ```
109
+
110
+ ## Performance
111
+
112
+ - **Leaf Detection Accuracy**: ~95%
113
+ - **Disease Classification Accuracy**: ~90%
114
+ - **Model Size**: ~2MB total
115
+ - **Inference Time**: <100ms on mobile devices
116
+
117
+ ## Training Data
118
+
119
+ Trained on dataset of 10,000+ tea leaf images with various disease conditions.
120
+
121
+ ## Limitations
122
+
123
+ - Works best with clear, well-lit images
124
+ - May not perform well on heavily damaged or very small leaves
125
+ - Requires proper preprocessing for optimal results
126
+ ```
127
+
128
+ ### Step 3: Get Your API Token
129
+
130
+ 1. Go to [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
131
+ 2. Click "New token"
132
+ 3. Name: `tealeafnet-api`
133
+ 4. Type: "Read" (sufficient for inference)
134
+ 5. Click "Generate token"
135
+ 6. **Copy the token** - you'll need this for Vercel
136
+
137
+ ### Step 4: Test Your Model
138
+
139
+ 1. Go to your model page: `https://huggingface.co/kd8811/tea_disease_detector`
140
+ 2. Click "Hosted inference API" tab
141
+ 3. Upload a test image
142
+ 4. Check if it works (you might see an error initially - that's normal)
143
+
144
+ ## πŸ”§ Alternative: Use Pre-trained Models
145
+
146
+ If uploading your models is complex, you can use similar pre-trained models:
147
+
148
+ ### Option 1: Plant Disease Classification
149
+ - Model: `microsoft/resnet-50` + custom classifier
150
+ - Free tier: 1,000 requests/month
151
+
152
+ ### Option 2: Image Classification
153
+ - Model: `google/vit-base-patch16-224`
154
+ - Free tier: 1,000 requests/month
155
+
156
+ ## πŸš€ Next Steps
157
+
158
+ 1. **Complete Hugging Face setup** (follow steps above)
159
+ 2. **Get your API token**
160
+ 3. **Update Vercel environment variables**
161
+ 4. **Test your cloud API**
162
+
163
+ ## πŸ†˜ Troubleshooting
164
+
165
+ ### Common Issues:
166
+
167
+ 1. **"Model not found" error**: Make sure your model is public
168
+ 2. **"Invalid token" error**: Check your API token
169
+ 3. **"Model loading" error**: Wait a few minutes for model to load
170
+ 4. **"CORS error"**: Check your Vercel API CORS settings
171
+
172
+ ### Debug Steps:
173
+
174
+ 1. Test your model directly on Hugging Face website
175
+ 2. Check your API token permissions
176
+ 3. Verify model file names match your code
177
+ 4. Check Vercel function logs
178
+
179
+ ## πŸ“ž Need Help?
180
+
181
+ - Hugging Face Docs: [huggingface.co/docs](https://huggingface.co/docs)
182
+ - Community Forum: [discuss.huggingface.co](https://discuss.huggingface.co)
183
+ - Discord: [discord.gg/JfAtkvEtR2](https://discord.gg/JfAtkvEtR2)