Meet YOLO26: next-gen vision AI.

Link to this sectionUltralytics 문서: YOLO26과 SAHI를 사용한 슬라이스 추론#

Open SAHI for Sliced Inference In Colab

YOLO26과 SAHI(Slicing Aided Hyper Inference)를 사용하는 방법에 대한 Ultralytics 문서에 오신 것을 환영합니다. 이 포괄적인 가이드는 YOLO26과 함께 SAHI를 구현하는 데 필요한 모든 필수 지식을 제공하는 것을 목표로 합니다. SAHI가 무엇인지, 왜 대규모 애플리케이션에서 슬라이스 추론이 중요한지, 그리고 향상된 객체 탐지 성능을 위해 이러한 기능을 YOLO26과 통합하는 방법을 자세히 알아봅니다.

SAHI tiled inference for small objects

Link to this sectionSAHI 소개#

SAHI(Slicing Aided Hyper Inference)는 대규모 및 고해상도 이미지에 대해 객체 탐지 알고리즘을 최적화하도록 설계된 혁신적인 라이브러리입니다. 핵심 기능은 이미지를 관리하기 쉬운 슬라이스로 분할하고, 각 슬라이스에서 객체 탐지를 실행한 다음, 결과를 다시 하나로 합치는 것입니다. SAHI는 YOLO 시리즈를 포함한 다양한 객체 탐지 모델과 호환되므로 계산 자원의 최적화된 사용을 보장하면서 유연성을 제공합니다.



Watch: How to use SAHI with Ultralytics YOLO26 to Detect Small Objects | Slicing Aided Hyper Inference 🚀

Link to this sectionSAHI의 주요 특징#

  • 원활한 통합: SAHI는 YOLO 모델과 쉽게 통합되므로, 코드 수정 없이도 바로 슬라이싱과 탐지를 시작할 수 있습니다.
  • 자원 효율성: 대형 이미지를 더 작은 부분으로 나눔으로써 SAHI는 메모리 사용량을 최적화하여 자원이 제한된 하드웨어에서도 고품질 탐지를 실행할 수 있게 합니다.
  • 높은 정확도: SAHI는 스티칭 과정에서 겹치는 탐지 상자를 병합하는 스마트 알고리즘을 사용하여 탐지 정확도를 유지합니다.

Link to this section슬라이스 추론이란?#

슬라이스 추론은 대형 또는 고해상도 이미지를 더 작은 세그먼트(슬라이스)로 세분화하고, 이 슬라이스들에 대해 객체 탐지를 수행한 다음, 슬라이스를 재결합하여 원본 이미지상의 객체 위치를 재구성하는 방식을 말합니다. 이 기술은 계산 자원이 제한된 상황이나 메모리 문제를 일으킬 수 있는 초고해상도 이미지를 다룰 때 매우 유용합니다.

Link to this section슬라이스 추론의 이점#

  • 계산 부담 감소: 더 작은 이미지 슬라이스는 처리 속도가 빠르고 메모리 소비가 적어 저사양 하드웨어에서도 원활하게 작동합니다.

  • 탐지 품질 유지: 각 슬라이스는 독립적으로 처리되므로 관심 객체를 포착할 만큼 슬라이스가 충분히 크다면 객체 탐지의 품질 저하는 발생하지 않습니다.

  • 향상된 확장성: 이 기술을 통해 객체 탐지 작업을 다양한 크기와 해상도의 이미지에 걸쳐 더 쉽게 확장할 수 있으므로, 위성 이미지 분석부터 의료 진단에 이르기까지 폭넓은 애플리케이션에 적합합니다.

YOLO26 without SAHIYOLO26 with SAHI
YOLO26 without SAHIYOLO26 with SAHI

Link to this section설치 및 준비#

Link to this section설치#

시작하려면 최신 버전의 SAHI와 Ultralytics를 설치하십시오:

pip install -U ultralytics sahi

Link to this section모듈 가져오기 및 리소스 다운로드#

테스트 이미지를 다운로드하는 방법은 다음과 같습니다:

from sahi.utils.file import download_from_url

# Download test images
download_from_url(
    "https://raw.githubusercontent.com/obss/sahi/main/demo/demo_data/small-vehicles1.jpeg",
    "demo_data/small-vehicles1.jpeg",
)
download_from_url(
    "https://raw.githubusercontent.com/obss/sahi/main/demo/demo_data/terrain2.png",
    "demo_data/terrain2.png",
)

