์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

Ultralytics ํƒ์ƒ‰๊ธฐ API

์†Œ๊ฐœ

๊ณต๋™ ์ž‘์—…์‹ค์—์„œ ์—ด๊ธฐ ํƒ์ƒ‰๊ธฐ API๋Š” ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ํƒ์ƒ‰ํ•˜๊ธฐ ์œ„ํ•œ Python API์ž…๋‹ˆ๋‹ค. SQL ์ฟผ๋ฆฌ, ๋ฒกํ„ฐ ์œ ์‚ฌ๋„ ๊ฒ€์ƒ‰, ์‹œ๋งจํ‹ฑ ๊ฒ€์ƒ‰์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์ง‘ํ•ฉ์„ ํ•„ํ„ฐ๋งํ•˜๊ณ  ๊ฒ€์ƒ‰ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.



Watch: Ultralytics ํƒ์ƒ‰๊ธฐ API ๊ฐœ์š”

์„ค์น˜

Explorer๋Š” ์ผ๋ถ€ ๊ธฐ๋Šฅ์„ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ์˜์กดํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์‚ฌ์šฉ ์‹œ ์ž๋™์œผ๋กœ ์„ค์น˜๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ข…์†์„ฑ์„ ์ˆ˜๋™์œผ๋กœ ์„ค์น˜ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

pip install ultralytics[explorer]

์‚ฌ์šฉ๋ฒ•

from ultralytics import Explorer

