Update README.md
Browse files
README.md
CHANGED
@@ -71,3 +71,40 @@ The model is trained to classify the following plant diseases and conditions:
|
|
71 |
40: "Tomato leaf with Tomato mosaic virus",
|
72 |
41: "Healthy Tomato leaf"
|
73 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
40: "Tomato leaf with Tomato mosaic virus",
|
72 |
41: "Healthy Tomato leaf"
|
73 |
}
|
74 |
+
```
|
75 |
+
## Usage
|
76 |
+
|
77 |
+
You can use the `clip-vit-large-patch14-finetuned-disease` model to classify images of plant leaves and generate captions describing their health condition or any disease present. Below is an example of how you can use this model in Python using the Hugging Face Transformers library:
|
78 |
+
|
79 |
+
```python
|
80 |
+
from transformers import CLIPProcessor, CLIPModel
|
81 |
+
from PIL import Image
|
82 |
+
import requests
|
83 |
+
|
84 |
+
# Load the model and processor
|
85 |
+
model = CLIPModel.from_pretrained("your_username/clip-vit-large-patch14-finetuned-disease")
|
86 |
+
processor = CLIPProcessor.from_pretrained("openai/clip-vit-large-patch14")
|
87 |
+
|
88 |
+
# Load an image of a plant leaf
|
89 |
+
image_url = "https://example.com/path_to_your_image.jpg"
|
90 |
+
image = Image.open(requests.get(image_url, stream=True).raw)
|
91 |
+
|
92 |
+
# Prepare the image
|
93 |
+
inputs = processor(text=["Apple leaf with Apple scab", "Healthy Tomato leaf", ...], images=image, return_tensors="pt", padding=True)
|
94 |
+
|
95 |
+
# Get predictions
|
96 |
+
outputs = model(**inputs)
|
97 |
+
logits_per_image = outputs.logits_per_image # Image-text similarity score
|
98 |
+
probs = logits_per_image.softmax(dim=1) # Convert logits to probabilities
|
99 |
+
|
100 |
+
# Print the most likely label
|
101 |
+
predicted_label = probs.argmax().item()
|
102 |
+
labels = [
|
103 |
+
"Apple leaf with Apple scab",
|
104 |
+
"Apple leaf with Black rot",
|
105 |
+
...
|
106 |
+
"Healthy Tomato leaf"
|
107 |
+
]
|
108 |
+
print(f"Predicted label: {labels[predicted_label]}")
|
109 |
+
```
|
110 |
+
|