Ví dụ về thăm dò VOC
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.
Thử yolo explorer
powered by Explorer API
Đơn giản pip install ultralytics
và chạy yolo explorer
trong thiết bị đầu cuối của bạn để chạy các truy vấn tùy chỉnh và tìm kiếm ngữ nghĩa trên các tập dữ liệu ngay bên trong trình duyệt của bạn!
Ghi chú cộng đồng ⚠️
Tính đến ultralytics>=8.3.10
, Ultralytics hỗ trợ explorer đã bị loại bỏ. Nhưng đừng lo lắng! Bây giờ bạn có thể truy cập chức năng tương tự và thậm chí được cải tiến thông qua Ultralytics TRUNG TÂM, nền tảng trực quan không cần mã của chúng tôi được thiết kế để hợp lý hóa quy trình làm việc của bạn. Với Ultralytics HUB, bạn có thể tiếp tục khám phá, trực quan hóa và quản lý dữ liệu của mình một cách dễ dàng, tất cả mà không cần viết một dòng mã nào. Hãy chắc chắn kiểm tra và tận dụng các tính năng mạnh mẽ của nó!🚀
Cài đặt
Cài đặt Pip ultralytics
Và sự phụ thuộc và kiểm tra phần mềm và phần cứng.
Similarity Search
Utilize the power of vector similarity search to find the similar data points in your dataset along with their distance in the embedding space. Simply create an embeddings table for the given dataset-model pair. It is only needed once, and it is reused automatically.
Sau khi bảng nhúng được xây dựng, bạn có thể chạy tìm kiếm ngữ nghĩa theo bất kỳ cách nào sau đây:
- On a given index / list of indices in the dataset like - 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) In case of multiple inputs, the aggregate of their embeddings is used.
You get a pandas dataframe with the limit number of most similar data points to the input, along with their distance in the embedding space. You can use this dataset to perform further filtering
Bạn cũng có thể sử dụng biểu đồ các mẫu tương tự trực tiếp bằng cách sử dụng plot_similar
sử dụng
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 external images
Ask AI: Search or filter with Natural Language
You can prompt the Explorer object with the kind of data points you want to see, and it'll try to return a dataframe with those. Because it is powered by LLMs, it doesn't always get it right. In that case, it'll return None.
df = exp.ask_ai("show me images containing more than 10 objects with at least 2 persons")
df.head(5)
để vẽ biểu đồ các kết quả này bạn có thể sử dụng plot_query_result
util Example:
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)
Run SQL queries on your Dataset
Sometimes you might want to investigate a certain type of entries in your dataset. For this Explorer allows you to execute SQL queries. It accepts either of the formats:
- Queries beginning with "WHERE" will automatically select all columns. This can be thought of as a shorthand query
- Bạn cũng có thể viết các truy vấn đầy đủ trong đó bạn có thể chỉ định các cột nào để chọn
Điều này có thể được sử dụng để điều tra hiệu suất mô hình và các điểm dữ liệu cụ thể. Ví dụ:
- giả sử mô hình của bạn gặp khó khăn khi xử lý hình ảnh có người và chó. Bạn có thể viết truy vấn như thế này để chọn các điểm có ít nhất 2 người VÀ ít nhất một con chó.
Bạn có thể kết hợp truy vấn SQL và tìm kiếm ngữ nghĩa để lọc xuống loại kết quả cụ thể
table = exp.sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10")
exp.plot_sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10", labels=True)
table = exp.sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10")
print(table)
Giống như tìm kiếm tương tự, bạn cũng có một tiện ích để trực tiếp vẽ các truy vấn sql bằng cách sử dụng exp.plot_sql_query
exp.plot_sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10", labels=True)
Working with embeddings Table (Advanced)
Explorer hoạt động trên LanceDB bảng nội bộ. Bạn có thể truy cập trực tiếp vào bảng này bằng cách sử dụng Explorer.table
đối tượng và chạy truy vấn thô, đẩy xuống bộ lọc trước và sau, v.v.
Run raw queries¶
Vector Search tìm các vector gần nhất từ cơ sở dữ liệu. Trong hệ thống đề xuất hoặc công cụ tìm kiếm, bạn có thể tìm thấy các sản phẩm tương tự từ sản phẩm bạn đã tìm kiếm. Trong LLM và các ứng dụng AI khác, mỗi điểm dữ liệu có thể được trình bày bằng các nhúng được tạo từ một số mô hình, nó trả về các tính năng có liên quan nhất.
Tìm kiếm trong không gian vectơ có chiều cao là tìm K-Gần-Gần-Nhất (KNN) của vectơ truy vấn.
Metric In LanceDB, a Metric is the way to describe the distance between a pair of vectors. Currently, it supports the following metrics:
- L2
- Cô sin
- 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 for i in range(256)]
table.search(dummy_img_embedding).limit(5).to_pandas()
Interconversion to popular data formats
Làm việc với nhúng
Bạn có thể truy cập nhúng thô từ Bảng Lancedb và phân tích nó. Nhúng hình ảnh được lưu trữ trong cột vector
import numpy as np
embeddings = table.to_pandas()["vector"].tolist()
embeddings = np.array(embeddings)
Biểu đồ phân tán
Một trong những bước sơ bộ trong việc phân tích nhúng là bằng cách vẽ chúng trong không gian 2D thông qua việc giảm chiều. Hãy thử một ví dụ
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA # pip install scikit-learn
# 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()
Chỉ số tương đồng
Đây là một ví dụ đơn giản về một hoạt động được hỗ trợ bởi bảng nhúng. Explorer đi kèm với similarity_index
hoạt động-
- Phương pháp này cố gắng ước tính mức độ giống nhau của từng điểm dữ liệu với phần còn lại của tập dữ liệu.
- It does that by counting how many image embeddings lie closer than max_dist to the current image in the generated embedding space, considering top_k similar images at a time.
Đối với một tập dữ liệu, mô hình nhất định, max_dist
& top_k
chỉ số tương đồng sau khi tạo sẽ được sử dụng lại. Trong trường hợp tập dữ liệu của bạn đã thay đổi hoặc bạn chỉ cần tạo lại chỉ số tương đồng, bạn có thể truyền force=True
. Similar to vector and SQL search, this also comes with a util to directly plot it. Let's look
sim_idx = exp.similarity_index(max_dist=0.2, top_k=0.01)
exp.plot_similarity_index(max_dist=0.2, top_k=0.01)
at the plot first
Bây giờ chúng ta hãy xem kết quả của hoạt động
Hãy tạo một truy vấn để xem những điểm dữ liệu nào có số điểm tương đồng lớn hơn 30 và vẽ các hình ảnh tương tự như chúng.
Bạn sẽ thấy một cái gì đó như thế này