# Create an Explorer object
explorer = Explorer(data='coco128.yaml', model='yolov8n.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์™€ ๊ฐ™์€ ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ์„ธํŠธ์— ๋Œ€ํ•œ ์ž„๋ฒ ๋”ฉ์„ ์ƒ์„ฑํ•˜๊ณ  ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์„ ๊ฐ•์ œ๋กœ ์—…๋ฐ์ดํŠธํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ „๋‹ฌํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. force=True ์— create_embeddings_table ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. LanceDB ํ…Œ์ด๋ธ” ๊ฐœ์ฒด์— ์ง์ ‘ ์•ก์„ธ์Šคํ•˜์—ฌ ๊ณ ๊ธ‰ ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํ‘œ ์„น์…˜์œผ๋กœ ์ž‘์—…ํ•˜๊ธฐ

์œ ์‚ฌ๋„ ๊ฒ€์ƒ‰์€ ์ฃผ์–ด์ง„ ์ด๋ฏธ์ง€์™€ ์œ ์‚ฌํ•œ ์ด๋ฏธ์ง€๋ฅผ ์ฐพ๋Š” ๊ธฐ์ˆ ์ž…๋‹ˆ๋‹ค. ๋น„์Šทํ•œ ์ด๋ฏธ์ง€์—๋Š” ๋น„์Šทํ•œ ์ž„๋ฒ ๋”ฉ์ด ์žˆ์„ ๊ฒƒ์ด๋ผ๋Š” ์ƒ๊ฐ์— ๊ธฐ๋ฐ˜ํ•ฉ๋‹ˆ๋‹ค. ์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์ด ๊ตฌ์ถ•๋˜๋ฉด ๋‹ค์Œ ์ค‘ ํ•œ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ์‹œ๋งจํ‹ฑ ๊ฒ€์ƒ‰์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

  • ๋ฐ์ดํ„ฐ ์„ธํŠธ์˜ ์ง€์ •๋œ ์ธ๋ฑ์Šค ๋˜๋Š” ์ธ๋ฑ์Šค ๋ชฉ๋ก์—์„œ: exp.get_similar(idx=[1,10], limit=10)
  • ๋ฐ์ดํ„ฐ ์„ธํŠธ์— ์—†๋Š” ์ด๋ฏธ์ง€ ๋˜๋Š” ์ด๋ฏธ์ง€ ๋ชฉ๋ก์—์„œ: exp.get_similar(img=["path/to/img1", "path/to/img2"], limit=10)

์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ž…๋ ฅ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ํ•ด๋‹น ์ž„๋ฒ ๋”ฉ์˜ ์ดํ•ฉ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

ํŒ๋‹ค ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์ด ํฌํ•จ๋œ limit ์ž…๋ ฅ๊ณผ ๊ฐ€์žฅ ์œ ์‚ฌํ•œ ๋ฐ์ดํ„ฐ ํฌ์ธํŠธ์˜ ์ˆ˜์™€ ์ž„๋ฒ ๋”ฉ ๊ณต๊ฐ„์—์„œ์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ์ด ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถ”๊ฐ€ ํ•„ํ„ฐ๋ง์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‹œ๋งจํ‹ฑ ๊ฒ€์ƒ‰

from ultralytics import Explorer

# create an Explorer object
exp = Explorer(data='coco128.yaml', model='yolov8n.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='yolov8n.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 ๋ฅผ ํด๋ฆญํ•˜๊ณ  ์œ ์‚ฌํ•œ ์ด๋ฏธ์ง€๋ฅผ ๊ทธ๋ฆฌ๋“œ์— ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

์œ ์‚ฌํ•œ ์ด๋ฏธ์ง€ ํ”Œ๋กœํŒ…

from ultralytics import Explorer

# create an Explorer object
exp = Explorer(data='coco128.yaml', model='yolov8n.pt')
exp.create_embeddings_table()

plt = exp.plot_similar(img='https://ultralytics.com/images/bus.jpg', limit=10)
plt.show()
from ultralytics import Explorer

# create an Explorer object
exp = Explorer(data='coco128.yaml', model='yolov8n.pt')
exp.create_embeddings_table()

plt = exp.plot_similar(idx=1, limit=10)
plt.show()

2. AI์—๊ฒŒ ์งˆ๋ฌธ(์ž์—ฐ์–ด ์ฟผ๋ฆฌ)

์ด๋ฅผ ํ†ตํ•ด ์ž์—ฐ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์ง‘ํ•ฉ์„ ํ•„ํ„ฐ๋งํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. SQL ์ฟผ๋ฆฌ ์ž‘์„ฑ์— ๋Šฅ์ˆ™ํ•  ํ•„์š”๋Š” ์—†์Šต๋‹ˆ๋‹ค. AI ๊ธฐ๋ฐ˜ ์ฟผ๋ฆฌ ์ƒ์„ฑ๊ธฐ๊ฐ€ ๋‚ด๋ถ€์—์„œ ์ž๋™์œผ๋กœ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, "์‚ฌ๋žŒ๊ณผ ๊ฐœ๊ฐ€ ์ •ํ™•ํžˆ ํ•œ ๋งˆ๋ฆฌ์”ฉ ์žˆ๋Š” ์ด๋ฏธ์ง€ 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='yolov8n.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 ์ฟผ๋ฆฌ

from ultralytics import Explorer

# create an Explorer object
exp = Explorer(data='coco128.yaml', model='yolov8n.pt')
exp.create_embeddings_table()

df = exp.sql_query("WHERE labels LIKE '%person%' AND labels LIKE '%dog%'")
print(df.head())

SQL ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ ํ”Œ๋กœํŒ…

๋˜ํ•œ ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ SQL ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ํ”Œ๋กœํŒ…ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. plot_sql_query ๋ฉ”์„œ๋“œ. ์ด ๋ฉ”์„œ๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ธ์ˆ˜๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค. sql_query ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ๋ฅผ ๊ทธ๋ฆฌ๋“œ์— ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

SQL ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ ํ”Œ๋กœํŒ…

from ultralytics import Explorer

# create an Explorer object
exp = Explorer(data='coco128.yaml', model='yolov8n.pt')
exp.create_embeddings_table()

# plot the SQL Query
exp.plot_sql_query("WHERE labels LIKE '%person%' AND labels LIKE '%dog%' LIMIT 10")

4. ๊ณ ๊ธ‰ - ์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ” ์ž‘์—…

์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”๋กœ ์ง์ ‘ ์ž‘์—…ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์ด ์ƒ์„ฑ๋˜๋ฉด ์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Explorer.table

ํƒ์ƒ‰๊ธฐ๋Š” ๋‹ค์Œ์—์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. LanceDB ํ…Œ์ด๋ธ”์„ ๋‚ด๋ถ€์ ์œผ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด ํ…Œ์ด๋ธ”์— ์ง์ ‘ ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Explorer.table ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ , ์›์‹œ ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜๊ณ , ์‚ฌ์ „ ๋ฐ ์‚ฌํ›„ ํ•„ํ„ฐ๋ฅผ ํ‘ธ์‹œ ๋‹ค์šดํ•˜๋Š” ๋“ฑ์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

from ultralytics import Explorer

exp = Explorer()
exp.create_embeddings_table()
table = exp.table

๋‹ค์Œ์€ ํ…Œ์ด๋ธ”๋กœ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ž‘์—…์˜ ๋ช‡ ๊ฐ€์ง€ ์˜ˆ์ž…๋‹ˆ๋‹ค:

์›์‹œ ์ž„๋ฒ ๋”ฉ ๊ฐ€์ ธ์˜ค๊ธฐ

์˜ˆ์ œ

from ultralytics import Explorer

exp = Explorer()
exp.create_embeddings_table()
table = exp.table

embeddings = table.to_pandas()["vector"]
print(embeddings)

์‚ฌ์ „ ๋ฐ ์‚ฌํ›„ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•œ ๊ณ ๊ธ‰ ์ฟผ๋ฆฌ ๊ธฐ๋Šฅ

์˜ˆ์ œ

from ultralytics import Explorer

exp = Explorer(model="yolov8n.pt")
exp.create_embeddings_table()
table = exp.table

# Dummy embedding
embedding = [i for i in range(256)]
rs = table.search(embedding).metric("cosine").where("").limit(10)

๋ฒกํ„ฐ ์ธ๋ฑ์Šค ์ƒ์„ฑ

๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, ๋” ๋น ๋ฅธ ์ฟผ๋ฆฌ๋ฅผ ์œ„ํ•ด ์ „์šฉ ๋ฒกํ„ฐ ์ธ๋ฑ์Šค๋ฅผ ๋งŒ๋“ค ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ž‘์—…์€ create_index ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

table.create_index(num_partitions=..., num_sub_vectors=...)

์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฒกํ„ฐ ์ธ๋ฑ์Šค ์œ ํ˜• ๋ฐ ๋งค๊ฐœ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์—ฌ๊ธฐ์—์„œ ํ™•์ธํ•˜์„ธ์š”. ํ–ฅํ›„์—๋Š” ์ต์Šคํ”Œ๋กœ๋Ÿฌ API์—์„œ ์ง์ ‘ ๋ฒกํ„ฐ ์ธ๋ฑ์Šค๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

5. ์ž„๋ฒ ๋”ฉ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์–‘ํ•œ ํƒ์ƒ‰ ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ๋ช‡ ๊ฐ€์ง€ ์˜ˆ์ž…๋‹ˆ๋‹ค:

์œ ์‚ฌ์„ฑ ์ง€์ˆ˜

Explorer๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. similarity_index ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค:

  • ๊ฐ ๋ฐ์ดํ„ฐ ํฌ์ธํŠธ๊ฐ€ ๋‚˜๋จธ์ง€ ๋ฐ์ดํ„ฐ ์„ธํŠธ์™€ ์–ผ๋งˆ๋‚˜ ์œ ์‚ฌํ•œ์ง€ ์ถ”์ •ํ•ฉ๋‹ˆ๋‹ค.
  • ์–ผ๋งˆ๋‚˜ ๋งŽ์€ ์ด๋ฏธ์ง€ ์ž„๋ฒ ๋”ฉ์ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐ€๊นŒ์šด ๊ณณ์— ์žˆ๋Š”์ง€ ์„ธ๋Š” ๋ฐฉ์‹์œผ๋กœ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค. max_dist ๋ฅผ ์ƒ์„ฑ๋œ ์ž„๋ฒ ๋”ฉ ๊ณต๊ฐ„์˜ ํ˜„์žฌ ์ด๋ฏธ์ง€๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค. top_k ๋น„์Šทํ•œ ์ด๋ฏธ์ง€๋ฅผ ํ•œ ๋ฒˆ์— ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ํ•จ์ˆ˜๋Š” ๋‹ค์Œ ์—ด์ด ํฌํ•จ๋œ ํŒฌ๋” ๋ฐ์ดํ„ฐ ํ”„๋ ˆ์ž„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค:

  • idx: ๋ฐ์ดํ„ฐ ์„ธํŠธ์— ์žˆ๋Š” ์ด๋ฏธ์ง€์˜ ์ธ๋ฑ์Šค
  • im_file: ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ
  • count: ๋ฐ์ดํ„ฐ ์„ธํŠธ์—์„œ ๋‹ค์Œ๋ณด๋‹ค ๋” ๊ฐ€๊นŒ์šด ์ด๋ฏธ์ง€ ์ˆ˜ max_dist ๋ฅผ ํ˜„์žฌ ์ด๋ฏธ์ง€๋กœ
  • sim_im_files: ๊ฒฝ๋กœ ๋ชฉ๋ก count ์œ ์‚ฌํ•œ ์ด๋ฏธ์ง€

ํŒ

์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ ์ง‘ํ•ฉ์— ๋Œ€ํ•ด ๋ชจ๋ธ๋งํ•ฉ๋‹ˆ๋‹ค, max_dist & top_k ๋กœ ์„ค์ •ํ•˜๋ฉด ํ•œ ๋ฒˆ ์ƒ์„ฑ๋œ ์œ ์‚ฌ๋„ ์ธ๋ฑ์Šค๊ฐ€ ์žฌ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ ์„ธํŠธ๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ๊ฑฐ๋‚˜ ๋‹จ์ˆœํžˆ ์œ ์‚ฌ๋„ ์ธ๋ฑ์Šค๋ฅผ ๋‹ค์‹œ ์ƒ์„ฑํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. force=True.

์œ ์‚ฌ์„ฑ ์ง€์ˆ˜

from ultralytics import Explorer

exp = Explorer()
exp.create_embeddings_table()

sim_idx = exp.similarity_index()

์œ ์‚ฌ๋„ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ •์˜ ์กฐ๊ฑด์„ ์ž‘์„ฑํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์ง‘ํ•ฉ์„ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์„ธํŠธ์˜ ๋‹ค๋ฅธ ์ด๋ฏธ์ง€์™€ ์œ ์‚ฌํ•˜์ง€ ์•Š์€ ์ด๋ฏธ์ง€๋ฅผ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

import numpy as np

sim_count = np.array(sim_idx["count"])
sim_idx['im_file'][sim_count > 30]

์ž„๋ฒ ๋”ฉ ๊ณต๊ฐ„ ์‹œ๊ฐํ™”

์›ํ•˜๋Š” ํ”Œ๋กœํŒ… ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž„๋ฒ ๋”ฉ ๊ณต๊ฐ„์„ ์‹œ๊ฐํ™”ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ์€ matplotlib๋ฅผ ์‚ฌ์šฉํ•œ ๊ฐ„๋‹จํ•œ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค:

import numpy as np
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 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๋ฅผ ์‚ฌ์šฉํ•ด ๋‚˜๋งŒ์˜ ์ด๋ ฅ์„œ ๋ฐ์ดํ„ฐ ์„ธํŠธ ํƒ์ƒ‰ ๋ณด๊ณ ์„œ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์„ธ์š”. ์˜๊ฐ์„ ์–ป์œผ๋ ค๋ฉด

Ultralytics ํƒ์ƒ‰๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ์ถ•ํ•œ ์•ฑ

์ต์Šคํ”Œ๋กœ๋Ÿฌ API ๊ธฐ๋ฐ˜ GUI ๋ฐ๋ชจ ์ฒดํ—˜ํ•˜๊ธฐ

์ถœ์‹œ ์˜ˆ์ •

  • [ ] ๋ฐ์ดํ„ฐ ์ง‘ํ•ฉ์—์„œ ํŠน์ • ๋ ˆ์ด๋ธ”์„ ๋ณ‘ํ•ฉํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ - ๋ชจ๋‘ ๊ฐ€์ ธ์˜ค๊ธฐ person ๋ผ๋ฒจ๊ณผ car ๋„์‹œ ํ’๊ฒฝ์˜ ๋ ˆ์ด๋ธ”
  • [ ] ์ง€์ •๋œ ์ž„๊ณ„๊ฐ’๋ณด๋‹ค ์œ ์‚ฌ๋„ ์ง€์ˆ˜๊ฐ€ ๋†’์€ ์ด๋ฏธ์ง€๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
  • [ ] ํ•ญ๋ชฉ ๋ณ‘ํ•ฉ/์ œ๊ฑฐ ํ›„ ์ƒˆ ๋ฐ์ดํ„ฐ์„ธํŠธ ์ž๋™ ์œ ์ง€
  • [ ] ๊ณ ๊ธ‰ ๋ฐ์ดํ„ฐ ์ง‘ํ•ฉ ์‹œ๊ฐํ™”


์ƒ์„ฑ 2024-01-07, ์—…๋ฐ์ดํŠธ 2024-02-11
์ž‘์„ฑ์ž: 0xSynapse (1), glenn-jocher (6), chr043416@gmail.com (2), AyushExel (2)

๋Œ“๊ธ€