You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduces two classes that will cache the model so creating
predictions for multiple images will only load the model and the
tree of life embeddings once.
Changes the prediction returned values to be more consistent.
One deviation from what was requested with issue #1 is flattening
the results to simplify creating a pandas DataFrame.
Fixes#1
Simplifies the command line interface to default to csv format and process
multiple images.
Adds tests that create predictions. These test require downloading the model
so may be inappropriate for automated testing.
Tests can be run with pytest.
Co-authored-by: Hilmar Lapp <[email protected]>
Co-authored-by: Elizabeth Campolongo <[email protected]>
If you have any issues with installation, please first upgrade pip by running `pip install --upgrade pip`.
31
30
32
-
## Command Line Usage
31
+
## Python Package Usage
32
+
### Predict species classification
33
33
34
-
### Predict classification
34
+
```python
35
+
from bioclip import TreeOfLifeClassifier, Rank
35
36
36
-
#### Example: Predict species for an image
37
-
The example image used below is [`Ursus-arctos.jpeg`](https://huggingface.co/spaces/imageomics/bioclip-demo/blob/ef075807a55687b320427196ac1662b9383f988f/examples/Ursus-arctos.jpeg) from the [bioclip-demo](https://huggingface.co/spaces/imageomics/bioclip-demo).
Output from the `predict()` method showing the dictionary structure:
54
+
```
55
+
[{
56
+
'kingdom': 'Animalia',
57
+
'phylum': 'Chordata',
58
+
'class': 'Mammalia',
59
+
'order': 'Carnivora',
60
+
'family': 'Ursidae',
61
+
'genus': 'Ursus',
62
+
'species_epithet': 'arctos',
63
+
'species': 'Ursus arctos',
64
+
'common_name': 'Kodiak bear'
65
+
'score': 0.9356034994125366
66
+
}]
67
+
```
68
+
69
+
The output from the predict function can be converted into a [pandas DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html) like so:
#### Optional arguments for predicting classifications:
88
-
-`--rank RANK` - rank of the classification (kingdom, phylum, class, order, family, genus, species) [default: species]
89
-
-`--k K` - number of top predictions to show [default: 5]
90
-
-`--format FORMAT` - format of the output (table, json, or csv) [default: table]
91
-
-`--output OUTPUT` - save output to a filename instead of printing it [default: stdout]
99
+
Arguments:
100
+
IMAGE_FILE input image file
92
101
102
+
Options:
103
+
-h --help
104
+
--format=FORMAT format of the output (table or csv) [default: csv]
105
+
--rank=RANK rank of the classification (kingdom, phylum, class, order, family, genus, species)
106
+
[default: species]
107
+
--k=K number of top predictions to show [default: 5]
108
+
--cls=CLS comma separated list of classes to predict, when specified the --rank and
109
+
--k arguments are ignored [default: all]
110
+
--output=OUTFILE print output to file OUTFILE [default: stdout]
111
+
```
93
112
94
-
### Predict from a list of classes
113
+
### Predict classification
95
114
96
-
Create predictions for 3 classes (cat, bird, and bear) for image `Ursus-arctos.jpeg`:
115
+
#### Predict species for an image
116
+
The example images used below are [`Ursus-arctos.jpeg`](https://huggingface.co/spaces/imageomics/bioclip-demo/blob/ef075807a55687b320427196ac1662b9383f988f/examples/Ursus-arctos.jpeg)
117
+
and [`Felis-catus.jpeg`](https://huggingface.co/spaces/imageomics/bioclip-demo/blob/ef075807a55687b320427196ac1662b9383f988f/examples/Felis-catus.jpeg) both from the [bioclip-demo](https://huggingface.co/spaces/imageomics/bioclip-demo).
0 commit comments