rdinnager commited on
Commit
2af9bf3
·
verified ·
1 Parent(s): 3d1c972

How-to-Use: use AutoImageProcessor; note torchvision requirement

Browse files
Files changed (1) hide show
  1. README.md +10 -6
README.md CHANGED
@@ -83,14 +83,17 @@ PhenoVisionL is initialized from the trained PhenoVision reproductive structures
83
 
84
  ## How to Use
85
 
 
 
 
86
  ```python
87
- from transformers import ViTForImageClassification, ViTImageProcessor
88
  from PIL import Image
89
  import torch
90
 
91
  # Load model and processor
92
- processor = ViTImageProcessor.from_pretrained("phenobase/phenovisionL")
93
- model = ViTForImageClassification.from_pretrained("phenobase/phenovisionL")
94
  model.eval()
95
 
96
  # Run inference
@@ -101,9 +104,10 @@ with torch.no_grad():
101
  outputs = model(**inputs)
102
  probs = torch.sigmoid(outputs.logits)[0]
103
 
104
- green_prob = probs[0].item()
105
- colored_prob = probs[1].item()
106
- breaking_buds_prob = probs[2].item()
 
107
 
108
  print(f"Green leaves: {green_prob:.3f}")
109
  print(f"Colored leaves: {colored_prob:.3f}")
 
83
 
84
  ## How to Use
85
 
86
+ Requires `transformers`, `torch`, and `torchvision` (torchvision is needed by the
87
+ image processor in `transformers` v5+).
88
+
89
  ```python
90
+ from transformers import AutoModelForImageClassification, AutoImageProcessor
91
  from PIL import Image
92
  import torch
93
 
94
  # Load model and processor
95
+ processor = AutoImageProcessor.from_pretrained("phenobase/phenovisionL")
96
+ model = AutoModelForImageClassification.from_pretrained("phenobase/phenovisionL")
97
  model.eval()
98
 
99
  # Run inference
 
104
  outputs = model(**inputs)
105
  probs = torch.sigmoid(outputs.logits)[0]
106
 
107
+ # Output order is [green, colored, breaking_buds].
108
+ green_prob = probs[0].item() # index 0 = green leaves
109
+ colored_prob = probs[1].item() # index 1 = colored leaves
110
+ breaking_buds_prob = probs[2].item() # index 2 = breaking leaf buds
111
 
112
  print(f"Green leaves: {green_prob:.3f}")
113
  print(f"Colored leaves: {colored_prob:.3f}")