|
| 1 | +# Binary Classification Detectors |
| 2 | + |
| 3 | +Binary classification detectors are used to answer yes/no questions about images. Most of Groundlight's documentation examples are for binary classification detectors, as they are the simplest type of detector. |
| 4 | + |
| 5 | +In order to create a binary classification detector, you need to provide a query that asks a yes/no question. For example, "Is there an eagle visible?" or "Is the door fully closed?". |
| 6 | + |
| 7 | +```python |
| 8 | +from groundlight import Groundlight |
| 9 | +gl = Groundlight() |
| 10 | + |
| 11 | +# highlight-start |
| 12 | +detector = gl.create_detector( |
| 13 | + name="eagle-detector", |
| 14 | + query="Is there an eagle visible?", |
| 15 | + confidence_threshold=0.9, |
| 16 | +) |
| 17 | +# highlight-end |
| 18 | +``` |
| 19 | + |
| 20 | +## Submit an Image Query to a Binary Classification Detector |
| 21 | + |
| 22 | +Now that you have created a binary classification detector, you can submit an image query to it. |
| 23 | + |
| 24 | +```python notest |
| 25 | +from groundlight import Groundlight |
| 26 | +gl = Groundlight() |
| 27 | + |
| 28 | +detector = gl.get_detector_by_name("eagle-detector") |
| 29 | + |
| 30 | +# highlight-start |
| 31 | +# Check if an eagle is visible in an image |
| 32 | +image_query = gl.submit_image_query(detector, "path/to/image.jpg") |
| 33 | +# highlight-end |
| 34 | + |
| 35 | +print(f"Result: {image_query.result.label}") |
| 36 | +print(f"Confidence: {image_query.result.confidence}") |
| 37 | +``` |
| 38 | + |
| 39 | +Binary classification detectors return a `label` attribute in the result object, which will be either `"YES"` or `"NO"`. If a query is ambiguous, it is also possible for the detector to return an `"UNCLEAR"` label. |
| 40 | + |
| 41 | +The `confidence` attribute represents the confidence level in the predicted label, which (for a binary classification detector) is a value between 0.5 and 1. A higher confidence score indicates that the model is more certain about its prediction. |
| 42 | + |
| 43 | +## Add a label to a Binary Classification Detector |
| 44 | + |
| 45 | +To provide ground truth labels for binary classification detectors, you can specify the label as either `"YES"`, `"NO"`, or `"UNCLEAR"`. This helps improve the accuracy of your detector over time. |
| 46 | + |
| 47 | +```python notest |
| 48 | +from groundlight import Groundlight |
| 49 | +gl = Groundlight() |
| 50 | + |
| 51 | +# highlight-start |
| 52 | +# Add a binary label to the image query from the previous example |
| 53 | +gl.add_label(image_query, label="YES") |
| 54 | +# highlight-end |
| 55 | +``` |
0 commit comments