Fix explorer.md python codeblocks (#18471)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Glenn Jocher 2025-01-02 21:11:17 +01:00 committed by GitHub
parent 26ff8b5914
commit 126867e355
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -53,9 +53,7 @@ Pip install `ultralytics` and [dependencies](https://github.com/ultralytics/ultr
```bash ```bash
%pip install ultralytics[explorer] openai %pip install ultralytics[explorer] openai
import ultralytics yolo checks
ultralytics.checks()
``` ```
## Similarity Search ## Similarity Search
@ -88,11 +86,9 @@ You can use the also plot the similar samples directly using the `plot_similar`
```python ```python
exp.plot_similar(idx=6500, limit=20) exp.plot_similar(idx=6500, limit=20)
# exp.plot_similar(idx=[100,101], limit=10) # Can also pass list of idxs or imgs exp.plot_similar(idx=[100, 101], limit=10) # Can also pass list of idxs or imgs
exp.plot_similar( exp.plot_similar(img="https://ultralytics.com/images/bus.jpg", limit=10, labels=False) # Can also pass external images
img="https://ultralytics.com/images/bus.jpg", limit=10, labels=False
) # Can also pass any external images
``` ```
![Similarity search image 2](https://github.com/ultralytics/docs/releases/download/0/similarity-search-image-2.avif) ![Similarity search image 2](https://github.com/ultralytics/docs/releases/download/0/similarity-search-image-2.avif)
@ -149,7 +145,7 @@ exp.plot_sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%'
```python ```python
table = exp.sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10") table = exp.sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10")
table print(table)
``` ```
Just like similarity search, you also get a util to directly plot the sql queries using `exp.plot_sql_query` Just like similarity search, you also get a util to directly plot the sql queries using `exp.plot_sql_query`
@ -166,7 +162,7 @@ Explorer works on [LanceDB](https://lancedb.github.io/lancedb/) tables internall
```python ```python
table = exp.table table = exp.table
table.schema print(table.schema)
``` ```
### Run raw queries¶ ### Run raw queries¶
@ -213,12 +209,8 @@ One of the preliminary steps in analysing embeddings is by plotting them in 2D s
![Scatterplot Example](https://github.com/ultralytics/docs/releases/download/0/scatterplot-sql-queries.avif) ![Scatterplot Example](https://github.com/ultralytics/docs/releases/download/0/scatterplot-sql-queries.avif)
```python ```python
pip install scikit-learn
%matplotlib inline
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np from sklearn.decomposition import PCA # pip install scikit-learn
from sklearn.decomposition import PCA
# Reduce dimensions using PCA to 3 components for visualization in 3D # Reduce dimensions using PCA to 3 components for visualization in 3D
pca = PCA(n_components=3) pca = PCA(n_components=3)