Link to this sectionYOLO26을 사용한 표준 추론#

Link to this section모델 인스턴스화#

다음과 같이 객체 탐지를 위해 YOLO26 모델을 인스턴스화할 수 있습니다:

from sahi import AutoDetectionModel

detection_model = AutoDetectionModel.from_pretrained(
    model_type="ultralytics",
    model_path="yolo26n.pt",
    confidence_threshold=0.3,
    device="cpu",  # or 'cuda:0'
)

Link to this section표준 예측 수행#

이미지 경로를 사용하여 표준 추론을 수행합니다.

from sahi.predict import get_prediction

result = get_prediction("demo_data/small-vehicles1.jpeg", detection_model)

result.export_visuals(export_dir="demo_data/", hide_conf=True)

Link to this section결과 시각화#

예측된 경계 상자와 마스크를 내보내고 시각화하십시오:

from PIL import Image

# Open the predicted image
processed_image = Image.open("demo_data/prediction_visual.png")

# Display the predicted image
processed_image.show()

Link to this sectionYOLO26을 사용한 슬라이스 추론#

슬라이스 크기와 겹침 비율을 지정하여 슬라이스 추론을 수행합니다:

from PIL import Image
from sahi.predict import get_sliced_prediction

result = get_sliced_prediction(
    "demo_data/small-vehicles1.jpeg",
    detection_model,
    slice_height=256,
    slice_width=256,
    overlap_height_ratio=0.2,
    overlap_width_ratio=0.2,
)

# Export results
result.export_visuals(export_dir="demo_data/", hide_conf=True)

# Open the predicted image
processed_image = Image.open("demo_data/prediction_visual.png")

# Display the predicted image
processed_image.show()

Link to this section예측 결과 처리#

SAHI는 다양한 주석 형식으로 변환할 수 있는 PredictionResult 객체를 제공합니다:

# Access the object prediction list
object_prediction_list = result.object_prediction_list

# Convert to COCO annotation and COCO prediction formats
result.to_coco_annotations()[:3]
result.to_coco_predictions(image_id=1)[:3]
추가 내보내기 형식

PredictionResult can also convert detections to imantics and FiftyOne objects with result.to_imantics_annotations() and result.to_fiftyone_detections(). These methods require the respective packages, so install them first with pip install imantics fiftyone.

Link to this section배치 예측#

이미지 디렉토리에 대한 배치 예측을 수행하려면:

from sahi.predict import predict

predict(
    model_type="ultralytics",
    model_path="yolo26n.pt",
    model_device="cpu",  # or 'cuda:0'
    model_confidence_threshold=0.4,
    source="path/to/dir",
    slice_height=256,
    slice_width=256,
    overlap_height_ratio=0.2,
    overlap_width_ratio=0.2,
)

이제 YOLO26과 SAHI를 사용하여 표준 추론 및 슬라이스 추론을 수행할 준비가 되었습니다.

Link to this section인용 및 감사의 글#

연구 또는 개발 작업에 SAHI를 사용하는 경우, 원본 SAHI 논문을 인용하고 저자에게 공로를 인정해 주시기 바랍니다:

인용
@article{akyon2022sahi,
  title={Slicing Aided Hyper Inference and Fine-tuning for Small Object Detection},
  author={Akyon, Fatih Cagatay and Altinuc, Sinan Onur and Temizel, Alptekin},
  journal={2022 IEEE International Conference on Image Processing (ICIP)},
  doi={10.1109/ICIP46576.2022.9897990},
  pages={966-970},
  year={2022}
}

컴퓨터 비전 커뮤니티를 위한 이 귀중한 자원을 만들고 유지 관리해 주신 SAHI 연구 그룹에 감사드립니다. SAHI와 그 제작자에 대한 자세한 내용은 SAHI GitHub 저장소를 방문하십시오.

Link to this sectionFAQ#

Link to this section객체 탐지에서 슬라이스 추론을 위해 YOLO26을 SAHI와 어떻게 통합할 수 있나요?#

Ultralytics YOLO26을 SAHI(Slicing Aided Hyper Inference)와 통합하여 슬라이스 추론을 수행하면 고해상도 이미지를 관리하기 쉬운 슬라이스로 분할하여 객체 탐지 작업을 최적화할 수 있습니다. 이 접근 방식은 메모리 사용량을 개선하고 높은 탐지 정확도를 보장합니다. 시작하려면 ultralytics 및 sahi 라이브러리를 설치해야 합니다:

