Ultralytics ãšã¯ã¹ãããŒã©API
ã³ãã¥ããã£ã»ããŒã â ïž
çŸåš ultralytics>=8.3.10
Ultralytics ãšã¯ã¹ãããŒã©ãŒã®ãµããŒãã¯å»æ¢ãããŸãããããããå¿é
ãªãïŒçŸåšã§ã¯ãåæ§ã®æ©èœãããã«åŒ·åãããæ©èœã« Ultralytics ããHUBã¯ãã¯ãŒã¯ãããŒãåçåããããã«èšèšããããçŽæçãªã³ãŒãäžèŠã®ãã©ãããã©ãŒã ã§ããUltralytics HUBã䜿ãã°ãã³ãŒããäžè¡ãæžãããšãªããããŒã¿ã®æ¢çŽ¢ãèŠèŠåã管çã楜ã«ç¶ããããšãã§ããŸãããã²ãã§ãã¯ããŠããã®åŒ·åãªæ©èœãã掻çšãã ããðã
ã¯ããã«
Explorer API ã¯ãããŒã¿ã»ãããæ¢çŽ¢ããããã®Python API ã§ããSQLã¯ãšãªã䜿ã£ãããŒã¿ã»ããã®ãã£ã«ã¿ãªã³ã°ãæ€çŽ¢ããã¯ãã«é¡äŒŒåºŠæ€çŽ¢ãã»ãã³ãã£ãã¯æ€çŽ¢ããµããŒãããŠããŸãã
èŠããã ïŒ Ultralytics ãšã¯ã¹ãããŒã©APIã®æŠèŠ
ã€ã³ã¹ããŒã«
ãšã¯ã¹ãããŒã©ãŒã®æ©èœã®äžéšã¯å€éšã©ã€ãã©ãªã«äŸåããŠããŸãããããã¯äœ¿çšæã«èªåçã«ã€ã³ã¹ããŒã«ãããããããã®äŸåé¢ä¿ãæåã§ã€ã³ã¹ããŒã«ããã«ã¯ã以äžã®ã³ãã³ãã䜿çšããïŒ
䜿çšæ¹æ³
from ultralytics import Explorer
# Create an Explorer object
explorer = Explorer(data="coco128.yaml", model="yolo11n.pt")
# Create embeddings for your dataset
explorer.create_embeddings_table()
# Search for similar images to a given image/images
dataframe = explorer.get_similar(img="path/to/image.jpg")
# Or search for similar images to a given index/indices
dataframe = explorer.get_similar(idx=0)
泚
äžããããããŒã¿ã»ãããšã¢ãã«ã®ãã¢ã«å¯Ÿããåã蟌ã¿ããŒãã«ã¯ãäžåºŠã ãäœæãããåå©çšãããŸãããããã¯ãªã³ãã£ã¹ã¯ã§ã¹ã±ãŒã«ããLanceDBã䜿çšããŠãããããCOCOã®ãããªå€§èŠæš¡ãªããŒã¿ã»ããã§ãã¡ã¢ãªäžè¶³ã«ãªãããšãªããšã³ãããã£ã³ã°ãäœæããåå©çšããããšãã§ããŸãã
embeddingsããŒãã«ã匷å¶çã«æŽæ°ãããå Žåã¯ã次ã®ããã«ããŸãã force=True
ãžã® create_embeddings_table
ã¡ãœããã䜿çšããã
LanceDBããŒãã«ã»ãªããžã§ã¯ãã«çŽæ¥ã¢ã¯ã»ã¹ããŠé«åºŠãªåæãè¡ãããšãã§ããŸãã詳ããã¯ãåã蟌ã¿ããŒãã«ã䜿çšããã»ã¯ã·ã§ã³ãã芧ãã ããã
1.é¡äŒŒæ€çŽ¢
é¡äŒŒç»åæ€çŽ¢ã¯ãäžããããç»åã«é¡äŒŒããç»åãèŠã€ããæè¡ã§ãããé¡äŒŒç»åã¯é¡äŒŒã®åã蟌ã¿ãæã€ãšããèãã«åºã¥ããŠããŸããåã蟌ã¿ããŒãã«ãæ§ç¯ããããšã以äžã®ããããã®æ¹æ³ã§ã»ãã³ãã£ãã¯æ€çŽ¢ãå®è¡ããããšãã§ããŸãïŒ
- ããŒã¿ã»ããäžã®æå®ãããã€ã³ããã¯ã¹ïŒãŸãã¯ã€ã³ããã¯ã¹ã®ãªã¹ãïŒ
exp.get_similar(idx=[1,10], limit=10)
- ããŒã¿ã»ããã«å«ãŸããŠããªãç»åãŸãã¯ç»åã®ãªã¹ãïŒ
exp.get_similar(img=["path/to/img1", "path/to/img2"], limit=10)
è€æ°ã®å ¥åãããå Žåã¯ããããã®åã蟌ã¿å€ã®åèšã䜿ãããã
ã§pandasããŒã¿ãã¬ãŒã ãååŸããŸãã limit
å
¥åãšæãé¡äŒŒããããŒã¿ç¹ã®æ°ãšãåã蟌ã¿ç©ºéã«ããããããã®è·é¢ããã®ããŒã¿ã»ããã䜿ã£ãŠãããã«ãã£ã«ã¿ãªã³ã°ãè¡ãããšãã§ãã
ã»ãã³ãã£ãã¯æ€çŽ¢
from ultralytics import Explorer
# create an Explorer object
exp = Explorer(data="coco128.yaml", model="yolo11n.pt")
exp.create_embeddings_table()
similar = exp.get_similar(img="https://ultralytics.com/images/bus.jpg", limit=10)
print(similar.head())
# Search using multiple indices
similar = exp.get_similar(
img=["https://ultralytics.com/images/bus.jpg", "https://ultralytics.com/images/bus.jpg"],
limit=10,
)
print(similar.head())
from ultralytics import Explorer
# create an Explorer object
exp = Explorer(data="coco128.yaml", model="yolo11n.pt")
exp.create_embeddings_table()
similar = exp.get_similar(idx=1, limit=10)
print(similar.head())
# Search using multiple indices
similar = exp.get_similar(idx=[1, 10], limit=10)
print(similar.head())
é¡äŒŒç»åã®ãããã
ã䜿ã£ãŠé¡äŒŒç»åãããããããããšãã§ããŸãã plot_similar
ã¡ãœãããšåãåŒæ°ãåãããã®ã¡ãœãã㯠get_similar
ã§ãé¡äŒŒããç»åãæ Œåç¶ã«ããããããã
é¡äŒŒç»åã®ãããã
2.Ask AI (èªç¶èšèªã¯ãšãª)
ããã«ãããèªç¶èšèªã䜿ã£ãŠããŒã¿ã»ãããã©ã®ããã«ãã£ã«ã¿ãªã³ã°ãããããæžãããšãã§ãããSQLã¯ãšãªã®èšè¿°ã«ç¿çããå¿ èŠã¯ãããŸãããç§ãã¡ã®AIã¯ãšãªãŒãžã§ãã¬ãŒã¿ãŒããèªåçã«ãããè¡ããŸããäŸãã°ãã人ã1人ãç¬ã2å¹åã£ãŠããç»åã100æ衚瀺ããŠãã ãããä»ã®ãªããžã§ã¯ãããããŸã "ãšèšãã°ãå éšã§ã¯ãšãªãçæãããã®çµæã衚瀺ããŸãã 泚æïŒããã¯LLMã䜿çšããŠããã®ã§ãçµæã¯ç¢ºççã§ãããæã«ã¯ééã£ãŠããŸããããããŸããã
AIã«èã
from ultralytics import Explorer
from ultralytics.data.explorer import plot_query_result
# create an Explorer object
exp = Explorer(data="coco128.yaml", model="yolo11n.pt")
exp.create_embeddings_table()
df = exp.ask_ai("show me 100 images with exactly one person and 2 dogs. There can be other objects too")
print(df.head())
# plot the results
plt = plot_query_result(df)
plt.show()
3.SQLã¯ãšãª
ããŒã¿ã»ããã«å¯Ÿã㊠SQL ã¯ãšãªãå®è¡ããã«ã¯ sql_query
ã¡ãœããã䜿çšããŸãããã®ã¡ãœããã¯ãSQL ã¯ãšãªãå
¥åãšããŠåãåãããã®çµæã pandas ããŒã¿ãã¬ãŒã ãšããŠè¿ããŸãã
SQLã¯ãšãª
SQLã¯ãšãªã®çµæããããããã
SQLã¯ãšãªã®çµæãããããããããšãã§ããŸãã plot_sql_query
ã¡ãœãããšåãåŒæ°ãåãããã®ã¡ãœãã㯠sql_query
ãããŠçµæãã°ãªããã«ããããããã
SQLã¯ãšãªã®çµæããããããã
4.åã蟌ã¿è¡šã䜿ã
embeddingsããŒãã«ãçŽæ¥æäœããããšãã§ããŸããembeddingsããŒãã«ãäœæããããšããã®ããŒãã«ã«ã¯ Explorer.table
ããã
ãšã¯ã¹ãããŒã©ãŒã¯ ã©ã³ã¹DB ããŒãã«ãå
éšçã«äœ¿çšããŸãããã®ããŒãã«ã«ã¯ Explorer.table
ãªããžã§ã¯ããäœæããçã®ã¯ãšãªãŒãå®è¡ããããããªã»ãã£ã«ã¿ãŒããã¹ãã»ãã£ã«ã¿ãŒãããã·ã¥ããŠã³ãããããããšãã§ããŸãã
ãã®ããŒãã«ã§ã§ããããšã®äŸãããã€ã玹ä»ãããïŒ
çã®åã蟌ã¿ãååŸãã
äŸ
äºåã»äºåŸãã£ã«ã¿ã«ããé«åºŠãªã¯ãšãª
äŸ
ãã¯ãã«ã»ã€ã³ããã¯ã¹ã®äœæ
倧èŠæš¡ãªããŒã¿ã»ããã䜿çšããå Žåã¯ãå°çšã®ãã¯ãã«ã»ã€ã³ããã¯ã¹ãäœæããŠãããé«éãªã¯ãšãªãå®è¡ããããšãã§ããŸãããã㯠create_index
ã¡ãœããã䜿çšããã
å©çšå¯èœãªãã¯ãã«ã»ã€ã³ããã¯ã¹ã®çš®é¡ãšãã©ã¡ãŒã¿ã®è©³çŽ°ã«ã€ããŠã¯ããã¡ããã芧ãã ããã å°æ¥çã«ã¯ããšã¯ã¹ãããŒã©APIããçŽæ¥ãã¯ãã«ã»ã€ã³ããã¯ã¹ãäœæããããã®ãµããŒããè¿œå ããäºå®ã§ãã
5.åã蟌ã¿ã¢ããªã±ãŒã·ã§ã³
åã蟌ã¿è¡šã䜿ã£ãŠãããŸããŸãªæ¢çŽ¢çåæãè¡ãããšãã§ããã以äžã«ããã€ãã®äŸã瀺ããŸãïŒ
é¡äŒŒæ§ææ°
ãšã¯ã¹ãããŒã©ãŒã«ã¯ similarity_index
ãªãã¬ãŒã·ã§ã³ãè¡ãïŒ
- ããã¯ãåããŒã¿ãã€ã³ããæ®ãã®ããŒã¿ã»ãããšã©ã®çšåºŠé¡äŒŒããŠããããæšå®ããããšãããã®ã§ããã
- ãããè¿ãç»ååã蟌ã¿ãããã€ããããã«ãŠã³ãããããšã§ãããè¡ãã
max_dist
ãïŒçæãããåã蟌ã¿ç©ºéå ã®çŸåšã®ç»åã«é©çšãããtop_k
åããããªç»åãäžåºŠã«èŠãããšãã§ããã
ããã¯ã以äžã®ã«ã©ã ãæã€pandasããŒã¿ãã¬ãŒã ãè¿ãïŒ
idx
:ããŒã¿ã»ããäžã®ç»åã®ã€ã³ããã¯ã¹im_file
:ç»åãã¡ã€ã«ãžã®ãã¹count
:ãããè¿ãããŒã¿ã»ããã®ç»åã®æ°ãmax_dist
çŸåšã®ç»åã«sim_im_files
:ãžã®ãã¹ã®ãªã¹ããcount
é¡äŒŒç»å
ããã
äžããããããŒã¿ã»ããã«å¯ŸããŠãã¢ãã«ã max_dist
& top_k
ãæž¡ããšãäžåºŠçæãããé¡äŒŒåºŠã€ã³ããã¯ã¹ãåå©çšããããããŒã¿ã»ãããå€æŽãããå Žåããããã¯åã«é¡äŒŒåºŠã€ã³ããã¯ã¹ãåçæããå¿
èŠãããå Žåã次ã®ããã«æž¡ãããšãã§ããŸãã force=True
.
é¡äŒŒæ§ææ°
é¡äŒŒåºŠã€ã³ããã¯ã¹ã䜿çšããŠãããŒã¿ã»ããããã£ã«ã¿ãªã³ã°ããããã®ã«ã¹ã¿ã æ¡ä»¶ãæ§ç¯ããããšãã§ããŸããããšãã°ãããŒã¿ã»ããå ã®ã©ã®ç»åãšã䌌ãŠããªãç»åããã£ã«ã¿ãªã³ã°ããã«ã¯ã次ã®ã³ãŒãã䜿ããŸãïŒ
åã蟌ã¿ç©ºéãå¯èŠåãã
ã奜ã¿ã®ããããããŒã«ã䜿ã£ãŠãåã蟌ã¿ç©ºéãå¯èŠåããããšãã§ããŸããäŸãã°ãmatplotlibã䜿ã£ãç°¡åãªäŸã§ãïŒ
import matplotlib.pyplot as plt
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 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()
ãšã¯ã¹ãããŒã©APIã䜿çšããŠãç¬èªã®CVããŒã¿ã»ãã調æ»ã¬ããŒãã®äœæãéå§ããŸããã€ã³ã¹ãã¬ãŒã·ã§ã³ãåŸãããã«
Ultralytics Explorerã䜿çšããŠæ§ç¯ãããã¢ããª
ãšã¯ã¹ãããŒã©APIãããŒã¹ã«ããGUIãã¢ããè©Šããã ããã
è¿æ¥å ¬é
- [ããŒã¿ã»ããããç¹å®ã®ã©ãã«ãããŒãžããŸããäŸ - ãã¹ãŠãã€ã³ããŒã
person
COCOãšcar
ã·ãã£ã¹ã±ãŒãã®ã©ãã« - [æå®ãããéŸå€ãããé«ãé¡äŒŒåºŠææ°ãæã€ç»åãåé€ããŸãã
- [ãšã³ããªãŒãããŒãž/åé€ããåŸãæ°ããããŒã¿ã»ãããèªåçã«æ°žç¶åããã
- [é«åºŠãªããŒã¿ã»ããèŠèŠå
ããããã質å
Ultralytics Explorer APIã¯äœã«äœ¿ãã®ã§ããïŒ
Ultralytics Explorer API ã¯ãå æ¬çãªããŒã¿ã»ããæ¢çŽ¢ã®ããã«èšèšãããŠãããSQLã¯ãšãªããã¯ãã«é¡äŒŒåºŠæ€çŽ¢ãã»ãã³ãã£ãã¯æ€çŽ¢ã䜿çšããŠãããŒã¿ã»ããããã£ã«ã¿ãªã³ã°ããã³æ€çŽ¢ããããšãã§ããããã®åŒ·åãªPython API ã¯å€§èŠæš¡ãªããŒã¿ã»ãããåŠçã§ãããããUltralytics ã¢ãã«ã䜿çšããããŸããŸãªã³ã³ãã¥ãŒã¿ã»ããžã§ã³ã»ã¿ã¹ã¯ã«æé©ã§ãã
Ultralytics Explorer APIã¯ã©ã®ããã«ã€ã³ã¹ããŒã«ããã®ã§ããïŒ
Ultralytics Explorer APIãšãã®äŸåé¢ä¿ãã€ã³ã¹ããŒã«ããã«ã¯ã以äžã®ã³ãã³ãã䜿çšããïŒ
ããã«ããããšã¯ã¹ãããŒã©APIã®æ©èœã«å¿ èŠãªå€éšã©ã€ãã©ãªããã¹ãŠèªåçã«ã€ã³ã¹ããŒã«ãããŸããã»ããã¢ããã®è©³çŽ°ã«ã€ããŠã¯ãããã¥ã¡ã³ãã®ã€ã³ã¹ããŒã«ã»ã¯ã·ã§ã³ãåç §ããŠãã ããã
é¡äŒŒæ€çŽ¢ã«Ultralytics Explorer API ã䜿çšããã«ã¯ã©ãããã°ããã§ããïŒ
Ultralytics Explorer API ã䜿ã£ãŠãembeddings ããŒãã«ãäœæããé¡äŒŒç»åãæ€çŽ¢ããããšãã§ããŸãã以äžã«åºæ¬çãªäŸã瀺ããŸãïŒ
from ultralytics import Explorer
# Create an Explorer object
explorer = Explorer(data="coco128.yaml", model="yolo11n.pt")
explorer.create_embeddings_table()
# Search for similar images to a given image
similar_images_df = explorer.get_similar(img="path/to/image.jpg")
print(similar_images_df.head())
詳ããã¯ããé¡äŒŒæ€çŽ¢ããã芧ãã ããã
Ultralytics Explorerã§LanceDBã䜿çšããã¡ãªããã¯äœã§ããïŒ
Ultralytics Explorerã§äœ¿çšãããŠããLanceDBã¯ãã¹ã±ãŒã©ãã«ã§ãã£ã¹ã¯äžã®åã蟌ã¿ããŒãã«ãæäŸããŸããããã«ãããCOCOã®ãããªå€§èŠæš¡ãªããŒã¿ã»ããã«å¯ŸããŠããã¡ã¢ãªäžè¶³ã«ãªãããšãªããšã³ãããã£ã³ã°ãäœæããåå©çšããããšãã§ããŸãããããã®ããŒãã«ã¯äžåºŠã ãäœæãããåå©çšããããšãã§ãããããããŒã¿åŠçã®å¹çãåäžããŸãã
Ultralytics Explorer APIã®Ask AIæ©èœã¯ã©ã®ããã«æ©èœããã®ã§ããïŒ
Ask AIæ©èœã«ããããŠãŒã¶ãŒã¯èªç¶èšèªã¯ãšãªã䜿ã£ãŠããŒã¿ã»ããããã£ã«ã¿ãªã³ã°ã§ããããã®æ©èœã¯ãLLMã掻çšãããããã®ã¯ãšãªãè£ã§SQLã¯ãšãªã«å€æããŸãã以äžã«äŸãæããïŒ
from ultralytics import Explorer
# Create an Explorer object
explorer = Explorer(data="coco128.yaml", model="yolo11n.pt")
explorer.create_embeddings_table()
# Query with natural language
query_result = explorer.ask_ai("show me 100 images with exactly one person and 2 dogs. There can be other objects too")
print(query_result.head())
ãã®ä»ã®äŸã«ã€ããŠã¯ããAIã«èããã®ã»ã¯ã·ã§ã³ãã芧ãã ããã