ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Pre-trained models for segmentation
    Autonomous Lawn Mower/Opencv 2025. 1. 13. 11:51
    반응형

    The ADE20K dataset is a widely used benchmark for semantic segmentation and scene parsing. It contains over 20,000 images annotated with pixel-level labels for 150 object categories

    잔디와 도로, 펜스 등을 인식하기 위해서 개인 목적으로 무료인 ADE20K라는 dataset을 사용한다. ADE20K를 이용하여 잔디와 그 외 지역을 구분하는데 그 목적이 있다. 

    1. Download the ADE20K Dataset

    • Go to the official GitHub repository.
    • Download the dataset:
      • Training images (ADEChallengeData2016 folder).
      • Validation images (ADEChallengeData2016/validation).
      • Annotation files (ADEChallengeData2016/annotations).

    다운로드 방법: RealVNC에서 파일 매니저를 열어 /home/pi 경로에서 00_Lawn_Mower 폴더에 마우스 오른쪽 클릭 후 Open in terminal을 클릭하여 터미널을 연다. 다음 명령어를 이용하여 파일을 00_Lawn_Mower 폴더 안에 복사해 온다. git clone https://github.com/CSAILVision/semantic-segmentation-pytorch

     

    ADE20K requirement: ADE20K를 이용하려면 아래의 것들이 인스톨되어 있어야 한다. 

    • numpy
      • RealVNC 라즈베리파이의 터미널에서 pip show numpy을 이용하여 확인 가능.
      • ver 1.24.2가 깔려 있음.
      • Numpy는 Numerical Python의 약자로, 수치 및 과학 컴퓨팅에 사용되는 강력한 오픈소스 Python 라이브러리다. 대규모 다차원 배열과 행렬에 대한 지원과 이러한 배열에서 효율적으로 작동하기 위한 수학 함수 모음을 제공힌다. 
    • scipy: 
      • pip show scipy를 이용하여 확인 가능
      • scipy는 안 깔려 있음
      • Tonny에서 python executable 폴더를 virtual 환경으로 설정 후 Tools/Open system shell에서 pip install scipy로 설치
      • ver 1.15.1 설치 완료
      • SciPy는 Scientific Python의 약자로 NumPy를 기반으로 구축된 오픈소스 Python 라이브러리로 과학 및 기술 컴퓨팅을 위한 추가 도구를 제공한다. 
        - 최적화: 선형 프로그래밍 문제 해결, 함수 최소화
        - 적분: 수치 적분 및 상미분 방정식 해결
        - 보간: 보간 함수 구성
        - 선형 대수: 고급 행렬 연산, 고유값 계산
        - 통계: 확률 분포, 통계적 검정 및 기술 통계
        - 신호 및 이미지 처리: 푸리에 변환, 필터링 및 이미지 분석
        - SciPy는 광범위한 기능으로 인해 데이터 과학, 머신 러닝 및 엔지니어링 작업에 널리 사용된다. 

    • pytorch==0.4.1
    • torchvision
      • pip install torch torchvision torchaudio로 설치 완료
      • torch: ver 2.5.1
      • torchvision: ver 0.20.1
      • torchaudio: ver 2.5.1
    • opencv3: AI 인공지능 자율주행 자동차에서 인스톨 됨
    • yacs
      • Yet Another Configuration System의 약자로서, 딥 러닝 및 기타 프로젝트에서 구성 파일을 관리하도록 설계된 가벼운 Python 라이브러리입니다. 계층적 구성을 Python 객체로 정의하여 구성 설정을 처리하는 구조화된 방법을 제공합니다. YACS는 컴퓨터 비전, 자연어 처리 또는 머신 러닝과 같이 실험에 여러 구성 변경이 필요한 프로젝트에서 특히 인기가 있습니다.
      • ver 0.1.8 설치 완료
    • tqdm
      • tqdm은 루프의 진행률 막대를 표시하는 데 사용되는 Python 라이브러리로, 완료하는 데 시간이 걸릴 수 있는 작업의 진행 상황을 더 쉽게 모니터링할 수 있습니다. 데이터 처리, 파일 다운로드 또는 머신 러닝 모델 학습과 같은 시나리오에서 널리 사용됩니다.
      • ver 4.64.1 설치 완료

    2. Explore the Dataset

    • The dataset contains:
      • Images: High-quality scenes from indoor and outdoor environments.
      • Annotations: Pixel-level masks for each object category (e.g., grass, building, sky).

    Files are structured as:

    ADEChallengeData2016/
    ├── images/
    │   ├── training/
    │   ├── validation/
    ├── annotations/
    │   ├── training/
    │   ├── validation/

     

    3. Use Pre-Trained Models (Optional)

    You can use pre-trained models trained on ADE20K for semantic segmentation tasks. Popular frameworks offering pre-trained models include:

    a. DeepLab (TensorFlow/PyTorch):

    from torchvision.models.segmentation import deeplabv3_resnet101
    model = deeplabv3_resnet101(pretrained=True)
    model.eval()

    b. MMSegmentation (OpenMMLab):

    Install MMSegmentation:

     

     
    pip install mmcv-full mmsegmentation
     

    4. Train a Model on ADE20K

    If you want to train your own model:

    a. Preprocessing

    • Resize images to a uniform size (e.g., 512x512 or 256x256).
    • Split the dataset into training, validation, and test sets.

    b. Model Training

    1. Choose a segmentation model (e.g., U-Net, DeepLab, PSPNet).
    2. Use a deep learning framework like TensorFlow, PyTorch, or OpenMMLab.

    Example with PyTorch:

    import torch
    from torchvision import transforms
    from torchvision.models.segmentation import fcn_resnet50

    # Load the ADE20K dataset and a pre-trained model
    model = fcn_resnet50(pretrained=True)
     

    c. Evaluation

    • Evaluate your model on ADE20K validation images using metrics like mIoU (mean Intersection over Union)

    5. Fine-Tune for Custom Tasks

    If ADE20K categories (e.g., "grass") fit your needs, fine-tune the pre-trained model on your data:

    1. Modify the dataset annotations or add new classes.
    2. Fine-tune using transfer learning.

    6. Visualizing Results

    Tools like Matplotlib or OpenCV can visualize segmented results overlaid on images. Example:

    import cv2
    import matplotlib.pyplot as plt

    # Read an image
    image = cv2.imread('path/to/image.jpg')
    segmentation_map = model(image)

    # Overlay segmentation map
    plt.imshow(image)
    plt.imshow(segmentation_map, alpha=0.5)
    plt.show()

    반응형

    'Autonomous Lawn Mower > Opencv' 카테고리의 다른 글

    라즈베리파이 학습 방법  (1) 2025.01.17
    비디오 파일 재생  (1) 2024.12.24
    카메라 영상 출력 Camera display  (0) 2024.12.15
    Imwrite  (1) 2024.11.26
    Imread  (0) 2024.11.26
Designed by Tistory.