pip install -U ultralytics sahi

그런 다음 테스트 이미지를 다운로드합니다:

from sahi.utils.file import download_from_url

# Download test images
download_from_url(
    "https://raw.githubusercontent.com/obss/sahi/main/demo/demo_data/small-vehicles1.jpeg",
    "demo_data/small-vehicles1.jpeg",
)
download_from_url(
    "https://raw.githubusercontent.com/obss/sahi/main/demo/demo_data/terrain2.png",
    "demo_data/terrain2.png",
)

더 자세한 지침은 슬라이스 추론 가이드를 참조하십시오.

Link to this section대형 이미지에 대한 객체 탐지 시 왜 SAHI와 YOLO26을 함께 사용해야 하나요?#

대형 이미지 객체 탐지에 Ultralytics YOLO26과 SAHI를 함께 사용하면 다음과 같은 이점이 있습니다:

  • 계산 부담 감소: 더 작은 슬라이스는 처리 속도가 빠르고 메모리 사용량이 적어 자원이 제한된 하드웨어에서도 고품질 탐지를 실행할 수 있습니다.
  • 탐지 정확도 유지: SAHI는 지능형 알고리즘을 사용하여 겹치는 상자를 병합함으로써 탐지 품질을 보존합니다.
  • 향상된 확장성: 다양한 이미지 크기와 해상도에 걸쳐 객체 탐지 작업을 확장할 수 있으므로 SAHI는 위성 이미지 분석 및 의료 진단과 같은 다양한 애플리케이션에 이상적입니다.

문서에서 슬라이스 추론의 이점에 대해 자세히 알아보십시오.

Link to this sectionYOLO26과 SAHI를 사용할 때 예측 결과를 시각화할 수 있나요?#

네, YOLO26과 SAHI를 사용할 때 예측 결과를 시각화할 수 있습니다. 결과 내보내기 및 시각화 방법은 다음과 같습니다:

from PIL import Image

result.export_visuals(export_dir="demo_data/", hide_conf=True)

processed_image = Image.open("demo_data/prediction_visual.png")

processed_image.show()

이 명령은 시각화된 예측을 지정된 디렉토리에 저장하며, 노트북이나 애플리케이션에서 이미지를 불러와 확인할 수 있습니다. 자세한 가이드는 표준 추론 섹션을 확인하십시오.

Link to this sectionSAHI는 YOLO26 객체 탐지를 개선하기 위해 어떤 기능을 제공하나요?#

SAHI(Slicing Aided Hyper Inference)는 객체 탐지를 위해 Ultralytics YOLO26을 보완하는 몇 가지 기능을 제공합니다:

  • 원활한 통합: SAHI는 최소한의 코드 수정만으로 YOLO 모델과 쉽게 통합됩니다.
  • 자원 효율성: 대형 이미지를 더 작은 슬라이스로 분할하여 메모리 사용량과 속도를 최적화합니다.
  • 높은 정확도: 스티칭 과정에서 겹치는 탐지 상자를 효과적으로 병합함으로써 SAHI는 높은 탐지 정확도를 유지합니다.

더 깊은 이해를 위해 SAHI의 주요 특징에 대해 읽어보십시오.

Link to this sectionYOLO26과 SAHI를 사용하여 대규모 추론 프로젝트를 처리하려면 어떻게 해야 하나요?#

YOLO26과 SAHI를 사용하는 대규모 추론 프로젝트를 처리하려면 다음 모범 사례를 따르십시오:

  1. 필수 라이브러리 설치: 최신 버전의 ultralytics와 sahi가 설치되어 있는지 확인하십시오.
  2. 슬라이스 추론 구성: 특정 프로젝트에 적합한 최적의 슬라이스 크기와 겹침 비율을 결정하십시오.
  3. 배치 예측 실행: SAHI의 기능을 활용하여 이미지 디렉토리에 대한 배치 예측을 수행하면 효율성이 향상됩니다.

배치 예측 예시:

from sahi.predict import predict

predict(
    model_type="ultralytics",
    model_path="path/to/yolo26n.pt",
    model_device="cpu",  # or 'cuda:0'
    model_confidence_threshold=0.4,
    source="path/to/dir",
    slice_height=256,
    slice_width=256,
    overlap_height_ratio=0.2,
    overlap_width_ratio=0.2,
)

더 자세한 단계는 배치 예측 섹션을 방문하십시오.

댓글