VOC Exploration Example¶
中文 | 한국어 | 日本語 | Русский | Deutsch | Français | Español | Português | Türkçe | Tiếng Việt | العربية
Welcome to the Ultralytics Explorer API notebook! This notebook serves as the starting point for exploring the various resources available to help you get started with using Ultralytics to explore your datasets using with the power of semantic search. You can utilities out of the box that allow you to examine specific types of labels using vector search or even SQL queries.
Wir hoffen, dass die Ressourcen in diesem Notizbuch dir dabei helfen, das Beste aus Ultralytics herauszuholen. Bitte sieh dir die Explorer Docs an, um Details zu erfahren, wirf ein Problem auf GitHub auf, um Unterstützung zu erhalten, und tritt unserer Discord-Community bei, um Fragen zu stellen und zu diskutieren!
Versuche yolo explorer
powered by Exlorer API
Einfach pip install ultralytics
und laufen yolo explorer
in deinem Terminal, um benutzerdefinierte Abfragen und die semantische Suche auf deinen Datensätzen direkt in deinem Browser auszuführen!
Ultralytics Explorer support deprecated ⚠️¶
As of ultralytics>=8.3.10
, Ultralytics explorer support has been deprecated. But don’t worry! You can now access similar and even enhanced functionality through Ultralytics HUB, our intuitive no-code platform designed to streamline your workflow. With Ultralytics HUB, you can continue exploring, visualizing, and managing your data effortlessly, all without writing a single line of code. Make sure to check it out and take advantage of its powerful features!🚀
Setup¶
Pip installieren ultralytics
und Abhängigkeiten und überprüfe Software und Hardware.
%pip install ultralytics[explorer] openai
import ultralytics
ultralytics.checks()
von ultralytics importieren Explorer
Ähnlichkeitssuche¶
Nutze die Leistungsfähigkeit der vektoriellen Ähnlichkeitssuche, um die ähnlichen Datenpunkte in deinem Datensatz und ihren Abstand im Einbettungsraum zu finden. Erstelle einfach eine Einbettungstabelle für das gegebene Datensatz-Modell-Paar. Sie wird nur einmal benötigt und automatisch wiederverwendet.
exp = Explorer("VOC.yaml", model="yolo11n.pt")
exp.create_embeddings_table()
Sobald die Tabelle mit den Einbettungen erstellt ist, kannst du die semantische Suche auf eine der folgenden Arten durchführen:
- Auf einen bestimmten Index / eine Liste von Indizes im Datensatz wie -
exp.get_similar(idx=[1,10], limit=10)
- On any image/ list of images not in the dataset -
exp.get_similar(img=["path/to/img1", "path/to/img2"], limit=10)
Wenn es mehrere Eingaben gibt, wird die Summe ihrer Einbettungen verwendet.
Du erhältst einen Pandas-Datenrahmen mit dem limit
Anzahl der Datenpunkte, die der Eingabe am ähnlichsten sind, zusammen mit ihrem Abstand im Einbettungsraum. Du kannst diesen Datensatz verwenden, um weitere Filterungen vorzunehmen
ähnlich = exp.get_similar(idx=1, Grenze=10)
ähnlich.Kopf()
Du kannst die ähnlichen Proben auch direkt mit der Funktion plot_similar
util
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(
img="https://ultralytics.com/images/bus.jpg", limit=10, labels=False
) # Can also pass any external images
2. Ask AI: Mit natürlicher Sprache suchen oder filtern¶
Du kannst dem Explorer-Objekt die Art von Datenpunkten vorgeben, die du sehen willst, und es wird versuchen, einen Datenrahmen mit diesen Punkten zurückzugeben. Da er von LLMs gesteuert wird, gelingt ihm das nicht immer. In diesem Fall gibt er keinen zurück.
df = exp.ask_ai("Zeige mir Bilder, die mehr als 10 Objekte mit mindestens 2 Personen enthalten")
df.Kopf(5)
Für das Plotten dieser Ergebnisse kannst du plot_query_result
Beispiel nutzen:
plt = plot_query_result(exp.ask_ai("show me 10 images containing exactly 2 persons"))
Image.fromarray(plt)
# plot
from PIL import Image
from ultralytics.data.explorer import plot_query_result
plt = plot_query_result(exp.ask_ai("show me 10 images containing exactly 2 persons"))
Image.fromarray(plt)
3. Führe SQL-Abfragen auf deinem Dataset aus!¶
Manchmal möchtest du vielleicht eine bestimmte Art von Einträgen in deinem Datensatz untersuchen. Zu diesem Zweck kannst du im Explorer SQL-Abfragen ausführen. Er akzeptiert eines der beiden Formate:
- Abfragen, die mit "WHERE" beginnen, wählen automatisch alle Spalten aus. Das kann man sich als eine Art Kurzabfrage vorstellen
- Du kannst auch vollständige Abfragen schreiben, bei denen du angeben kannst, welche Spalten ausgewählt werden sollen
Dies kann genutzt werden, um die Modellleistung und bestimmte Datenpunkte zu untersuchen. Zum Beispiel:
- Nehmen wir an, dein Modell kämpft mit Bildern, auf denen Menschen und Hunde zu sehen sind. Du kannst eine Abfrage wie diese schreiben, um die Punkte auszuwählen, die mindestens 2 Menschen UND mindestens einen Hund enthalten.
Du kannst SQL-Abfragen und die semantische Suche kombinieren, um bestimmte Arten von Ergebnissen herauszufiltern
Tabelle = exp.sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10")
Tabelle
Genau wie bei der Ähnlichkeitssuche kannst du auch die SQL-Abfragen direkt mit exp.plot_sql_query
exp.plot_sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10", labels=True)
Tabelle = exp.Tabelle
Tabelle.schema
Rohabfragen durchführen¶
Die Vektorsuche findet die nächstgelegenen Vektoren in der Datenbank. In einem Empfehlungssystem oder einer Suchmaschine kannst du ähnliche Produkte finden wie die, die du gesucht hast. In LLM und anderen KI-Anwendungen kann jeder Datenpunkt durch die aus einigen Modellen generierten Einbettungen dargestellt werden, die die relevantesten Merkmale liefern.
Bei einer Suche im hochdimensionalen Vektorraum geht es darum, K-Nächste-Nachbarn (KNN) des Abfragevektors zu finden.
Metrik In LanceDB ist eine Metrik die Art und Weise, wie der Abstand zwischen einem Paar Vektoren beschrieben wird. Derzeit werden die folgenden Metriken unterstützt:
- L2
- Kosinus
- Dot Explorer's similarity search uses L2 by default. You can run queries on tables directly, or use the lance format to build custom utilities to manage datasets. More details on available LanceDB table ops in the docs
dummy_img_embedding = [i für i in Bereich(256)]
Tabelle.Suche(dummy_img_embedding).limit(5).to_pandas()
Interkonvertierung in gängige Datenformate¶
df = Tabelle.to_pandas()
pa_table = Tabelle.to_arrow()
Arbeit mit Einbettungen¶
Du kannst auf die rohen Einbettungen in der lancedb-Tabelle zugreifen und sie analysieren. Die Bildeinbettungen werden in der Spalte vector
importiere numpy as np
Einbettungen = Tabelle.to_pandas()["vector"].to_list()
Einbettungen = np.array(Einbettungen)
Scatterplot¶
Einer der ersten Schritte bei der Analyse von Einbettungen ist die Darstellung im 2D-Raum mittels Dimensionalitätsreduktion. Versuchen wir ein Beispiel
!pip installieren scikit-learn --q
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from sklearn.decomposition import PCA
# Reduce dimensions using PCA to 3 components for visualization in 3D
pca = PCA(n_components=3)
reduced_data = pca.fit_transform(embeddings)
# Create a 3D scatter plot using Matplotlib's Axes3D
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection="3d")
# Scatter plot
ax.scatter(reduced_data[:, 0], reduced_data[:, 1], reduced_data[:, 2], alpha=0.5)
ax.set_title("3D Scatter Plot of Reduced 256-Dimensional Data (PCA)")
ax.set_xlabel("Component 1")
ax.set_ylabel("Component 2")
ax.set_zlabel("Component 3")
plt.show()
4. Ähnlichkeitsindex¶
Hier ist ein einfaches Beispiel für eine Operation, die von der Einbettungstabelle unterstützt wird. Der Explorer kommt mit einer similarity_index
Betrieb-
- Sie versucht abzuschätzen, wie ähnlich jeder Datenpunkt dem Rest des Datensatzes ist.
- Dabei wird gezählt, wie viele Bildeinbettungen näher liegen als
max_dist
zum aktuellen Bild im generierten Einbettungsraum, unter Berücksichtigungtop_k
ähnliche Bilder zu einer Zeit.
Für einen bestimmten Datensatz das Modell, max_dist
& top_k
wird der einmal erstellte Ähnlichkeitsindex wiederverwendet. Falls sich dein Datensatz geändert hat oder du den Ähnlichkeitsindex einfach neu erstellen musst, kannst du die force=True
. Ähnlich wie bei der Vektorsuche und der SQL-Suche gibt es auch hier ein Tool, mit dem du die Daten direkt darstellen kannst. Schauen wir uns zuerst den Plot an
exp.plot_similarity_index(max_dist=0.2, top_k=0.01)
Schauen wir uns nun die Ausgabe der Operation an
importiere numpy as np
sim_idx = exp.Ähnlichkeit_index(max_dist=0.2, top_k=0.01, Kraft=Falsch)
sim_idx
Lass uns eine Abfrage erstellen, um zu sehen, welche Datenpunkte eine Ähnlichkeitszahl von mehr als 30 haben, und ähnliche Bilder einzeichnen.
import numpy as np
sim_count = np.array(sim_idx["count"])
sim_idx["im_file"][sim_count > 30]
Du solltest etwas wie das hier sehen
exp.plot_similar(idx=[7146, 14035]) # Using avg embeddings of 2 images