[AWS] AWS Direct Connect 알아보기

AWS의 네트워크 서비스로는 대표적으로 Amazon VPC(Virtual Private Cloud)가 있습니다.
VPC의 기능을 통해서 내부 네트워크를 할당하거나 외부 네트워크를 사용할 수 있도록 설정할 수 있는데요.

 

AWS Direct Connect은 AWS의 클라우드 서비스에 직접적으로 연결할 수 있는 네트워킹 서비스로,
공용 인터넷을 우회하고 전용 연결을 통해 더 안정적이고 안전한 네트워크 연결을 구성할 수 있습니다.

 

 


주요 기능

AWS Direct Connect를 사용하면 전용 케이블을 통해 내부 네트워크를 AWS Direct Connect와 연결 할 수 있습니다.

주요 기능은 아래와 같습니다.

 

  1. 전용 연결
    • 내부 네트워크 망이나 AWS 리전 간의 전용 연결읕 설정할 수 있습니다.
    • 전용 연결을 통해 안정적이고 저지연의 연결을 제공하며, 데이터 속도와 신뢰성을 향상시킵니다
  2. 가상 인터페이스
    • 가상 인터페이스를 통해 AWS 내의 VPC 또는 기타 AWS 서비스와 연결할 수 있습니다.
  3. 보안
    • 공용 인터넷 대역폭을 우회하여 데이터 전송을 보안하며 전용 연결을 통해 고객의 데이터는 인터넷을 거치지 않고 직접 AWS에 도달하므로 더 높은 보안 수준을 제공합니다.
  4. 대역폭 제어
    • 1Gbps, 10Gbps, 100Gbps 등 다양한 속도의 연결을 선택하여 필요한 만큼의 대역폭을 확장하거나 축소하여 비용을 효율적으로 관리할 수 있습니다.

 

 


다이어그램

AWS Direct Connect를 사용하여 네트워크에 대한 종합적인 개요를 보여주는 다이어그램입니다.


온프레미스의 고객 네트워크와 AWS Cloud와의 네트워크 통신을 AWS Direct Connect의 전용 연결을 통해 네트워크 통신을 할 수 있습니다. AWS Direct Connect의 라우터와 고객 라우터는 BGP 라우팅을 통해서 설정을 관리하고 라우팅 정보를 교환합니다.


Private Subnet과의 연결을 위해 Virtual Private Gateway를 설정하고 가상 인터페이스를 통해 Direct Connect와 연결합니다. 이제 보안 그룹 및 네트워크 ACL 규칙 등을 설정하면 온프레미스의 고객 네트워크와 AWS Cloud와의 네트워크 통신을 할 수 있습니다.

 

 


각 요소들

가상 인터페이스(Virtual Interface, VIF)

  • 가상 인터페이스는 AWS Direct Connect 연결을 통해 생성되는 논리적인 연결로 VPC 및 기타 AWS 서비스와 연결할 수 있는 방법을 제공합니다.
  • VLAN(Virtual LAN)을 사용하여 네트워크 트래픽을 분리하고, BGP를 사용하여 라우팅을 구성합니다.

 

전용 연결(dedicated connections)

  • AWS Direct Connect의 연결 유형 중 하나로, 고객이 AWS Direct Connect 위치에 직접 연결하여 대량의 트래픽을 처리하는 데 사용되는 유형입니다
  • 전용 연결을 설정하기 위해 고객은 AWS Direct Connect 위치에서 고객 장비를 설치하거나, AWS Direct Connect 서비스 파트너를 통해 연결을 요청해야 합니다.
  • 대량의 트래픽을 처리하거나 고객의 네트워크에 안정적이고 고성능의 연결을 제공하는데 적합한 방법입니다.

 

호스팅 연결(hosted connections)

  • AWS Direct Connect의 연결 유형 중 하나로, AWS Direct Connect 위치와 인터넷 서비스 공급자(ISP)의 피어링 지점에 연결하여 작은 양의 트래픽이나 테스트 및 개발 용도로 사용되는 유형입니다.
  • 호스팅 연결을 설정하기 위해 고객은 AWS Direct Connect 위치와 ISP 피어링 지점에 대한 연결 요청을 수행해야 합니다.
  • 작은 규모의 트래픽이나 테스트, 개발 용도에 적합한 방법입니다.

 

SiteLink

  • AWS Direct Connect의 연결 유형 중 하나로, 동일한 AWS Direct Connect 위치의 여러 장치나 데이터 센터 간에 전용 연결을 설정하는 기능을 제공합니다.
  • 여러 지역 또는 데이터 센터 간에 AWS Direct Connect 연결을 구성하여 AWS의 다중 지역 아키텍처를 구축하거나, 여러 데이터 센터에서 AWS 리소스에 안전하고 고성능의 연결을 확보할 수 있습니다.

 

Virtual Private Gateway

  • Virtual Private Gateway는 AWS 클라우드 내에서 VPC와 인터넷 간의 연결을 제공하는 가상 장치입니다.
  • AWS Direct Connect와 함께 사용하여 VPC를 온프레미스 환경 또는 다른 외부 네트워크와 연결할 수 있습니다.
  • Site-to-Site VPN 연결과 BGP 라우팅을 통해 네트워크 연결을 구성하고 제어할 수 있습니다.

 

 


요금

AWS Direct Connect의 요금은 포트 연결 시간 및 송수신 데이터에 따라 결정됩니다.

 

포트 시간: 전용 연결

전용 연결은 AWS Direct Connect 위치 내 AWS 네트워크 포트 및 사용자의 네트워크 포트 간 물리적 연결입니다.
전용 포트 시간은 사용하기 위해 포트를 프로비저닝한 만큼 요금이 청구됩니다.

 

트 시간 : 호스팅 연결

호스팅 연결은 AWS Direct Connect 제공 파트너가 사용자를 대신하여 프로비저닝하는 논리적 연결입니다.
호스팅 연결을 사용하는 경우 파트너 포트 중 하나를 사용하여 AWS 네트워크에 연결합니다.

 

데이터 송신(DTO)

DTO 요금은 소스 AWS 리전 또는 로컬 영역 및 AWS Direct Connect 위치에 따라 다르며, GB당 USD 요금이 부과됩니다.

 

SiteLink 데이터 전송

SiteLink는 AWS Direct Connect 서비스에서 제공되는 네트워크 연결 유형 중 하나로,
여러 지리적 위치나 데이터 센터 간에 안전하고 신뢰성 있는 전용 연결을 설정하는 기능을 제공합니다

 

 


활용

  1. Hybrid Cloud 구축
    온프레미스에서 운영중인 시스템을 한번에 모두 AWS Cloud로 Migration 하기는 어렵습니다.
    또한 내부에 구축한 환경을 동일하게 AWS Cloud로 구현할 수 없다면 온프레미스에서 운영중인 시스템을 같이 사용해야 되는데요.
    AWS Direct Connect을 사용하여 온프레미스와 AWS 클라우드 간의 안전하고 고성능의 연결을 설정할 수 있습니다.
    이를 통해 하이브리드 클라우드 아키텍처를 구축하고 온프레미스 리소스를 사용 가능하게 합니다.

 

  1. 보안 네트워크 구축
    별도의 방화벽과 보안 장치가 없이 인터넷 망을 통해서 AWS Cloud와 온프레미스 서로간의 네트워크 접근과 데이터를 전송한다면 보안에 취약합니다.
    AWS Direct Connect은 전용 연결을 통해 인터넷을 거치지 않고 공용 인터넷 대역폭을 우회하여 데이터 전송을 보안함으로써 더 높은 보안 수준을 제공합니다.
    또한 VPC 내의 프라이빗 서브넷과 온프레미스 리소스 간에 안전하고 효율적인 통신을 가능하게 합니다.

 

  1. 대용량 데이터 전송 및 고품질 네트워크 구축
    인터넷 망을 통해서 AWS Cloud와 온프레미스 서로간의 대용량의 데이터를 전송한다면 네트워크 지연 발생으로 안정적으로 데이터를 전송할 수 없습니다.
    AWS Direct Connect을 사용하여 대용량의 데이터를 안정적으로 업로드하거나 다운로드 할 수 있으며,
    실시간 비디오 스트리밍, 온라인 게임, 음성 통화 등의 애플리케이션에서는 네트워크 지연을 최소화하고 품질을 향상시킬 수 있습니다.

 

 

AWS Direct Connect에 대한 주요 기능, 요금, 활용 등 다양한 부분을 확인해봤는데요. 내부 네트워크 연결을 위해 AWS Direct Connect의 다양한 기능을 사용해보시기 바랍니다.

 

 

 

지금까지 AWS의 클라우드 서비스에 직접적으로 연결할 수 있는 네트워킹 서비스인 AWS Direct Connect를 알아보는 시간이었습니다....! 끝...!

 

 

유익하게 보셨다면 공감을 눌러주고, 댓글로 의견을 공유해 남겨주시면 감사하겠습니다!

 

 

 

[Reference]

 

 

 

[AWS] Amazon SNS 알아보기

서비스 장애 메시지를 실시간으로 확인하거나 서비스 업데이트 알림 등을 보내기 위해서는 이메일, 모바일 푸시 알림 및 모바일 문자 메시지(SMS) 등을 사용하고 있는데요. AWS 에서는 메시지 전송 관리형 서비스인 Amazon Simple Notification Service(Amazon SNS)를 통해 서비스를 지원하고 있습니다.

 

Amazon SNS는 다양한 클라이언트들에게 실시간으로 메시지를 보내고 수신할 수 있으며는 주제, 구독자, 발행자의 개념을 기반으로 관리되고 있습니다. 다양한 프로토콜을 지원하여 이메일, SMS, HTTP/HTTPS 모바일 푸시 알림 등을 통해 메시지를 전송할 수 있으며 Amazon Kinesis Data Firehose, Amazon SQS, AWS Lambda 등의 AWS 서비스에도 연동하여 사용할 수 있습니다.

 

 


주요 기능

Amazon SNS는 애플리케이션, 시스템, 서비스 간에 신속하고 안정적인 메시지 전송을 제공하며

아래와 같은 주요 기능을 제공합니다.

 

  1. 메시지 푸시
    • Amazon SNS를 사용하여 다양한 클라이언트에게 메시지를 푸시할 수 있습니다.
    • 이메일, SMS, HTTP/HTTPS, 모바일 푸시 알림 등 다양한 프로토콜을 통해 메시지를 전송할 수 있습니다.
  2. 주제 기반 구독
    • Amazon SNS는 주제(Topic)를 생성하여 관련 구독자를 그룹화할 수 있습니다.
    • 구독자는 특정 주제에 대한 알림을 받기 위해 해당 주제에 가입하고, 이를 통해 세밀한 구독 관리와 대상 그룹의 동적 구성이 가능합니다.
  3. 다양한 엔드포인트 지원
    • Amazon SNS는 이메일 주소, SMS 번호, AWS Lambda 함수, Amazon Simple Queue Service (SQS) 대기열 등 다양한 대상에게 메시지를 전달하고 연동할 수 있습니다.
  4. 확장성과 안정성
    • Amazon SNS는 확장 가능한 서비스로, 메시지 처리량이 매우 높은 환경에서도 안정적으로 동작합니다.
    • 수신 확인 및 재시도 기능을 제공하여 메시지 전송의 신뢰성을 보장합니다.
  5. 필터링 및 메시지 페이로드
    • Amazon SNS는 메시지 필터링을 통해 특정 조건에 따라 메시지를 선택적으로 전송할 수 있습니다.
    • 메시지 페이로드를 통해 추가 데이터를 전송하고 수신측에서 이를 활용할 수 있습니다.
  6. AWS 서비스와의 통합
    • Amazon SNS는 다른 AWS 서비스와의 강력한 통합을 제공합니다.
    • Amazon Kinesis Data Firehose, Amazon SQS, AWS Lambda와의 연동을 통해 실시간 데이터 스트리밍, 큐잉 및 서버리스 아키텍처 시나리오에서 유연하게 메시지를 전송하고 처리할 수 있습니다.

 

 


작동 방식

Amazon SNS는 A2A와 A2P의 두 가지 방식으로 알림을 전송합니다.

 

A2A는 분산된 시스템, 마이크로서비스 및 이벤트 중심의 서버리스 애플리케이션 간에 처리량이 많은 푸시 기반의 다대다 메시징을 제공합니다. 이러한 애플리케이션에는 Amazon Simple Queue Service(SQS), Amazon Kinesis Data Firehose, AWS Lambda, 기타 HTTPS 엔드포인트가 포함됩니다.


A2P 기능을 사용하면 SMS 텍스트, 푸시 알림, 이메일을 통해 고객에게 메시지를 전송할 수 있습니다.

 

게시/구독

 

SMS

 

모바일 푸시

 


요금

Amazon SNS의 요금은 표준 주제 API 요청, FIFO 주제 API 요청, 페이로드 크기, Amazon S3에서 페이로드 크기 확장, AWS KMS와 상호 작용으로 측정됩니다.


간단히 요약한다면 API 요청과 데이터 전송으로 나눠져 있다고 생각하면 좋을 것 같습니다.

 

알림 전달

 

데이터 전송

 

상세한 내용은 아래 링크를 통해 확인하시기 바랍니다.
https://aws.amazon.com/ko/sns/pricing/

 

 

추가적으로 모바일 문자 메시지(SMS) 및 모바일 푸시 알림 등은 지원되는 리전이 정해져있으니 참고하시기 바랍니다.

 

 


화면

Amazon SNS은 주제(Topic)을 기준으로 서비스를 관리할 수 있습니다.

 

 

Topics 메뉴에서 Topic을 생성하거나 기존에 생성된 Topic을 관리할 수 있습니다.
Subscriptions 메뉴에서는 각 Topic에 대한 구독자를 관리할 수 있습니다.

 

 


활용

서비스에서 발생하는 이벤트에 대한 알림을 실시간으로 Email 및 SMS 등을 전송할 수 있습니다.
예를 들어 주문 상태 변경, 결제 완료 등의 이벤트가 있습니다.

 

 

서비스에 중요한 이벤트나 장애가 발생하면 실시간으로 이벤트를 Email 및 SMS 등을 통해 경고 알림을 전송할 수 있습니다.

예를 들어, 시스템 다운, CPU or Memory 부하 발생, 서비스 이용자 급증 등의 이벤트가 있습니다.

 

 

AWS에서 제공하는 암호화 서비스(KMS) 등과의 연동을 통해 암호화된 메시지를 전송할 수 있습니다.

SageMaker에서 S3 버킷에 저장된 기계 학습 데이터를 사용하는 작업을 완료하였습니다.

 

 

Amazon SNS에 대한 기존적인 정보들을 알아보았으니 실제 서비스에 적용하여 활용해보시기 바랍니다.

지금까지 Amazon에서 제공하는 메시지 전송 관리형 서비스인 Amazon Simple Notification Service(Amazon SNS)을 알아보는 시간이었습니다....! 끝...!

 

 

유익하게 보셨다면 공감을 눌러주고, 댓글로 의견을 공유해 남겨주시면 감사하겠습니다!

 

 

 

 

[Reference]

 

 

 

 

[AWS] SageMaker에서 S3 버킷에 저장된 학습 데이터 사용하기

이전 포스트에서는 AWS에서 자체 제공하는 기계 학습 플랫폼인 SageMaker를 사용하여 기계 학습 환경을 구축해봤는데요.


SageMaker에서 기계 학습 시 로컬 디렉토리나 다운로드 받은 기계 학습 데이터를 사용하는 것이 아닌 S3 버킷에 저장된 기계 학습 데이터를 사용하여 기계 학습을 실행할 수 있도록 해보겠습니다.

 

이전이 작성한 포스트인 Amazon SageMaker를 사용하여 기계 학습 환경을 구축하는 방법을 기준으로 진행하는 작업이므로 이전 포스트를 사전에 확인 후 작업하시면 더 도움이 될 것 같습니다.

 

 


SageMaker S3 버킷 확인

SageMaker Studio에서 Jupyter Notebook을 통해 Session 생성 시 Default S3 버킷이 생성됩니다.


아래 명령어를 통해 Default S3 버킷 이름을 확인하실 수 있습니다.

import sagemaker

#========== 기본설정 ==========
# Session 생성
sagemaker_session = sagemaker.Session()

# Amazon S3 bucket 이름
s3_bucket_name = sagemaker_session.default_bucket()

# Amazon S3 bucket 출력
print (s3_bucket_name)

 

 


기계 학습 데이터 S3 버킷 업로드

기계 학습 데이터는 COCO 데이터 셋을 사용하도록 하겠습니다.


SageMaker Default S3 버킷에 폴더를 생성 후 COCO 데이터 셋을 업로드 합니다.


업로드 작업은 AWS Console에서 작업하거나 AWS CLI를 통해 S3 버킷에 기계 학습 데이터를 업로드 할 수 있습니다.

 

AWS CLI 예시

# aws s3 cp {{기계 학습 데이터}}  s3://{{S3 버킷 URL}}/coco128/images/.

 

 


기계 학습 코드

 

기계 학습 코드 - 기본 설정

SageMaker Default S3 버킷을 확인하고 COCO 데이터 셋 경로와 모델 저장 경로를 설정합니다.

import sagemaker

#========== 기본설정 ==========
# Session 생성
sagemaker_session = sagemaker.Session()

# Amazon S3 bucket 이름
s3_bucket_name = sagemaker_session.default_bucket()

# IAM role
role = sagemaker.get_execution_role()


#========== 학습 설정 ==========
# 데이터셋 경로
dataset_path = 'coco128'

# 모델 저장 경로
output_path = 'coco128/train'

# S3 bucket 데이터셋 경로
s3_dataset_path = f's3://{s3_bucket_name}/{dataset_path}'

# S3 bucket 모델 저장 경로
s3_output_path = f's3://{s3_bucket_name}/{output_path}'


# Estimator 설정
est_pytorch_entry_point= 'train.py'
est_pytorch_image_uri = '{ECR_URL}/sagemaker:pytorch-training-2.0.0-gpu-py310-cu118-ubuntu20.04-sagemaker'
est_pytorch_framework_version = '2.0.0'
est_pytorch_py_version = 'py310'
est_pytorch_instance_type = 'ml.g4dn.xlarge'
est_pytorch_instance_count = 1
est_pytorch_source_dir = './'

# Hyperparameters 설정
est_pytorch_hyperparameters={
    'data': 'coco128.yaml',
    'cfg': 'yolov5s.yaml',
    'epochs': 3,
    'project' : '/opt/ml/model',
    'batch-size': 8
}

 

  1. SageMaker Default S3 버킷 이름을 설정합니다.
    • s3_bucket_name = sagemaker_session.default_bucket()
  2. S3 버킷관련 경로 설정을 추가합니다.
    • 데이터셋 경로 : dataset_path = 'coco128'
    • 모델 저장 경로 : output_path = 'coco128/train'
    • S3 bucket 데이터셋 경로 : s3_dataset_path = f's3://{s3_bucket_name}/{dataset_path}'
    • S3 bucket 모델 저장 경로 : s3_output_path = f's3://{s3_bucket_name}/{output_path}'

 

 

기계 학습 코드 - 입력 데이터 채널 및 Estimator 생성

기계 학습 입력 데이터 채널을 생성하고, 모델 저장 경로를 Estimator 생성 시 설정합니다.

from sagemaker.pytorch import PyTorch
from sagemaker.inputs import TrainingInput

# 입력 데이터 채널 (기계 학습 데이터)
data_inputs = TrainingInput(s3_data=s3_dataset_path, content_type='application/x-image')

# Estimator 생성
pytorch_estimator = PyTorch(
    entry_point=est_pytorch_entry_point,
    image_uri=est_pytorch_image_uri,
    framework_version=est_pytorch_framework_version,
    py_version=est_pytorch_py_version,
    instance_type=est_pytorch_instance_type,
    instance_count=est_pytorch_instance_count,
    source_dir=est_pytorch_source_dir,
    output_path=s3_output_path,
    train_output=s3_output_path,
    sagemaker_session=sagemaker_session,
    role=role,
    hyperparameters=est_pytorch_hyperparameters
)

 

  1. 사전에 S3 버킷에 업로드한 기계 학습 데이터를 사용할 수 있도록 기계 학습 입력 데이터 채널을 생성합니다.
  2. Estimator 생성 시 output_path, train_output 옵션을 추가하여 모델 저장 경로를 설정합니다.

 

 

기계 학습 코드 - 학습 시작

사전에 생성한 기계 학습 입력 데이터 채널을 기계 학습 시작 시 사용하는 .fit() 함수에 추가합니다.

# 학습 시작
pytorch_estimator.fit(inputs=data_inputs)

 

 

 

기계 학습 코드 - 데이터 셋 경로 설정 변경

S3 버킷을 통해 기계 학습 데이터 다운로드 시 기본 경로인 /opt/ml/input/data 경로에 데이터가 다운로드 됩니다.


coco128.yaml 파일을 사용하여 데이터 셋을 정의하고 있으며 해당 파일의 경로 설정을 변경하여 S3 버킷을 통해 다운로드 받은 기계 학습 데이터를 사용할 수 있도록 수정합니다.

# 기존
path: ../datasets/coco128  # dataset root dir
# 수정
path: /opt/ml/input/data/training

 

 


기계 학습 코드 실행

작성한 기계 학습 코드를 실행해보도록 하겠습니다.

 

Estimator의 fit 함수를 실행합니다.

 

 

 

기존에는 학습 데이터를 저장하고 있지 않았기 때문에 기계 학습 데이터를 다운로드 받으며,

S3 버킷의 기계 학습 데이터를 사용할 경우 데이터 셋을 확인하여 이후 작업을 진행합니다.

  • 기존

 

  • S3 버킷 기계 학습 데이터 사용

 

 

 

S3 버킷의 기계 학습 데이터를 사용하기 때문에 기계 학습 시간도 단축됩니다.

  • 기존 (427)

 

  • S3 버킷 기계 학습 데이터 사용 (363초)

 

 

  • 기계 학습 완료 시 사전에 설정한 모델 저장 경로에 모델 파일이 저장되어 있는지 저장 경로를 확인할 수 있습니다.

 

  • S3 버킷에 직접 접속 후 기계 학습이 완료된 모델 파일을 확인하시기 바랍니다.

 

 

전체 학습 상세 로그는 아래 버튼을 클릭하여 확인하시기 바랍니다.

학습 상세 로그
Using provided s3_resource
INFO:sagemaker:Creating training-job with name: sagemaker-2023-07-04-07-46-10-310
2023-07-04 07:46:13 Starting - Starting the training job...
2023-07-04 07:46:28 Starting - Preparing the instances for training......
2023-07-04 07:47:31 Downloading - Downloading input data...
2023-07-04 07:48:01 Training - Downloading the training image...........................
2023-07-04 07:52:27 Training - Training image download completed. Training in progress.bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
2023-07-04 07:52:37,314 sagemaker-training-toolkit INFO     Imported framework sagemaker_pytorch_container.training
2023-07-04 07:52:37,331 sagemaker-training-toolkit INFO     No Neurons detected (normal if no neurons installed)
2023-07-04 07:52:37,340 sagemaker_pytorch_container.training INFO     Block until all host DNS lookups succeed.
2023-07-04 07:52:37,345 sagemaker_pytorch_container.training INFO     Invoking user training script.
2023-07-04 07:52:39,710 sagemaker-training-toolkit INFO     Installing dependencies from requirements.txt:
/opt/conda/bin/python3.10 -m pip install -r requirements.txt
Collecting gitpython>=3.1.30 (from -r requirements.txt (line 5))
Downloading GitPython-3.1.31-py3-none-any.whl (184 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 184.3/184.3 kB 12.4 MB/s eta 0:00:00
Requirement already satisfied: matplotlib>=3.3 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 6)) (3.7.1)
Requirement already satisfied: numpy>=1.18.5 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 7)) (1.23.5)
Requirement already satisfied: opencv-python>=4.1.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 8)) (4.7.0)
Requirement already satisfied: Pillow>=7.1.2 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 9)) (9.4.0)
Requirement already satisfied: psutil in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 10)) (5.9.5)
Requirement already satisfied: PyYAML>=5.3.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 11)) (5.4.1)
Requirement already satisfied: requests>=2.23.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 12)) (2.28.2)
Requirement already satisfied: scipy>=1.4.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 13)) (1.10.1)
Collecting thop>=0.1.1 (from -r requirements.txt (line 14))
Downloading thop-0.1.1.post2209072238-py3-none-any.whl (15 kB)
Requirement already satisfied: torch>=1.7.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 15)) (2.0.0)
Requirement already satisfied: torchvision>=0.8.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 16)) (0.15.1)
Requirement already satisfied: tqdm>=4.64.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 17)) (4.65.0)
Collecting ultralytics>=8.0.111 (from -r requirements.txt (line 18))
Downloading ultralytics-8.0.125-py3-none-any.whl (612 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 612.5/612.5 kB 80.2 MB/s eta 0:00:00
Requirement already satisfied: pandas>=1.1.4 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 27)) (2.0.1)
Requirement already satisfied: seaborn>=0.11.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 28)) (0.12.2)
Requirement already satisfied: setuptools>=65.5.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 42)) (65.6.3)
Collecting gitdb<5,>=4.0.1 (from gitpython>=3.1.30->-r requirements.txt (line 5))
Downloading gitdb-4.0.10-py3-none-any.whl (62 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.7/62.7 kB 21.5 MB/s eta 0:00:00
Requirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (1.0.7)
Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (4.39.4)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (1.4.4)
Requirement already satisfied: packaging>=20.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (23.1)
Requirement already satisfied: pyparsing>=2.3.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (2.8.2)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (3.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (1.26.15)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (2023.5.7)
Requirement already satisfied: filelock in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (3.12.0)
Requirement already satisfied: typing-extensions in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (4.5.0)
Requirement already satisfied: sympy in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (1.11.1)
Requirement already satisfied: networkx in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (3.1)
Requirement already satisfied: jinja2 in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (3.1.2)
Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=1.1.4->-r requirements.txt (line 27)) (2023.3)
Requirement already satisfied: tzdata>=2022.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=1.1.4->-r requirements.txt (line 27)) (2023.3)
Collecting smmap<6,>=3.0.1 (from gitdb<5,>=4.0.1->gitpython>=3.1.30->-r requirements.txt (line 5))
Downloading smmap-5.0.0-py3-none-any.whl (24 kB)
Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.3->-r requirements.txt (line 6)) (1.16.0)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/lib/python3.10/site-packages (from jinja2->torch>=1.7.0->-r requirements.txt (line 15)) (2.1.2)
Requirement already satisfied: mpmath>=0.19 in /opt/conda/lib/python3.10/site-packages (from sympy->torch>=1.7.0->-r requirements.txt (line 15)) (1.3.0)
Installing collected packages: smmap, gitdb, thop, gitpython, ultralytics
Successfully installed gitdb-4.0.10 gitpython-3.1.31 smmap-5.0.0 thop-0.1.1.post2209072238 ultralytics-8.0.125
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
2023-07-04 07:52:42,410 sagemaker-training-toolkit INFO     Waiting for the process to finish and give a return code.
2023-07-04 07:52:42,411 sagemaker-training-toolkit INFO     Done waiting for a return code. Received 0 from exiting process.
2023-07-04 07:52:42,428 sagemaker-training-toolkit INFO     No Neurons detected (normal if no neurons installed)
2023-07-04 07:52:42,453 sagemaker-training-toolkit INFO     No Neurons detected (normal if no neurons installed)
2023-07-04 07:52:42,477 sagemaker-training-toolkit INFO     No Neurons detected (normal if no neurons installed)
2023-07-04 07:52:42,485 sagemaker-training-toolkit INFO     Invoking user script
Training Env:
{
    "additional_framework_parameters": {},
    "channel_input_dirs": {
        "training": "/opt/ml/input/data/training"
    },
    "current_host": "algo-1",
    "current_instance_group": "homogeneousCluster",
    "current_instance_group_hosts": [
        "algo-1"
    ],
    "current_instance_type": "ml.g4dn.xlarge",
    "distribution_hosts": [],
    "distribution_instance_groups": [],
    "framework_module": "sagemaker_pytorch_container.training:main",
    "hosts": [
        "algo-1"
    ],
    "hyperparameters": {
        "batch-size": 8,
        "cfg": "yolov5s.yaml",
        "data": "coco128.yaml",
        "epochs": 3,
        "project": "/opt/ml/model/"
    },
    "input_config_dir": "/opt/ml/input/config",
    "input_data_config": {
        "training": {
            "ContentType": "application/x-image",
            "TrainingInputMode": "File",
            "S3DistributionType": "FullyReplicated",
            "RecordWrapperType": "None"
        }
    },
    "input_dir": "/opt/ml/input",
    "instance_groups": [
        "homogeneousCluster"
    ],
    "instance_groups_dict": {
        "homogeneousCluster": {
            "instance_group_name": "homogeneousCluster",
            "instance_type": "ml.g4dn.xlarge",
            "hosts": [
                "algo-1"
            ]
        }
    },
    "is_hetero": false,
    "is_master": true,
    "is_modelparallel_enabled": null,
    "is_smddpmprun_installed": true,
    "job_name": "sagemaker-2023-07-04-07-46-10-310",
    "log_level": 20,
    "master_hostname": "algo-1",
    "model_dir": "/opt/ml/model",
    "module_dir": "s3://####################/sagemaker-2023-07-04-07-46-10-310/source/sourcedir.tar.gz",
    "module_name": "train",
    "network_interface_name": "eth0",
    "num_cpus": 4,
    "num_gpus": 1,
    "num_neurons": 0,
    "output_data_dir": "/opt/ml/output/data",
    "output_dir": "/opt/ml/output",
    "output_intermediate_dir": "/opt/ml/output/intermediate",
    "resource_config": {
        "current_host": "algo-1",
        "current_instance_type": "ml.g4dn.xlarge",
        "current_group_name": "homogeneousCluster",
        "hosts": [
            "algo-1"
        ],
        "instance_groups": [
            {
                "instance_group_name": "homogeneousCluster",
                "instance_type": "ml.g4dn.xlarge",
                "hosts": [
                    "algo-1"
                ]
            }
        ],
        "network_interface_name": "eth0"
    },
    "user_entry_point": "train.py"
}
Environment variables:
SM_HOSTS=["algo-1"]
SM_NETWORK_INTERFACE_NAME=eth0
SM_HPS={"batch-size":8,"cfg":"yolov5s.yaml","data":"coco128.yaml","epochs":3,"project":"/opt/ml/model/"}
SM_USER_ENTRY_POINT=train.py
SM_FRAMEWORK_PARAMS={}
SM_RESOURCE_CONFIG={"current_group_name":"homogeneousCluster","current_host":"algo-1","current_instance_type":"ml.g4dn.xlarge","hosts":["algo-1"],"instance_groups":[{"hosts":["algo-1"],"instance_group_name":"homogeneousCluster","instance_type":"ml.g4dn.xlarge"}],"network_interface_name":"eth0"}
SM_INPUT_DATA_CONFIG={"training":{"ContentType":"application/x-image","RecordWrapperType":"None","S3DistributionType":"FullyReplicated","TrainingInputMode":"File"}}
SM_OUTPUT_DATA_DIR=/opt/ml/output/data
SM_CHANNELS=["training"]
SM_CURRENT_HOST=algo-1
SM_CURRENT_INSTANCE_TYPE=ml.g4dn.xlarge
SM_CURRENT_INSTANCE_GROUP=homogeneousCluster
SM_CURRENT_INSTANCE_GROUP_HOSTS=["algo-1"]
SM_INSTANCE_GROUPS=["homogeneousCluster"]
SM_INSTANCE_GROUPS_DICT={"homogeneousCluster":{"hosts":["algo-1"],"instance_group_name":"homogeneousCluster","instance_type":"ml.g4dn.xlarge"}}
SM_DISTRIBUTION_INSTANCE_GROUPS=[]
SM_IS_HETERO=false
SM_MODULE_NAME=train
SM_LOG_LEVEL=20
SM_FRAMEWORK_MODULE=sagemaker_pytorch_container.training:main
SM_INPUT_DIR=/opt/ml/input
SM_INPUT_CONFIG_DIR=/opt/ml/input/config
SM_OUTPUT_DIR=/opt/ml/output
SM_NUM_CPUS=4
SM_NUM_GPUS=1
SM_NUM_NEURONS=0
SM_MODEL_DIR=/opt/ml/model
SM_MODULE_DIR=s3://####################/sagemaker-2023-07-04-07-46-10-310/source/sourcedir.tar.gz
SM_TRAINING_ENV={"additional_framework_parameters":{},"channel_input_dirs":{"training":"/opt/ml/input/data/training"},"current_host":"algo-1","current_instance_group":"homogeneousCluster","current_instance_group_hosts":["algo-1"],"current_instance_type":"ml.g4dn.xlarge","distribution_hosts":[],"distribution_instance_groups":[],"framework_module":"sagemaker_pytorch_container.training:main","hosts":["algo-1"],"hyperparameters":{"batch-size":8,"cfg":"yolov5s.yaml","data":"coco128.yaml","epochs":3,"project":"/opt/ml/model/"},"input_config_dir":"/opt/ml/input/config","input_data_config":{"training":{"ContentType":"application/x-image","RecordWrapperType":"None","S3DistributionType":"FullyReplicated","TrainingInputMode":"File"}},"input_dir":"/opt/ml/input","instance_groups":["homogeneousCluster"],"instance_groups_dict":{"homogeneousCluster":{"hosts":["algo-1"],"instance_group_name":"homogeneousCluster","instance_type":"ml.g4dn.xlarge"}},"is_hetero":false,"is_master":true,"is_modelparallel_enabled":null,"is_smddpmprun_installed":true,"job_name":"sagemaker-2023-07-04-07-46-10-310","log_level":20,"master_hostname":"algo-1","model_dir":"/opt/ml/model","module_dir":"s3://####################/sagemaker-2023-07-04-07-46-10-310/source/sourcedir.tar.gz","module_name":"train","network_interface_name":"eth0","num_cpus":4,"num_gpus":1,"num_neurons":0,"output_data_dir":"/opt/ml/output/data","output_dir":"/opt/ml/output","output_intermediate_dir":"/opt/ml/output/intermediate","resource_config":{"current_group_name":"homogeneousCluster","current_host":"algo-1","current_instance_type":"ml.g4dn.xlarge","hosts":["algo-1"],"instance_groups":[{"hosts":["algo-1"],"instance_group_name":"homogeneousCluster","instance_type":"ml.g4dn.xlarge"}],"network_interface_name":"eth0"},"user_entry_point":"train.py"}
SM_USER_ARGS=["--batch-size","8","--cfg","yolov5s.yaml","--data","coco128.yaml","--epochs","3","--project","/opt/ml/model/"]
SM_OUTPUT_INTERMEDIATE_DIR=/opt/ml/output/intermediate
SM_CHANNEL_TRAINING=/opt/ml/input/data/training
SM_HP_BATCH-SIZE=8
SM_HP_CFG=yolov5s.yaml
SM_HP_DATA=coco128.yaml
SM_HP_EPOCHS=3
SM_HP_PROJECT=/opt/ml/model/
PYTHONPATH=/opt/ml/code:/opt/conda/bin:/opt/conda/lib/python310.zip:/opt/conda/lib/python3.10:/opt/conda/lib/python3.10/lib-dynload:/opt/conda/lib/python3.10/site-packages
Invoking script with the following command:
/opt/conda/bin/python3.10 train.py --batch-size 8 --cfg yolov5s.yaml --data coco128.yaml --epochs 3 --project /opt/ml/model/
2023-07-04 07:52:42,517 sagemaker-training-toolkit INFO     Exceptions not imported for SageMaker TF as Tensorflow is not installed.
#033[34m#033[1mtrain: #033[0mweights=yolov5s.pt, cfg=yolov5s.yaml, data=coco128.yaml, hyp=data/hyps/hyp.scratch-low.yaml, epochs=3, batch_size=8, imgsz=640, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, bucket=, cache=None, image_weights=False, device=, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=8, project=/opt/ml/model/, name=exp, exist_ok=False, quad=False, cos_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, seed=0, local_rank=-1, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest
From https://github.com/ultralytics/yolov5
   0004c74..a453a45  master       -> origin/master
* [new branch]      discord-link -> origin/discord-link
* [new branch]      pre-commit-ci-update-config -> origin/pre-commit-ci-update-config
#033[34m#033[1mgithub: #033[0m⚠️ YOLOv5 is out of date by 2 commits. Use 'git pull' or 'git clone https://github.com/ultralytics/yolov5' to update.
YOLOv5 🚀 v7.0-187-g0004c74 Python-3.10.8 torch-2.0.0 CUDA:0 (Tesla T4, 15102MiB)
#033[34m#033[1mhyperparameters: #033[0mlr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0
#033[34m#033[1mComet: #033[0mrun 'pip install comet_ml' to automatically track and visualize YOLOv5 🚀 runs in Comet
#033[34m#033[1mTensorBoard: #033[0mStart with 'tensorboard --logdir /opt/ml/model', view at http://localhost:6006/
Downloading https://ultralytics.com/assets/Arial.ttf to /root/.config/Ultralytics/Arial.ttf...
0%|          | 0.00/755k [00:00<?, ?B/s]
100%|██████████| 755k/755k [00:00<00:00, 42.6MB/s]
Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to yolov5s.pt...
0%|          | 0.00/14.1M [00:00<?, ?B/s]
100%|██████████| 14.1M/14.1M [00:00<00:00, 411MB/s]
from  n    params  module                                  arguments
0                -1  1      3520  models.common.Conv                      [3, 32, 6, 2, 2]
1                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]
2                -1  1     18816  models.common.C3                        [64, 64, 1]
3                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]
4                -1  2    115712  models.common.C3                        [128, 128, 2]
5                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]
6                -1  3    625152  models.common.C3                        [256, 256, 3]
7                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]
8                -1  1   1182720  models.common.C3                        [512, 512, 1]
9                -1  1    656896  models.common.SPPF                      [512, 512, 5]
10                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]
11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']
12           [-1, 6]  1         0  models.common.Concat                    [1]
13                -1  1    361984  models.common.C3                        [512, 256, 1, False]
14                -1  1     33024  models.common.Conv                      [256, 128, 1, 1]
15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']
16           [-1, 4]  1         0  models.common.Concat                    [1]
17                -1  1     90880  models.common.C3                        [256, 128, 1, False]
18                -1  1    147712  models.common.Conv                      [128, 128, 3, 2]
19          [-1, 14]  1         0  models.common.Concat                    [1]
20                -1  1    296448  models.common.C3                        [256, 256, 1, False]
21                -1  1    590336  models.common.Conv                      [256, 256, 3, 2]
22          [-1, 10]  1         0  models.common.Concat                    [1]
23                -1  1   1182720  models.common.C3                        [512, 512, 1, False]
24      [17, 20, 23]  1    229245  models.yolo.Detect                      [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
YOLOv5s summary: 214 layers, 7235389 parameters, 7235389 gradients, 16.6 GFLOPs
Transferred 348/349 items from yolov5s.pt
#033[34m#033[1mAMP: #033[0mchecks passed ✅
#033[34m#033[1moptimizer:#033[0m SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 60 weight(decay=0.0005), 60 bias
#033[34m#033[1mtrain: #033[0mScanning /opt/ml/input/data/training/labels/train2017...:   0%|          | 0/128 [00:00<?, ?it/s]
#033[34m#033[1mtrain: #033[0mScanning /opt/ml/input/data/training/labels/train2017... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<00:00, 2417.66it/s]
#033[34m#033[1mtrain: #033[0mNew cache created: /opt/ml/input/data/training/labels/train2017.cache
#033[34m#033[1mval: #033[0mScanning /opt/ml/input/data/training/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<?, ?it/s]
#033[34m#033[1mval: #033[0mScanning /opt/ml/input/data/training/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<?, ?it/s]
#033[34m#033[1mAutoAnchor: #033[0m4.27 anchors/target, 0.994 Best Possible Recall (BPR). Current anchors are a good fit to dataset ✅
Plotting labels to /opt/ml/model/exp/labels.jpg...
Image sizes 640 train, 640 val
Using 4 dataloader workers
Logging results to #033[1m/opt/ml/model/exp#033[0m
Starting training for 3 epochs...
Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
0%|          | 0/16 [00:00<?, ?it/s]
0/2      1.72G    0.04263    0.04785    0.02002         84        640:   0%|          | 0/16 [00:00<?, ?it/s]
0/2      1.72G    0.04263    0.04785    0.02002         84        640:   6%|▋         | 1/16 [00:00<00:07,  2.00it/s]
0/2      1.86G    0.04137     0.0532    0.01919         77        640:   6%|▋         | 1/16 [00:00<00:07,  2.00it/s]
0/2      1.86G    0.04137     0.0532    0.01919         77        640:  12%|█▎        | 2/16 [00:00<00:04,  3.39it/s]
0/2      1.86G    0.04399    0.05919    0.01962         86        640:  12%|█▎        | 2/16 [00:00<00:04,  3.39it/s]
0/2      1.86G    0.04399    0.05919    0.01962         86        640:  19%|█▉        | 3/16 [00:00<00:03,  3.98it/s]
0/2      1.86G     0.0457    0.06293    0.01933        123        640:  19%|█▉        | 3/16 [00:01<00:03,  3.98it/s]#015        0/2      1.86G     0.0457    0.06293    0.01933        123        640:  25%|██▌       | 4/16 [00:01<00:03,  3.71it/s]
0/2      1.86G    0.04631    0.06611    0.01771        115        640:  25%|██▌       | 4/16 [00:01<00:03,  3.71it/s]
0/2      1.86G    0.04631    0.06611    0.01771        115        640:  31%|███▏      | 5/16 [00:01<00:02,  4.62it/s]
0/2      1.86G    0.04695    0.06591    0.01847        114        640:  31%|███▏      | 5/16 [00:01<00:02,  4.62it/s]#015        0/2      1.86G    0.04695    0.06591    0.01847        114        640:  38%|███▊      | 6/16 [00:01<00:01,  5.28it/s]
0/2      1.86G    0.04622    0.06352    0.01832         78        640:  38%|███▊      | 6/16 [00:01<00:01,  5.28it/s]#015        0/2      1.86G    0.04622    0.06352    0.01832         78        640:  44%|████▍     | 7/16 [00:01<00:01,  5.99it/s]
0/2      1.86G    0.04573    0.06442      0.018        118        640:  44%|████▍     | 7/16 [00:01<00:01,  5.99it/s]
0/2      1.86G    0.04573    0.06442      0.018        118        640:  50%|█████     | 8/16 [00:01<00:01,  6.63it/s]
0/2      1.86G    0.04537    0.06323    0.01781         76        640:  50%|█████     | 8/16 [00:01<00:01,  6.63it/s]
0/2      1.86G    0.04574    0.06244    0.01824         91        640:  50%|█████     | 8/16 [00:01<00:01,  6.63it/s]
0/2      1.86G    0.04574    0.06244    0.01824         91        640:  62%|██████▎   | 10/16 [00:01<00:00,  7.67it/s]
0/2      1.86G    0.04525    0.06201    0.01792         96        640:  62%|██████▎   | 10/16 [00:01<00:00,  7.67it/s]
0/2      1.86G    0.04525    0.06201    0.01792         96        640:  69%|██████▉   | 11/16 [00:01<00:00,  8.13it/s]
0/2      1.86G    0.04521     0.0621    0.01862        103        640:  69%|██████▉   | 11/16 [00:02<00:00,  8.13it/s]#015        0/2      1.86G    0.04521     0.0621    0.01862        103        640:  75%|███████▌  | 12/16 [00:02<00:00,  7.87it/s]
0/2      1.86G    0.04485    0.06149     0.0183         91        640:  75%|███████▌  | 12/16 [00:02<00:00,  7.87it/s]
0/2      1.86G    0.04485    0.06149     0.0183         91        640:  81%|████████▏ | 13/16 [00:02<00:00,  8.36it/s]
0/2      1.86G    0.04482    0.06218    0.01863        116        640:  81%|████████▏ | 13/16 [00:02<00:00,  8.36it/s]
0/2      1.86G    0.04482    0.06218    0.01863        116        640:  88%|████████▊ | 14/16 [00:02<00:00,  8.19it/s]
0/2      1.86G    0.04545    0.06109    0.01889         63        640:  88%|████████▊ | 14/16 [00:02<00:00,  8.19it/s]#015        0/2      1.86G    0.04545    0.06109    0.01889         63        640:  94%|█████████▍| 15/16 [00:02<00:00,  8.26it/s]
0/2      1.86G    0.04523    0.06067    0.01926         82        640:  94%|█████████▍| 15/16 [00:02<00:00,  8.26it/s]#015        0/2      1.86G    0.04523    0.06067    0.01926         82        640: 100%|██████████| 16/16 [00:02<00:00,  8.03it/s]#015        0/2      1.86G    0.04523    0.06067    0.01926         82        640: 100%|██████████| 16/16 [00:02<00:00,  6.20it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/8 [00:00<?, ?it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  12%|█▎        | 1/8 [00:01<00:10,  1.44s/it]
Class     Images  Instances          P          R      mAP50   mAP50-95:  25%|██▌       | 2/8 [00:01<00:04,  1.48it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  38%|███▊      | 3/8 [00:01<00:02,  2.10it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  50%|█████     | 4/8 [00:01<00:01,  2.94it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  62%|██████▎   | 5/8 [00:02<00:00,  3.70it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  75%|███████▌  | 6/8 [00:02<00:00,  3.92it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  88%|████████▊ | 7/8 [00:02<00:00,  4.14it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:02<00:00,  4.35it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:02<00:00,  2.92it/s]
all        128        929      0.732      0.631      0.718      0.477
Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
0%|          | 0/16 [00:00<?, ?it/s]
1/2      2.03G    0.05467    0.06597    0.02623        109        640:   0%|          | 0/16 [00:00<?, ?it/s]
1/2      2.03G    0.04909     0.0572     0.0236         60        640:   0%|          | 0/16 [00:00<?, ?it/s]
1/2      2.03G    0.04909     0.0572     0.0236         60        640:  12%|█▎        | 2/16 [00:00<00:01, 10.01it/s]
1/2      2.03G    0.04965    0.06586    0.02222        137        640:  12%|█▎        | 2/16 [00:00<00:01, 10.01it/s]
1/2      2.04G    0.04856    0.07264    0.02058        143        640:  12%|█▎        | 2/16 [00:00<00:01, 10.01it/s]
1/2      2.04G    0.04856    0.07264    0.02058        143        640:  25%|██▌       | 4/16 [00:00<00:01, 10.01it/s]
1/2      2.04G    0.04746    0.07102    0.01933         91        640:  25%|██▌       | 4/16 [00:00<00:01, 10.01it/s]
1/2      2.04G    0.04695     0.0708    0.01908         94        640:  25%|██▌       | 4/16 [00:00<00:01, 10.01it/s]
1/2      2.04G    0.04695     0.0708    0.01908         94        640:  38%|███▊      | 6/16 [00:00<00:01,  9.95it/s]
1/2      2.04G    0.04689     0.0724    0.01959        135        640:  38%|███▊      | 6/16 [00:00<00:01,  9.95it/s]
1/2      2.04G    0.04749    0.07476    0.01983        159        640:  38%|███▊      | 6/16 [00:00<00:01,  9.95it/s]
1/2      2.04G    0.04749    0.07476    0.01983        159        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
1/2      2.04G    0.04698    0.07365    0.01919         97        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
1/2      2.04G     0.0468    0.07334    0.01888        109        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
1/2      2.04G     0.0468    0.07334    0.01888        109        640:  62%|██████▎   | 10/16 [00:00<00:00,  9.99it/s]
1/2      2.04G    0.04633    0.07145      0.019         88        640:  62%|██████▎   | 10/16 [00:01<00:00,  9.99it/s]
1/2      2.04G    0.04585       0.07      0.019         79        640:  62%|██████▎   | 10/16 [00:01<00:00,  9.99it/s]
1/2      2.04G    0.04585       0.07      0.019         79        640:  75%|███████▌  | 12/16 [00:01<00:00,  9.89it/s]
1/2      2.04G    0.04636    0.06949    0.01866        104        640:  75%|███████▌  | 12/16 [00:01<00:00,  9.89it/s]
1/2      2.04G    0.04635    0.06968    0.01835        120        640:  75%|███████▌  | 12/16 [00:01<00:00,  9.89it/s]
1/2      2.04G    0.04635    0.06968    0.01835        120        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.15it/s]
1/2      2.04G    0.04637    0.06777    0.01839         76        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.15it/s]
1/2      2.04G    0.04622    0.06747    0.01825        116        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.15it/s]
1/2      2.04G    0.04622    0.06747    0.01825        116        640: 100%|██████████| 16/16 [00:01<00:00,  8.42it/s]#015        1/2      2.04G    0.04622    0.06747    0.01825        116        640: 100%|██████████| 16/16 [00:01<00:00,  9.33it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/8 [00:00<?, ?it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  12%|█▎        | 1/8 [00:00<00:00,  7.77it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  25%|██▌       | 2/8 [00:00<00:00,  7.41it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  38%|███▊      | 3/8 [00:00<00:00,  7.31it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  50%|█████     | 4/8 [00:00<00:00,  7.30it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  62%|██████▎   | 5/8 [00:00<00:00,  7.08it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  75%|███████▌  | 6/8 [00:00<00:00,  6.67it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  88%|████████▊ | 7/8 [00:01<00:00,  6.77it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:01<00:00,  6.87it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:01<00:00,  6.99it/s]
all        128        929      0.785      0.629      0.738      0.498
Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
0%|          | 0/16 [00:00<?, ?it/s]
2/2      2.04G    0.04802     0.1227    0.01417        195        640:   0%|          | 0/16 [00:00<?, ?it/s]
2/2      2.04G    0.04561    0.08766    0.01594        101        640:   0%|          | 0/16 [00:00<?, ?it/s]
2/2      2.04G    0.04561    0.08766    0.01594        101        640:  12%|█▎        | 2/16 [00:00<00:01,  9.64it/s]
2/2      2.04G    0.04542    0.07617    0.01757         86        640:  12%|█▎        | 2/16 [00:00<00:01,  9.64it/s]
2/2      2.04G    0.04423    0.07265    0.01708         98        640:  12%|█▎        | 2/16 [00:00<00:01,  9.64it/s]
2/2      2.04G    0.04423    0.07265    0.01708         98        640:  25%|██▌       | 4/16 [00:00<00:01, 10.27it/s]
2/2      2.04G    0.04398    0.07078    0.01723        111        640:  25%|██▌       | 4/16 [00:00<00:01, 10.27it/s]
2/2      2.04G    0.04369    0.07246    0.01751        113        640:  25%|██▌       | 4/16 [00:00<00:01, 10.27it/s]
2/2      2.04G    0.04369    0.07246    0.01751        113        640:  38%|███▊      | 6/16 [00:00<00:01, 10.00it/s]
2/2      2.04G    0.04346    0.06956      0.018        102        640:  38%|███▊      | 6/16 [00:00<00:01, 10.00it/s]
2/2      2.04G    0.04342    0.06977    0.01773        118        640:  38%|███▊      | 6/16 [00:00<00:01, 10.00it/s]
2/2      2.04G    0.04342    0.06977    0.01773        118        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
2/2      2.04G    0.04328    0.06999    0.01823        102        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
2/2      2.04G    0.04326    0.06942    0.01802        113        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
2/2      2.04G    0.04326    0.06942    0.01802        113        640:  62%|██████▎   | 10/16 [00:00<00:00, 10.05it/s]
2/2      2.04G    0.04364    0.06832    0.01798        118        640:  62%|██████▎   | 10/16 [00:01<00:00, 10.05it/s]
2/2      2.04G    0.04363    0.06963    0.01759        140        640:  62%|██████▎   | 10/16 [00:01<00:00, 10.05it/s]
2/2      2.04G    0.04363    0.06963    0.01759        140        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.25it/s]
2/2      2.04G    0.04389    0.06915     0.0175        107        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.25it/s]
2/2      2.04G    0.04385     0.0688    0.01785         98        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.25it/s]
2/2      2.04G    0.04385     0.0688    0.01785         98        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.07it/s]
2/2      2.04G    0.04383    0.06737    0.01852         62        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.07it/s]
2/2      2.04G    0.04365    0.06745    0.01911         96        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.07it/s]
2/2      2.04G    0.04365    0.06745    0.01911         96        640: 100%|██████████| 16/16 [00:01<00:00,  8.03it/s]#015        2/2      2.04G    0.04365    0.06745    0.01911         96        640: 100%|██████████| 16/16 [00:01<00:00,  9.17it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/8 [00:00<?, ?it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  12%|█▎        | 1/8 [00:00<00:00,  7.89it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  25%|██▌       | 2/8 [00:00<00:00,  7.56it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  38%|███▊      | 3/8 [00:00<00:00,  7.36it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  50%|█████     | 4/8 [00:00<00:00,  7.44it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  62%|██████▎   | 5/8 [00:00<00:00,  6.98it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  75%|███████▌  | 6/8 [00:00<00:00,  6.80it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  88%|████████▊ | 7/8 [00:01<00:00,  6.67it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:01<00:00,  6.90it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:01<00:00,  7.03it/s]
all        128        929      0.819      0.627      0.747      0.504
3 epochs completed in 0.004 hours.
Optimizer stripped from /opt/ml/model/exp/weights/last.pt, 14.8MB
Optimizer stripped from /opt/ml/model/exp/weights/best.pt, 14.8MB
Validating /opt/ml/model/exp/weights/best.pt...
Fusing layers...
YOLOv5s summary: 157 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs
Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/8 [00:00<?, ?it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  12%|█▎        | 1/8 [00:00<00:01,  5.84it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  25%|██▌       | 2/8 [00:00<00:01,  3.41it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  38%|███▊      | 3/8 [00:00<00:01,  2.83it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  50%|█████     | 4/8 [00:01<00:01,  2.61it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  62%|██████▎   | 5/8 [00:01<00:00,  3.20it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  75%|███████▌  | 6/8 [00:01<00:00,  3.68it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  88%|████████▊ | 7/8 [00:01<00:00,  4.16it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:02<00:00,  4.61it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:02<00:00,  3.76it/s]
all        128        929      0.819      0.627      0.746      0.503
person        128        254        0.9      0.669      0.807      0.523
bicycle        128          6          1      0.331      0.711      0.427
car        128         46      0.859      0.413      0.579      0.243
motorcycle        128          5      0.682        0.8      0.798      0.663
airplane        128          6      0.979          1      0.995      0.755
bus        128          7      0.748      0.714      0.779      0.659
train        128          3          1      0.659      0.863      0.532
truck        128         12      0.664      0.333      0.501      0.242
boat        128          6          1      0.301      0.519      0.252
traffic light        128         14      0.607      0.214      0.377      0.222
stop sign        128          2      0.792          1      0.995      0.772
bench        128          9      0.823       0.52      0.717      0.311
bird        128         16      0.885          1      0.991      0.651
cat        128          4      0.918          1      0.995       0.77
dog        128          9          1      0.653      0.901      0.693
horse        128          2       0.89          1      0.995      0.622
              elephant        128         17      0.972      0.882      0.939      0.651
                  bear        128          1       0.71          1      0.995      0.995
zebra        128          4      0.885          1      0.995       0.93
giraffe        128          9      0.877      0.791      0.962      0.756
backpack        128          6          1      0.562      0.836      0.428
umbrella        128         18       0.79      0.629      0.877      0.529
handbag        128         19      0.959      0.158      0.337      0.188
tie        128          7      0.817      0.645      0.777      0.486
              suitcase        128          4      0.866          1      0.995      0.601
               frisbee        128          5      0.735        0.8        0.8      0.627
skis        128          1      0.827          1      0.995      0.497
             snowboard        128          7       0.85      0.714      0.867      0.544
sports ball        128          6      0.685      0.667      0.668      0.346
kite        128         10      0.835      0.508      0.628       0.22
baseball bat        128          4      0.521       0.25      0.388      0.171
baseball glove        128          7      0.763      0.429       0.47      0.276
skateboard        128          5      0.725       0.54      0.648      0.479
tennis racket        128          7      0.801      0.429      0.559      0.344
bottle        128         18      0.588      0.333      0.601       0.31
wine glass        128         16      0.735      0.875       0.89      0.448
cup        128         36      0.902      0.667      0.839       0.52
                  fork        128          6          1      0.311      0.439      0.302
knife        128         16      0.829      0.625      0.704      0.393
spoon        128         22      0.828      0.439      0.637      0.363
bowl        128         28          1       0.63      0.763      0.573
banana        128          1      0.809          1      0.995      0.302
sandwich        128          2          1          0      0.448      0.383
orange        128          4      0.829          1      0.995      0.738
broccoli        128         11      0.824      0.364      0.491      0.356
carrot        128         24      0.685      0.625      0.713      0.487
hot dog        128          2      0.547          1      0.663      0.614
pizza        128          5          1      0.792      0.962       0.77
donut        128         14      0.674          1      0.946      0.799
cake        128          4      0.774          1      0.995      0.846
chair        128         35      0.612      0.632      0.619      0.319
couch        128          6          1      0.646      0.826      0.527
          potted plant        128         14      0.903      0.786      0.875      0.508
bed        128          3          1          0      0.863      0.532
          dining table        128         13      0.804      0.317      0.621      0.407
toilet        128          2      0.857          1      0.995      0.796
                    tv        128          2      0.751          1      0.995      0.796
                laptop        128          3          1          0      0.913      0.548
                 mouse        128          2          1          0     0.0907     0.0454
                remote        128          8          1      0.617      0.629      0.513
cell phone        128          8      0.722      0.332      0.453      0.262
             microwave        128          3      0.848          1      0.995      0.843
oven        128          5      0.667        0.4       0.43      0.298
sink        128          6      0.272      0.167      0.338      0.252
refrigerator        128          5      0.672        0.8       0.81      0.558
book        128         29      0.749      0.206      0.367      0.168
clock        128          9      0.762      0.778      0.879      0.689
vase        128          2      0.439          1      0.995      0.895
scissors        128          1          1          0      0.166     0.0332
            teddy bear        128         21       0.85      0.571      0.788      0.506
            toothbrush        128          5      0.826          1      0.995      0.618
Results saved to #033[1m/opt/ml/model/exp#033[0m
2023-07-04 07:53:23,480 sagemaker-training-toolkit INFO     Waiting for the process to finish and give a return code.
2023-07-04 07:53:23,480 sagemaker-training-toolkit INFO     Done waiting for a return code. Received 0 from exiting process.
2023-07-04 07:53:23,480 sagemaker-training-toolkit INFO     Reporting training SUCCESS

2023-07-04 07:53:38 Uploading - Uploading generated training model
2023-07-04 07:53:38 Completed - Training job completed
Training seconds: 368
Billable seconds: 368

 

SageMaker에서 S3 버킷에 저장된 기계 학습 데이터를 사용하는 작업을 완료하였습니다.
이제 기계 학습 시 사용하는 기계 학습 데이터를 S3 버킷에 저장 및 관리하면서 기계 학습을 사용해보시기 바랍니다.

 

 

 

지금까지 SageMaker에서 S3 버킷에 저장된 기계 학습 데이터를 사용해보는 작업을 알아보는 시간이었습니다....! 끝...!

 

 

유익하게 보셨다면 공감을 눌러주고, 댓글로 의견을 공유해 남겨주시면 감사하겠습니다!

 

 

 

[AWS] SageMaker에서 PyTorch를 활용한 기계 학습 환경 구축하기

AI(인공 지능)의 발전과 적용 분야의 다양화로 인해 기계 학습에 대한 수요가 높아지고 있는데요. 기계 학습 환경을 구축하기 위해서는 여러가지 요소들이 필요합니다.


AWS에서 자체 제공하는 기계 학습 플랫폼인 SageMaker를 사용하여 기계 학습 환경을 구현해보도록 하겠습니다.

 

Amazon SageMaker에 대한 기본적인 정보는 이전 포스트를 참고하시기 바랍니다.

 

 


기계 학습 환경

구현해보고자하는 기계 학습 환경 정보입니다. 

다양한 기계 학습 라이브러리, 학습 모델, 데이터셋 등을 사용하실 수 있습니다.

 

기계 학습 라이브러리

  • 기계 학습 라이브러리는 오픈소스 머신 러닝 라이브러리인 PyTorch를 사용하여 기계 학습 환경을 구현해보도록 하겠습니다.

기계 학습 모델

  • 기계 학습 모델은 Object Detection 분야에서 많이 알려진 YOLOv5모델을 사용하도록 하겠습니다.

기계 학습 데이터

  • 기계 학습 데이터는 COCO dataset을 사용하도록 하겠습니다.

개발 환경

  • 개발 환경은 기계 학습을 위한 완전한 IDE(통합 개발 환경)을 제공하는 Amazon SageMaker Studio를 사용하도록 하겠습니다.
  • Studio에서 학습 코드와 학습 데이터를 구성하고 바로 기계 학습을 할 수 있도록 구성해보겠습니다.

 

 


개발 환경 설정

개발 환경 설정을 위해 Amazon SageMaker Studio를 사용합니다.


Studio에서는 Jupyter Notebook 파일(ipynb)로 기계 학습 코드를 실행하거나 Terminal을 통해 개발 환경을 구성할 수 있습니다. 각각의 요소들을 하나씩 구현해보도록 하겠습니다.

 

 

기계 학습 모델 다운로드

Terminal을 실행하여 기계 학습 모델은 YOLOv5를 다운로드 받습니다.

 

git clone 명령어를 통해 github 프로젝트를 다운로드 받습니다.

git clone https://github.com/ultralytics/yolov5.git

 

 

다운로드 완료 시 기계 학습 모델 코드가 정상적으로 다운로드 되었는지 확인하실 수 있습니다.

 

 

Jupyter Notebook 실행

Studio에서 Jupyter Notebook을 실행하기 위해 Notebook을 추가합니다.

 

 

Image는 PyTorch 라이브러리를 사용하며 기계 학습을 실행할 수 있도록 PyTorch 2.0.0 Python 3.10 CPU Optimized를 선택하였습니다.


Instance type을 GPU Instance를 사용 시 GPU Optimized를 선택해주시면 되고, 그렇지 않다면 원하는 타입을 선택 후 진행해주시면 됩니다.

 

 

생성된 Notebook은 오른쪽 클릭 후 이름을 변경하였습니다.

 

 

왼쪽 메뉴에 있는 Running Terminals and Kernels 버튼을 클릭하여 현재 Studio에서 실행되고 있는 리소스들을 확인하실 수 있습니다.

 

 


기계 학습 코드 작성

다운로드 받은 기계 학습 모델을 통해 Notebook에서 python 코드를 바로 실행하면 기계 학습을 실행할 수 있습니다.

!python train.py --data coco128.yaml --cfg yolov5s.yaml  --epochs 3 --batch-size 8 --weights ''

하지만 SageMaker에서 제공하는 SDK를 통해 기계 학습 환경을 구성할 것이므로, SageMaker의 SDK를 사용해보도록 합시다.

 

 

기계 학습 코드 - 기본 설정

기계 학습을 위해 기본 SageMaker 관련 설정과 Estimator를 설정해야됩니다.


Amazon SageMaker의 Estimator는 기계 학습 모델을 학습 및 배포하기 위한 고수준 추상화 인터페이스입니다.
Estimator를 사용하면 다양한 기계 학습 작업을 쉽게 관리하고 실행할 수 있습니다.

import sagemaker

#========== 기본설정 ==========
# Session 생성
sagemaker_session = sagemaker.Session()

# IAM role
role = sagemaker.get_execution_role()

#========== 학습 설정 ==========
# Estimator 설정
est_pytorch_entry_point= 'train.py'
est_pytorch_image_uri = '{ECR_URL}/sagemaker:pytorch-training-2.0.0-gpu-py310-cu118-ubuntu20.04-sagemaker'
est_pytorch_framework_version = '2.0.0'
est_pytorch_py_version = 'py310'
est_pytorch_instance_type = 'ml.g4dn.xlarge'
est_pytorch_instance_count = 1
est_pytorch_source_dir = './'

# Hyperparameters 설정
est_pytorch_hyperparameters={
    'data': 'coco128.yaml',
    'cfg': 'yolov5s.yaml',
    'epochs': 3,
    'project' : '/opt/ml/model',
    'batch-size': 8
}
  1. YOLOv5 모델 프로젝트의 기본 학습 코드 인 train.py 파일을 사용합니다.
  2. 기계 학습 시 사용할 PyTorch, Python 버전과 컨테이너 이미지를 지정합니다.
    • 별도의 컨테이너 이미지를 지정하지 않아도 SageMaker에서 자체 제공하는 이미지를 통해 기계 학습이 실행됩니다.
  3. 기계 학습 시 사용할 데이터 셋 및 옵션을 선택합니다.
    • coco128.yml 데이터셋을 지정하고, 모델은 YOLOv5s를 선택하였습니다.
    • epochs 값은 3, batch-size는 8로 설정하였으며 SageMaker 기본 모델 저장 경로를 지정하기 위해 project 값은 /opt/ml/model로 설정하였습니다.

 

 

기계 학습 코드 - Estimator 생성

기계 학습을 실행하기 위한 Estimator를 생성 작업을 진행합니다.


사전에 설정한 정보를 통해 Estimator를 생성합니다.

from sagemaker.pytorch import PyTorch
from sagemaker.inputs import TrainingInput

# Estimator 생성
pytorch_estimator = PyTorch(
    entry_point=est_pytorch_entry_point,
    image_uri=est_pytorch_image_uri,
    framework_version=est_pytorch_framework_version,
    py_version=est_pytorch_py_version,
    instance_type=est_pytorch_instance_type,
    instance_count=est_pytorch_instance_count,
    source_dir=est_pytorch_source_dir,
    sagemaker_session=sagemaker_session,
    role=role,
    hyperparameters=est_pytorch_hyperparameters
)

 

 

기계 학습 코드 - 학습 시작

 pytorch_estimator 이름으로 생성한 Estimator를 실행합니다.


 .fit() 함수를 통해 학습을 시작합니다.

# 학습 시작
pytorch_estimator.fit()

 

 

 

기계 학습 코드 - 모델 저장 경로 확인

기계 학습 완료 후 아래 명령어를 통해 저장된 모델 파일 및 경로를 확인할 수 있습니다.

# 학습된 모델 아티팩트의 S3 경로
model_data = pytorch_estimator.model_data

# S3에 저장된 weights 파일 확인
print("Model artifacts saved at:", model_data)

 

 


기계 학습 코드 실행

작성한 기계 학습 코드를 실행해보도록 하겠습니다.

 

Estimator의 fit 함수를 실행합니다.

 

 

기계 학습 완료 시 생성된 모델 경로와 성공 여부, 학습 시간 등을 확인하실 수 있습니다.

 

 

전체 학습 상세 로그는 아래 버튼을 클릭하여 확인하시기 바랍니다.

학습 상세 로그
Using provided s3_resource
INFO:sagemaker:Creating training-job with name: sagemaker-2023-06-30-08-49-38-688
2023-06-30 08:49:43 Starting - Starting the training job...
2023-06-30 08:50:00 Starting - Preparing the instances for training......
2023-06-30 08:51:00 Downloading - Downloading input data...
2023-06-30 08:51:20 Training - Downloading the training image.................................
2023-06-30 08:56:55 Training - Training image download completed. Training in progress.bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
2023-06-30 08:57:05,915 sagemaker-training-toolkit INFO     Imported framework sagemaker_pytorch_container.training
2023-06-30 08:57:05,930 sagemaker-training-toolkit INFO     No Neurons detected (normal if no neurons installed)
2023-06-30 08:57:05,939 sagemaker_pytorch_container.training INFO     Block until all host DNS lookups succeed.
2023-06-30 08:57:05,944 sagemaker_pytorch_container.training INFO     Invoking user training script.
2023-06-30 08:57:08,222 sagemaker-training-toolkit INFO     Installing dependencies from requirements.txt:
/opt/conda/bin/python3.10 -m pip install -r requirements.txt
Collecting gitpython>=3.1.30 (from -r requirements.txt (line 5))
Downloading GitPython-3.1.31-py3-none-any.whl (184 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 184.3/184.3 kB 13.1 MB/s eta 0:00:00
Requirement already satisfied: matplotlib>=3.3 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 6)) (3.7.1)
Requirement already satisfied: numpy>=1.18.5 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 7)) (1.23.5)
Requirement already satisfied: opencv-python>=4.1.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 8)) (4.7.0)
Requirement already satisfied: Pillow>=7.1.2 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 9)) (9.4.0)
Requirement already satisfied: psutil in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 10)) (5.9.5)
Requirement already satisfied: PyYAML>=5.3.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 11)) (5.4.1)
Requirement already satisfied: requests>=2.23.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 12)) (2.28.2)
Requirement already satisfied: scipy>=1.4.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 13)) (1.10.1)
Collecting thop>=0.1.1 (from -r requirements.txt (line 14))
Downloading thop-0.1.1.post2209072238-py3-none-any.whl (15 kB)
Requirement already satisfied: torch>=1.7.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 15)) (2.0.0)
Requirement already satisfied: torchvision>=0.8.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 16)) (0.15.1)
Requirement already satisfied: tqdm>=4.64.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 17)) (4.65.0)
Collecting ultralytics>=8.0.111 (from -r requirements.txt (line 18))
Downloading ultralytics-8.0.124-py3-none-any.whl (612 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 612.6/612.6 kB 35.5 MB/s eta 0:00:00
Requirement already satisfied: pandas>=1.1.4 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 27)) (2.0.1)
Requirement already satisfied: seaborn>=0.11.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 28)) (0.12.2)
Requirement already satisfied: setuptools>=65.5.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 42)) (65.6.3)
Collecting gitdb<5,>=4.0.1 (from gitpython>=3.1.30->-r requirements.txt (line 5))
Downloading gitdb-4.0.10-py3-none-any.whl (62 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.7/62.7 kB 17.3 MB/s eta 0:00:00
Requirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (1.0.7)
Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (4.39.4)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (1.4.4)
Requirement already satisfied: packaging>=20.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (23.1)
Requirement already satisfied: pyparsing>=2.3.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in /opt/conda/lib/python3.10/site-packages (from matplotlib>=3.3->-r requirements.txt (line 6)) (2.8.2)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (3.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (1.26.15)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (2023.5.7)
Requirement already satisfied: filelock in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (3.12.0)
Requirement already satisfied: typing-extensions in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (4.5.0)
Requirement already satisfied: sympy in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (1.11.1)
Requirement already satisfied: networkx in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (3.1)
Requirement already satisfied: jinja2 in /opt/conda/lib/python3.10/site-packages (from torch>=1.7.0->-r requirements.txt (line 15)) (3.1.2)
Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=1.1.4->-r requirements.txt (line 27)) (2023.3)
Requirement already satisfied: tzdata>=2022.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=1.1.4->-r requirements.txt (line 27)) (2023.3)
Collecting smmap<6,>=3.0.1 (from gitdb<5,>=4.0.1->gitpython>=3.1.30->-r requirements.txt (line 5))
Downloading smmap-5.0.0-py3-none-any.whl (24 kB)
Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.3->-r requirements.txt (line 6)) (1.16.0)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/lib/python3.10/site-packages (from jinja2->torch>=1.7.0->-r requirements.txt (line 15)) (2.1.2)
Requirement already satisfied: mpmath>=0.19 in /opt/conda/lib/python3.10/site-packages (from sympy->torch>=1.7.0->-r requirements.txt (line 15)) (1.3.0)
Installing collected packages: smmap, gitdb, thop, gitpython, ultralytics
Successfully installed gitdb-4.0.10 gitpython-3.1.31 smmap-5.0.0 thop-0.1.1.post2209072238 ultralytics-8.0.124
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
2023-06-30 08:57:10,933 sagemaker-training-toolkit INFO     Waiting for the process to finish and give a return code.
2023-06-30 08:57:10,933 sagemaker-training-toolkit INFO     Done waiting for a return code. Received 0 from exiting process.
2023-06-30 08:57:10,950 sagemaker-training-toolkit INFO     No Neurons detected (normal if no neurons installed)
2023-06-30 08:57:10,975 sagemaker-training-toolkit INFO     No Neurons detected (normal if no neurons installed)
2023-06-30 08:57:10,999 sagemaker-training-toolkit INFO     No Neurons detected (normal if no neurons installed)
2023-06-30 08:57:11,008 sagemaker-training-toolkit INFO     Invoking user script
Training Env:
{
    "additional_framework_parameters": {},
    "channel_input_dirs": {},
    "current_host": "algo-1",
    "current_instance_group": "homogeneousCluster",
    "current_instance_group_hosts": [
        "algo-1"
    ],
    "current_instance_type": "ml.g4dn.xlarge",
    "distribution_hosts": [],
    "distribution_instance_groups": [],
    "framework_module": "sagemaker_pytorch_container.training:main",
    "hosts": [
        "algo-1"
    ],
    "hyperparameters": {
        "batch-size": 8,
        "cfg": "yolov5s.yaml",
        "data": "coco128.yaml",
        "epochs": 3,
        "project": "/opt/ml/model"
    },
    "input_config_dir": "/opt/ml/input/config",
    "input_data_config": {},
    "input_dir": "/opt/ml/input",
    "instance_groups": [
        "homogeneousCluster"
    ],
    "instance_groups_dict": {
        "homogeneousCluster": {
            "instance_group_name": "homogeneousCluster",
            "instance_type": "ml.g4dn.xlarge",
            "hosts": [
                "algo-1"
            ]
        }
    },
    "is_hetero": false,
    "is_master": true,
    "is_modelparallel_enabled": null,
    "is_smddpmprun_installed": true,
    "job_name": "sagemaker-2023-06-30-08-49-38-688",
    "log_level": 20,
    "master_hostname": "algo-1",
    "model_dir": "/opt/ml/model",
    "module_dir": "s3://####################/sagemaker-2023-06-30-08-49-38-688/source/sourcedir.tar.gz",
    "module_name": "train",
    "network_interface_name": "eth0",
    "num_cpus": 4,
    "num_gpus": 1,
    "num_neurons": 0,
    "output_data_dir": "/opt/ml/output/data",
    "output_dir": "/opt/ml/output",
    "output_intermediate_dir": "/opt/ml/output/intermediate",
    "resource_config": {
        "current_host": "algo-1",
        "current_instance_type": "ml.g4dn.xlarge",
        "current_group_name": "homogeneousCluster",
        "hosts": [
            "algo-1"
        ],
        "instance_groups": [
            {
                "instance_group_name": "homogeneousCluster",
                "instance_type": "ml.g4dn.xlarge",
                "hosts": [
                    "algo-1"
                ]
            }
        ],
        "network_interface_name": "eth0"
    },
    "user_entry_point": "train.py"
}
Environment variables:
SM_HOSTS=["algo-1"]
SM_NETWORK_INTERFACE_NAME=eth0
SM_HPS={"batch-size":8,"cfg":"yolov5s.yaml","data":"coco128.yaml","epochs":3,"project":"/opt/ml/model"}
SM_USER_ENTRY_POINT=train.py
SM_FRAMEWORK_PARAMS={}
SM_RESOURCE_CONFIG={"current_group_name":"homogeneousCluster","current_host":"algo-1","current_instance_type":"ml.g4dn.xlarge","hosts":["algo-1"],"instance_groups":[{"hosts":["algo-1"],"instance_group_name":"homogeneousCluster","instance_type":"ml.g4dn.xlarge"}],"network_interface_name":"eth0"}
SM_INPUT_DATA_CONFIG={}
SM_OUTPUT_DATA_DIR=/opt/ml/output/data
SM_CHANNELS=[]
SM_CURRENT_HOST=algo-1
SM_CURRENT_INSTANCE_TYPE=ml.g4dn.xlarge
SM_CURRENT_INSTANCE_GROUP=homogeneousCluster
SM_CURRENT_INSTANCE_GROUP_HOSTS=["algo-1"]
SM_INSTANCE_GROUPS=["homogeneousCluster"]
SM_INSTANCE_GROUPS_DICT={"homogeneousCluster":{"hosts":["algo-1"],"instance_group_name":"homogeneousCluster","instance_type":"ml.g4dn.xlarge"}}
SM_DISTRIBUTION_INSTANCE_GROUPS=[]
SM_IS_HETERO=false
SM_MODULE_NAME=train
SM_LOG_LEVEL=20
SM_FRAMEWORK_MODULE=sagemaker_pytorch_container.training:main
SM_INPUT_DIR=/opt/ml/input
SM_INPUT_CONFIG_DIR=/opt/ml/input/config
SM_OUTPUT_DIR=/opt/ml/output
SM_NUM_CPUS=4
SM_NUM_GPUS=1
SM_NUM_NEURONS=0
SM_MODEL_DIR=/opt/ml/model
SM_MODULE_DIR=s3://####################/sagemaker-2023-06-30-08-49-38-688/source/sourcedir.tar.gz
SM_TRAINING_ENV={"additional_framework_parameters":{},"channel_input_dirs":{},"current_host":"algo-1","current_instance_group":"homogeneousCluster","current_instance_group_hosts":["algo-1"],"current_instance_type":"ml.g4dn.xlarge","distribution_hosts":[],"distribution_instance_groups":[],"framework_module":"sagemaker_pytorch_container.training:main","hosts":["algo-1"],"hyperparameters":{"batch-size":8,"cfg":"yolov5s.yaml","data":"coco128.yaml","epochs":3,"project":"/opt/ml/model"},"input_config_dir":"/opt/ml/input/config","input_data_config":{},"input_dir":"/opt/ml/input","instance_groups":["homogeneousCluster"],"instance_groups_dict":{"homogeneousCluster":{"hosts":["algo-1"],"instance_group_name":"homogeneousCluster","instance_type":"ml.g4dn.xlarge"}},"is_hetero":false,"is_master":true,"is_modelparallel_enabled":null,"is_smddpmprun_installed":true,"job_name":"sagemaker-2023-06-30-08-49-38-688","log_level":20,"master_hostname":"algo-1","model_dir":"/opt/ml/model","module_dir":"s3://####################/sagemaker-2023-06-30-08-49-38-688/source/sourcedir.tar.gz","module_name":"train","network_interface_name":"eth0","num_cpus":4,"num_gpus":1,"num_neurons":0,"output_data_dir":"/opt/ml/output/data","output_dir":"/opt/ml/output","output_intermediate_dir":"/opt/ml/output/intermediate","resource_config":{"current_group_name":"homogeneousCluster","current_host":"algo-1","current_instance_type":"ml.g4dn.xlarge","hosts":["algo-1"],"instance_groups":[{"hosts":["algo-1"],"instance_group_name":"homogeneousCluster","instance_type":"ml.g4dn.xlarge"}],"network_interface_name":"eth0"},"user_entry_point":"train.py"}
SM_USER_ARGS=["--batch-size","8","--cfg","yolov5s.yaml","--data","coco128.yaml","--epochs","3","--project","/opt/ml/model"]
SM_OUTPUT_INTERMEDIATE_DIR=/opt/ml/output/intermediate
SM_HP_BATCH-SIZE=8
SM_HP_CFG=yolov5s.yaml
SM_HP_DATA=coco128.yaml
SM_HP_EPOCHS=3
SM_HP_PROJECT=/opt/ml/model
PYTHONPATH=/opt/ml/code:/opt/conda/bin:/opt/conda/lib/python310.zip:/opt/conda/lib/python3.10:/opt/conda/lib/python3.10/lib-dynload:/opt/conda/lib/python3.10/site-packages
Invoking script with the following command:
/opt/conda/bin/python3.10 train.py --batch-size 8 --cfg yolov5s.yaml --data coco128.yaml --epochs 3 --project /opt/ml/model
2023-06-30 08:57:11,040 sagemaker-training-toolkit INFO     Exceptions not imported for SageMaker TF as Tensorflow is not installed.
#033[34m#033[1mtrain: #033[0mweights=yolov5s.pt, cfg=yolov5s.yaml, data=coco128.yaml, hyp=data/hyps/hyp.scratch-low.yaml, epochs=3, batch_size=8, imgsz=640, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, bucket=, cache=None, image_weights=False, device=, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=8, project=/opt/ml/model, name=exp, exist_ok=False, quad=False, cos_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, seed=0, local_rank=-1, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest
#033[34m#033[1mgithub: #033[0mup to date with https://github.com/ultralytics/yolov5 ✅
YOLOv5 🚀 v7.0-187-g0004c74 Python-3.10.8 torch-2.0.0 CUDA:0 (Tesla T4, 15102MiB)
#033[34m#033[1mhyperparameters: #033[0mlr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0
#033[34m#033[1mComet: #033[0mrun 'pip install comet_ml' to automatically track and visualize YOLOv5 🚀 runs in Comet
#033[34m#033[1mTensorBoard: #033[0mStart with 'tensorboard --logdir /opt/ml/model', view at http://localhost:6006/
Dataset not found ⚠️, missing paths ['/opt/ml/datasets/coco128/images/train2017']
Downloading https://ultralytics.com/assets/coco128.zip to coco128.zip...
0%|          | 0.00/6.66M [00:00<?, ?B/s]
100%|██████████| 6.66M/6.66M [00:00<00:00, 258MB/s]
Dataset download success ✅ (0.8s), saved to #033[1m/opt/ml/datasets#033[0m
Downloading https://ultralytics.com/assets/Arial.ttf to /root/.config/Ultralytics/Arial.ttf...
0%|          | 0.00/755k [00:00<?, ?B/s]
100%|██████████| 755k/755k [00:00<00:00, 43.8MB/s]
Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to yolov5s.pt...
0%|          | 0.00/14.1M [00:00<?, ?B/s]
4%|▍         | 560k/14.1M [00:00<00:02, 5.63MB/s]
8%|▊         | 1.09M/14.1M [00:00<00:02, 5.60MB/s]
12%|█▏        | 1.62M/14.1M [00:00<00:02, 5.61MB/s]
17%|█▋        | 2.38M/14.1M [00:00<00:01, 6.49MB/s]
27%|██▋       | 3.80M/14.1M [00:00<00:01, 9.51MB/s]
37%|███▋      | 5.18M/14.1M [00:00<00:00, 10.8MB/s]
54%|█████▍    | 7.69M/14.1M [00:00<00:00, 15.7MB/s]
67%|██████▋   | 9.48M/14.1M [00:00<00:00, 16.6MB/s]
84%|████████▍ | 11.8M/14.1M [00:00<00:00, 19.1MB/s]
97%|█████████▋| 13.7M/14.1M [00:01<00:00, 18.8MB/s]
100%|██████████| 14.1M/14.1M [00:01<00:00, 14.1MB/s]
from  n    params  module                                  arguments
0                -1  1      3520  models.common.Conv                      [3, 32, 6, 2, 2]
1                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]
2                -1  1     18816  models.common.C3                        [64, 64, 1]
3                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]
4                -1  2    115712  models.common.C3                        [128, 128, 2]
5                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]
6                -1  3    625152  models.common.C3                        [256, 256, 3]
7                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]
8                -1  1   1182720  models.common.C3                        [512, 512, 1]
9                -1  1    656896  models.common.SPPF                      [512, 512, 5]
10                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]
11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']
12           [-1, 6]  1         0  models.common.Concat                    [1]
13                -1  1    361984  models.common.C3                        [512, 256, 1, False]
14                -1  1     33024  models.common.Conv                      [256, 128, 1, 1]
15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']
16           [-1, 4]  1         0  models.common.Concat                    [1]
17                -1  1     90880  models.common.C3                        [256, 128, 1, False]
18                -1  1    147712  models.common.Conv                      [128, 128, 3, 2]
19          [-1, 14]  1         0  models.common.Concat                    [1]
20                -1  1    296448  models.common.C3                        [256, 256, 1, False]
21                -1  1    590336  models.common.Conv                      [256, 256, 3, 2]
22          [-1, 10]  1         0  models.common.Concat                    [1]
23                -1  1   1182720  models.common.C3                        [512, 512, 1, False]
24      [17, 20, 23]  1    229245  models.yolo.Detect                      [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
YOLOv5s summary: 214 layers, 7235389 parameters, 7235389 gradients, 16.6 GFLOPs
Transferred 348/349 items from yolov5s.pt
#033[34m#033[1mAMP: #033[0mchecks passed ✅
#033[34m#033[1moptimizer:#033[0m SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 60 weight(decay=0.0005), 60 bias
#033[34m#033[1mtrain: #033[0mScanning /opt/ml/datasets/coco128/labels/train2017...:   0%|          | 0/128 [00:00<?, ?it/s]
#033[34m#033[1mtrain: #033[0mScanning /opt/ml/datasets/coco128/labels/train2017... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<00:00, 3075.76it/s]
#033[34m#033[1mtrain: #033[0mNew cache created: /opt/ml/datasets/coco128/labels/train2017.cache
#033[34m#033[1mval: #033[0mScanning /opt/ml/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<?, ?it/s]
#033[34m#033[1mval: #033[0mScanning /opt/ml/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<?, ?it/s]
#033[34m#033[1mAutoAnchor: #033[0m4.27 anchors/target, 0.994 Best Possible Recall (BPR). Current anchors are a good fit to dataset ✅
Plotting labels to /opt/ml/model/exp/labels.jpg...
Image sizes 640 train, 640 val
Using 4 dataloader workers
Logging results to #033[1m/opt/ml/model/exp#033[0m
Starting training for 3 epochs...
Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
0%|          | 0/16 [00:00<?, ?it/s]
0/2      1.72G    0.04263    0.04785    0.02002         84        640:   0%|          | 0/16 [00:00<?, ?it/s]
0/2      1.72G    0.04263    0.04785    0.02002         84        640:   6%|▋         | 1/16 [00:00<00:09,  1.65it/s]
0/2      1.86G    0.04137     0.0532    0.01919         77        640:   6%|▋         | 1/16 [00:00<00:09,  1.65it/s]
0/2      1.86G    0.04137     0.0532    0.01919         77        640:  12%|█▎        | 2/16 [00:00<00:04,  2.91it/s]
0/2      1.86G    0.04399    0.05919    0.01962         86        640:  12%|█▎        | 2/16 [00:00<00:04,  2.91it/s]
0/2      1.86G    0.04399    0.05919    0.01962         86        640:  19%|█▉        | 3/16 [00:00<00:03,  3.75it/s]
0/2      1.86G     0.0457    0.06293    0.01933        123        640:  19%|█▉        | 3/16 [00:01<00:03,  3.75it/s]
0/2      1.86G     0.0457    0.06293    0.01933        123        640:  25%|██▌       | 4/16 [00:01<00:02,  4.25it/s]
0/2      1.86G    0.04631    0.06611    0.01771        115        640:  25%|██▌       | 4/16 [00:01<00:02,  4.25it/s]
0/2      1.86G    0.04631    0.06611    0.01771        115        640:  31%|███▏      | 5/16 [00:01<00:02,  5.16it/s]
0/2      1.86G    0.04695    0.06591    0.01847        114        640:  31%|███▏      | 5/16 [00:01<00:02,  5.16it/s]
0/2      1.86G    0.04695    0.06591    0.01847        114        640:  38%|███▊      | 6/16 [00:01<00:01,  6.04it/s]
0/2      1.86G    0.04622    0.06352    0.01832         78        640:  38%|███▊      | 6/16 [00:01<00:01,  6.04it/s]
0/2      1.86G    0.04622    0.06352    0.01832         78        640:  44%|████▍     | 7/16 [00:01<00:01,  6.84it/s]
0/2      1.86G    0.04573    0.06442      0.018        118        640:  44%|████▍     | 7/16 [00:01<00:01,  6.84it/s]
0/2      1.86G    0.04573    0.06442      0.018        118        640:  50%|█████     | 8/16 [00:01<00:01,  7.43it/s]
0/2      1.86G    0.04537    0.06323    0.01781         76        640:  50%|█████     | 8/16 [00:01<00:01,  7.43it/s]
0/2      1.86G    0.04574    0.06244    0.01824         91        640:  50%|█████     | 8/16 [00:01<00:01,  7.43it/s]
0/2      1.86G    0.04574    0.06244    0.01824         91        640:  62%|██████▎   | 10/16 [00:01<00:00,  8.43it/s]
0/2      1.86G    0.04525    0.06201    0.01792         96        640:  62%|██████▎   | 10/16 [00:01<00:00,  8.43it/s]
0/2      1.86G    0.04521     0.0621    0.01862        103        640:  62%|██████▎   | 10/16 [00:01<00:00,  8.43it/s]
0/2      1.86G    0.04521     0.0621    0.01862        103        640:  75%|███████▌  | 12/16 [00:01<00:00,  8.92it/s]
0/2      1.86G    0.04485    0.06149     0.0183         91        640:  75%|███████▌  | 12/16 [00:02<00:00,  8.92it/s]
0/2      1.86G    0.04482    0.06218    0.01863        116        640:  75%|███████▌  | 12/16 [00:02<00:00,  8.92it/s]
0/2      1.86G    0.04482    0.06218    0.01863        116        640:  88%|████████▊ | 14/16 [00:02<00:00,  9.25it/s]
0/2      1.86G    0.04545    0.06109    0.01889         63        640:  88%|████████▊ | 14/16 [00:02<00:00,  9.25it/s]
0/2      1.86G    0.04523    0.06067    0.01926         82        640:  88%|████████▊ | 14/16 [00:02<00:00,  9.25it/s]
0/2      1.86G    0.04523    0.06067    0.01926         82        640: 100%|██████████| 16/16 [00:02<00:00,  9.50it/s]#015        0/2      1.86G    0.04523    0.06067    0.01926         82        640: 100%|██████████| 16/16 [00:02<00:00,  6.71it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/8 [00:00<?, ?it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  12%|█▎        | 1/8 [00:01<00:08,  1.26s/it]
Class     Images  Instances          P          R      mAP50   mAP50-95:  25%|██▌       | 2/8 [00:01<00:03,  1.67it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  38%|███▊      | 3/8 [00:01<00:02,  2.34it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  50%|█████     | 4/8 [00:01<00:01,  3.15it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  62%|██████▎   | 5/8 [00:01<00:00,  3.84it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  75%|███████▌  | 6/8 [00:02<00:00,  3.89it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  88%|████████▊ | 7/8 [00:02<00:00,  4.17it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:02<00:00,  4.39it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:02<00:00,  3.10it/s]
all        128        929      0.732      0.631      0.718      0.477
Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
0%|          | 0/16 [00:00<?, ?it/s]
1/2      2.19G    0.05467    0.06597    0.02623        109        640:   0%|          | 0/16 [00:00<?, ?it/s]
1/2      2.19G    0.04909     0.0572     0.0236         60        640:   0%|          | 0/16 [00:00<?, ?it/s]
1/2      2.19G    0.04909     0.0572     0.0236         60        640:  12%|█▎        | 2/16 [00:00<00:01, 10.13it/s]
1/2      2.19G    0.04965    0.06586    0.02222        137        640:  12%|█▎        | 2/16 [00:00<00:01, 10.13it/s]
1/2      2.19G    0.04856    0.07264    0.02058        143        640:  12%|█▎        | 2/16 [00:00<00:01, 10.13it/s]
1/2      2.19G    0.04856    0.07264    0.02058        143        640:  25%|██▌       | 4/16 [00:00<00:01, 10.04it/s]
1/2      2.19G    0.04746    0.07102    0.01933         91        640:  25%|██▌       | 4/16 [00:00<00:01, 10.04it/s]
1/2      2.19G    0.04695     0.0708    0.01908         94        640:  25%|██▌       | 4/16 [00:00<00:01, 10.04it/s]
1/2      2.19G    0.04695     0.0708    0.01908         94        640:  38%|███▊      | 6/16 [00:00<00:01,  9.85it/s]
1/2      2.19G    0.04689     0.0724    0.01959        135        640:  38%|███▊      | 6/16 [00:00<00:01,  9.85it/s]
1/2      2.19G    0.04749    0.07476    0.01983        159        640:  38%|███▊      | 6/16 [00:00<00:01,  9.85it/s]
1/2      2.19G    0.04749    0.07476    0.01983        159        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
1/2      2.19G    0.04698    0.07365    0.01919         97        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
1/2      2.19G     0.0468    0.07334    0.01888        109        640:  50%|█████     | 8/16 [00:00<00:00, 10.21it/s]
1/2      2.19G     0.0468    0.07334    0.01888        109        640:  62%|██████▎   | 10/16 [00:00<00:00, 10.03it/s]
1/2      2.19G    0.04633    0.07145      0.019         88        640:  62%|██████▎   | 10/16 [00:01<00:00, 10.03it/s]
1/2      2.19G    0.04585       0.07      0.019         79        640:  62%|██████▎   | 10/16 [00:01<00:00, 10.03it/s]
1/2      2.19G    0.04585       0.07      0.019         79        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.01it/s]
1/2      2.19G    0.04636    0.06949    0.01866        104        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.01it/s]
1/2      2.19G    0.04635    0.06968    0.01835        120        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.01it/s]
1/2      2.19G    0.04635    0.06968    0.01835        120        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.25it/s]
1/2      2.19G    0.04637    0.06777    0.01839         76        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.25it/s]
1/2      2.19G    0.04622    0.06747    0.01825        116        640:  88%|████████▊ | 14/16 [00:01<00:00, 10.25it/s]
1/2      2.19G    0.04622    0.06747    0.01825        116        640: 100%|██████████| 16/16 [00:01<00:00,  8.37it/s]#015        1/2      2.19G    0.04622    0.06747    0.01825        116        640: 100%|██████████| 16/16 [00:01<00:00,  9.33it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/8 [00:00<?, ?it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  12%|█▎        | 1/8 [00:00<00:00,  7.10it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  25%|██▌       | 2/8 [00:00<00:00,  7.13it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  38%|███▊      | 3/8 [00:00<00:00,  6.68it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  50%|█████     | 4/8 [00:00<00:00,  6.66it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  62%|██████▎   | 5/8 [00:00<00:00,  6.84it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  75%|███████▌  | 6/8 [00:00<00:00,  6.74it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  88%|████████▊ | 7/8 [00:01<00:00,  6.84it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:01<00:00,  6.61it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:01<00:00,  6.73it/s]
all        128        929      0.785      0.629      0.738      0.498
Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
0%|          | 0/16 [00:00<?, ?it/s]
2/2       2.2G    0.04802     0.1227    0.01417        195        640:   0%|          | 0/16 [00:00<?, ?it/s]
2/2       2.2G    0.04561    0.08766    0.01594        101        640:   0%|          | 0/16 [00:00<?, ?it/s]
2/2       2.2G    0.04561    0.08766    0.01594        101        640:  12%|█▎        | 2/16 [00:00<00:01,  9.72it/s]
2/2       2.2G    0.04542    0.07617    0.01757         86        640:  12%|█▎        | 2/16 [00:00<00:01,  9.72it/s]
2/2       2.2G    0.04423    0.07265    0.01708         98        640:  12%|█▎        | 2/16 [00:00<00:01,  9.72it/s]
2/2       2.2G    0.04423    0.07265    0.01708         98        640:  25%|██▌       | 4/16 [00:00<00:01, 10.23it/s]
2/2       2.2G    0.04398    0.07078    0.01723        111        640:  25%|██▌       | 4/16 [00:00<00:01, 10.23it/s]
2/2       2.2G    0.04369    0.07246    0.01751        113        640:  25%|██▌       | 4/16 [00:00<00:01, 10.23it/s]
2/2       2.2G    0.04369    0.07246    0.01751        113        640:  38%|███▊      | 6/16 [00:00<00:00, 10.09it/s]
2/2       2.2G    0.04346    0.06956      0.018        102        640:  38%|███▊      | 6/16 [00:00<00:00, 10.09it/s]
2/2       2.2G    0.04342    0.06977    0.01773        118        640:  38%|███▊      | 6/16 [00:00<00:00, 10.09it/s]
2/2       2.2G    0.04342    0.06977    0.01773        118        640:  50%|█████     | 8/16 [00:00<00:00, 10.27it/s]
2/2       2.2G    0.04328    0.06999    0.01823        102        640:  50%|█████     | 8/16 [00:00<00:00, 10.27it/s]
2/2       2.2G    0.04326    0.06942    0.01802        113        640:  50%|█████     | 8/16 [00:00<00:00, 10.27it/s]
2/2       2.2G    0.04326    0.06942    0.01802        113        640:  62%|██████▎   | 10/16 [00:00<00:00, 10.14it/s]
2/2       2.2G    0.04364    0.06832    0.01798        118        640:  62%|██████▎   | 10/16 [00:01<00:00, 10.14it/s]
2/2       2.2G    0.04363    0.06963    0.01759        140        640:  62%|██████▎   | 10/16 [00:01<00:00, 10.14it/s]
2/2       2.2G    0.04363    0.06963    0.01759        140        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.36it/s]
2/2       2.2G    0.04389    0.06915     0.0175        107        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.36it/s]
2/2       2.2G    0.04385     0.0688    0.01785         98        640:  75%|███████▌  | 12/16 [00:01<00:00, 10.36it/s]
2/2       2.2G    0.04385     0.0688    0.01785         98        640:  88%|████████▊ | 14/16 [00:01<00:00,  9.54it/s]
2/2       2.2G    0.04383    0.06737    0.01852         62        640:  88%|████████▊ | 14/16 [00:01<00:00,  9.54it/s]
2/2       2.2G    0.04365    0.06745    0.01911         96        640:  88%|████████▊ | 14/16 [00:01<00:00,  9.54it/s]
2/2       2.2G    0.04365    0.06745    0.01911         96        640: 100%|██████████| 16/16 [00:01<00:00,  8.02it/s]#015        2/2       2.2G    0.04365    0.06745    0.01911         96        640: 100%|██████████| 16/16 [00:01<00:00,  9.14it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/8 [00:00<?, ?it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  12%|█▎        | 1/8 [00:00<00:00,  7.91it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  25%|██▌       | 2/8 [00:00<00:00,  7.70it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  38%|███▊      | 3/8 [00:00<00:00,  7.29it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  50%|█████     | 4/8 [00:00<00:00,  7.22it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  62%|██████▎   | 5/8 [00:00<00:00,  7.08it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  75%|███████▌  | 6/8 [00:00<00:00,  6.85it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  88%|████████▊ | 7/8 [00:01<00:00,  6.53it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:01<00:00,  6.88it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:01<00:00,  7.00it/s]
all        128        929      0.819      0.627      0.747      0.504
3 epochs completed in 0.004 hours.
Optimizer stripped from /opt/ml/model/exp/weights/last.pt, 14.8MB
Optimizer stripped from /opt/ml/model/exp/weights/best.pt, 14.8MB
Validating /opt/ml/model/exp/weights/best.pt...
Fusing layers...
YOLOv5s summary: 157 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs
Class     Images  Instances          P          R      mAP50   mAP50-95:   0%|          | 0/8 [00:00<?, ?it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  12%|█▎        | 1/8 [00:00<00:01,  5.90it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  25%|██▌       | 2/8 [00:00<00:01,  3.32it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  38%|███▊      | 3/8 [00:01<00:01,  2.74it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  50%|█████     | 4/8 [00:01<00:01,  2.66it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  62%|██████▎   | 5/8 [00:01<00:00,  3.31it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  75%|███████▌  | 6/8 [00:01<00:00,  3.88it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95:  88%|████████▊ | 7/8 [00:01<00:00,  4.44it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:02<00:00,  4.97it/s]
Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 8/8 [00:02<00:00,  3.91it/s]
all        128        929      0.819      0.627      0.746      0.503
person        128        254        0.9      0.669      0.807      0.523
bicycle        128          6          1      0.331      0.711      0.427
                   car        128         46      0.859      0.413      0.579      0.243
motorcycle        128          5      0.682        0.8      0.798      0.663
              airplane        128          6      0.979          1      0.995      0.755
                   bus        128          7      0.748      0.714      0.779      0.659
train        128          3          1      0.659      0.863      0.532
truck        128         12      0.664      0.333      0.501      0.242
boat        128          6          1      0.301      0.519      0.252
traffic light        128         14      0.607      0.214      0.377      0.222
stop sign        128          2      0.792          1      0.995      0.772
bench        128          9      0.823       0.52      0.717      0.311
bird        128         16      0.885          1      0.991      0.651
cat        128          4      0.918          1      0.995       0.77
dog        128          9          1      0.653      0.901      0.693
horse        128          2       0.89          1      0.995      0.622
elephant        128         17      0.972      0.882      0.939      0.651
bear        128          1       0.71          1      0.995      0.995
zebra        128          4      0.885          1      0.995       0.93
giraffe        128          9      0.877      0.791      0.962      0.756
backpack        128          6          1      0.562      0.836      0.428
umbrella        128         18       0.79      0.629      0.877      0.529
handbag        128         19      0.959      0.158      0.337      0.188
tie        128          7      0.817      0.645      0.777      0.486
suitcase        128          4      0.866          1      0.995      0.601
frisbee        128          5      0.735        0.8        0.8      0.627
skis        128          1      0.827          1      0.995      0.497
snowboard        128          7       0.85      0.714      0.867      0.544
sports ball        128          6      0.685      0.667      0.668      0.346
kite        128         10      0.835      0.508      0.628       0.22
          baseball bat        128          4      0.521       0.25      0.388      0.171
        baseball glove        128          7      0.763      0.429       0.47      0.276
            skateboard        128          5      0.725       0.54      0.648      0.479
tennis racket        128          7      0.801      0.429      0.559      0.344
                bottle        128         18      0.588      0.333      0.601       0.31
            wine glass        128         16      0.735      0.875       0.89      0.448
                   cup        128         36      0.902      0.667      0.839       0.52
                  fork        128          6          1      0.311      0.439      0.302
                 knife        128         16      0.829      0.625      0.704      0.393
                 spoon        128         22      0.828      0.439      0.637      0.363
                  bowl        128         28          1       0.63      0.763      0.573
                banana        128          1      0.809          1      0.995      0.302
sandwich        128          2          1          0      0.448      0.383
orange        128          4      0.829          1      0.995      0.738
broccoli        128         11      0.824      0.364      0.491      0.356
carrot        128         24      0.685      0.625      0.713      0.487
hot dog        128          2      0.547          1      0.663      0.614
pizza        128          5          1      0.792      0.962       0.77
donut        128         14      0.674          1      0.946      0.799
cake        128          4      0.774          1      0.995      0.846
chair        128         35      0.612      0.632      0.619      0.319
couch        128          6          1      0.646      0.826      0.527
potted plant        128         14      0.903      0.786      0.875      0.508
bed        128          3          1          0      0.863      0.532
          dining table        128         13      0.804      0.317      0.621      0.407
                toilet        128          2      0.857          1      0.995      0.796
                    tv        128          2      0.751          1      0.995      0.796
laptop        128          3          1          0      0.913      0.548
mouse        128          2          1          0     0.0907     0.0454
remote        128          8          1      0.617      0.629      0.513
cell phone        128          8      0.722      0.332      0.453      0.262
microwave        128          3      0.848          1      0.995      0.843
oven        128          5      0.667        0.4       0.43      0.298
sink        128          6      0.272      0.167      0.338      0.252
refrigerator        128          5      0.672        0.8       0.81      0.558
book        128         29      0.749      0.206      0.367      0.168
clock        128          9      0.762      0.778      0.879      0.689
vase        128          2      0.439          1      0.995      0.895
scissors        128          1          1          0      0.166     0.0332
teddy bear        128         21       0.85      0.571      0.788      0.506
toothbrush        128          5      0.826          1      0.995      0.618
Results saved to #033[1m/opt/ml/model/exp#033[0m
2023-06-30 08:57:53,434 sagemaker-training-toolkit INFO     Waiting for the process to finish and give a return code.
2023-06-30 08:57:53,434 sagemaker-training-toolkit INFO     Done waiting for a return code. Received 0 from exiting process.
2023-06-30 08:57:53,435 sagemaker-training-toolkit INFO     Reporting training SUCCESS

2023-06-30 08:58:07 Uploading - Uploading generated training model
2023-06-30 08:58:07 Completed - Training job completed
Training seconds: 427
Billable seconds: 427

 

 

기계 학습 완료 후 저장된 모델 파일 및 경로를 확인합니다.

 

 

기계 학습이 완료되어 저장된 모델 파일은 SageMaker의 기본 S3 버킷 경로에 생성되며 output 디렉토리의 model.tar.gz 이름으로 생성됩니다. 이제 생성된 모델을 통해 AI(인공지능) 분야에서 사용하기길 바랍니다!

 

 

SageMaker에서 Studio의 Jupyter Notebook 파일(ipynb)을 통해 간단히 기계 학습을 완료하였습니다.
이제 기계 학습 시 사용할 라이브러리, 모델, 학습 데이터 등을 설정 후 원하는 기계 학습 환경을 구성해보시기 바랍니다.

 

 

 

지금까지 SageMaker에서 PyTorch를 활용한 기계 학습 환경을 구축하는 작업을 알아보는 시간이었습니다....! 끝...!

 

 

유익하게 보셨다면 공감을 눌러주고, 댓글로 의견을 공유해 남겨주시면 감사하겠습니다!

 

 

 

[Reference]

 

 

 

[Jenkins] Window Nodes 추가 및 연동하기

Jenkins에서는 도커 컨테이너를 통해 다양한 환경에서의 빌드 및 배포 작업을 진핼할 수 있습니다.
하지만 Host OS가 Linux인 Jenkins 서버에서는 Window OS에서만 할 수 있는 작업에는 제한이 있는데요.
Host OS가 Linux인 Jenkins 서버에서 Window 관련 작업을 진행하기 위한 Window Nodes 추가 및 연동하는 작업을 진행해 보겠습니다.

 

 


Nodes 설정 추가

Dashboard -> Jenkins 관리 -> Nodes 메뉴에서 Nodes 관련 설정을 관리할 수 있습니다.

 

기본적으로 Jenkins 서버를 설치하면 Host OS에 맞는 기본 Nodes가 Built-In Node 이름으로 생성되어 있습니다.
Window Nodes를 신규 추가할 것이므로 New Node를 클릭하여 Nodes 설정을 추가합니다.

 

 

Nodes Name을 입력 후 Type은 Permanent Agent를 선택합니다.


Permanent Agent는 Jenkins 마스터 서버와 연결되어 지속적으로 사용 가능한 에이전트(또는 슬레이브)를 할당하는 것을 의미합니다.

 

 

Number of executors 값은 Nodes에서 수행할 수 있는 동시 빌드 작업 수를 정의합니다.


Remote root directory 값은 Nodes에서 사용할 작업 디렉토리를 지정하며, 작업 디렉토리는 설정한 값과 동일하게 Window Nodes에 추가해야됩니다.

 

 

Labels 값은 여러 에이전트를 그룹화하고 Pipeline에서 에이전트를 선택 시 사용하는 값입니다.


Usage 값은 빌드 작업에 대한 방법을 제어하며 Only build jobs with label expressions matching this node 값을 선택합니다. 레이블 표현식이 있는 작업만 빌드 시 사용하겠다는 것을 의미합니다.

 

 

Nodes 설정 추가 작업을 완료하면 아래와 같이 추가된 Nodes 정보를 확인하실 수 있습니다.

 

 


Nodes 연결

Nodes 설정을 추가하였으니 이제 Window에서 Nodes를 연결하도록 설정해보겠습니다.
Nodes 이름을 클릭하면 아래와 같이 Nodes 연결을 위한 agent.jar 파일 다운로드와 연결 명령어가 정리되어 있습니다.

 

 

이제 Window OS에 접속하여 해당 명령어를 입력하여 agent.jar 파일 다운로드 후 jenkins의 Nodes로 연결합니다.

 

 

연결이 완료되면 Nodes 관리 페이지에서도 해당 Nodes의 상태에 X 표시가 사라지고 정상적으로 연결됨을 확인하실 수 있습니다.

 

 


Nodes 사용

이제 Jenkins Pipeline에서 설정한 Nodes를 사용하도록 설정해보겠습니다.


Pipeline에서는 Nodes 생성 시 설정한 Labels 값을 통해 Nodes를 지정하고 빌드 시 사용할 수 있습니다.

stage('window-agent-stage') {
  agent {
    // Nodes 생성 시 설정한 label 값
    label 'windows'
  }
  steps {
    // 명령어 입력
    bat '''
      bat 'dir /b
    '''
  }
}

 

 

agent { label 'windows' } agent 옵션을 사용하여 Nodes 생성 시 설정한 Labels 값을 지정하였습니다.
이제 Jenkins의 Pipeline이 동작할 경우 해당 Stage에서는 Nodes를 통해 연결된 Window OS 환경에서 명령어를 실행하여 빌드 시 사용할 수 있게 되었습니다.

 

 

Jenkins를 Window OS 환경에서 설치하여 사용할 경우 위와 같은 작업은 필요 없지만,

Linux OS 환경에 설치된 Jenkins에서 Window OS 환경 작업이 필요한 경우,

Window OS 환경에 설치된 Jenkins에서 Linux OS 환경 작업이 필요한 경우,

Nodes 추가 작업으로 작업을 구분하여 빌드 및 배포 작업을 구현할 수 있습니다.

 

 

 

지금까지 Jenkins에서 Window Nodes 추가 및 연동하는 작업을 알아보는 시간이었습니다....! 끝...!

 

 

유익하게 보셨다면 공감을 눌러주고, 댓글로 의견을 공유해 남겨주시면 감사하겠습니다!

 

 

 

[Jenkins] AWS EC2에 컨테이너 배포하기

Jenkins에서 빌드한 컨테이너 이미지를 EC2에 배포하는 작업을 진행해보겠습니다.
사전에 컨테이너 빌드 작업 완료 후 AWS ECR(Elastic Container Registry)에 업로드하는 작업을 생성해둔 상태입니다.

 

 


플러그인 설치

우선 Jenkins에서 빌드한 컨테이너 이미지를 EC2에 배포하기 위해서는 SSH 접속을 통한 접근이 필요한데요.
Jenkins에서 EC2에 SSH 접속을 하기 위해서는 플러그인을 설치해야됩니다.


설치해야되는 플러그인은 SSH Agent Plugin 입니다.

 

 


SSH Key 발급 및 적용

SSH 접속은 Key를 통해 접속하므로 Key 발급 및 적용 작업을 진행합니다.

 

SSH Key 발급

ssh-keygen 명령어를 통해 개인키(id_rsa)와 공개키(id_rsa.pub)를 발급합니다.

 

EC2 공개키(id_rsa.pub) 적용

발급한 키 중 공개키(id_rsa.pub)를 배포하고자 하는 EC2에 적용합니다.
적용하고자 하는 접속 계정의 ~/.ssh/authorized_keys 파일에 공개키를 복사합니다.

### ssh-copy-id 명령어로 복사
ssh-copy-id {HOSTNAME}@{IP}
EX) ssh-copy-id ec2-user@10.1.1,1

### cat 명령어로 복사
cat .ssh/id_rsa.pub >> .ssh/authorized_keys

### vi로 파일 내용 추가
vi .ssh/authorized_keys
key 값 복사

 

EC2 서버로 직접 접속하여 공개키(id_rsa.pub)가 정상적으로 적용되었는지 확인합니다.

cat .ssh/authorized_keys
ssh-rsa ##############################################################################
######################################################################################
################################### root@ip-10-1-1-205.ap-northeast-2.compute.internal

 

 


Jenkins 개인키(id_rsa) 적용

SSH Agent를 통해 EC2를 접속하기 위해 사전에 발급한 SSH Key 중 개인키(id_rsa)를 Credentials로 등록합니다.


개인키(id_rsa)는 Dashboard -> Jenkins 관리 -> Credentials 메뉴에서 등록합니다.

 

 

Credentials 발급 시 Kind는 SSH Username with private key를 선택합니다.
사용하고자 하는 ID와 Username을 지정합니다.

 

 

Private Key 값은 Enter directly 버튼을 클릭하여 직접 개인키(id_rsa)를 입력할 수 있도록 합니다.
개인키(id_rsa)를 Key에 입력 후 Create 버튼을 클릭하여 Credentials 등록을 완료합니다.

 

 


Jenkins Pipeline 설정

SSH Agent 플러그인을 사용하여 사전에 등록한 Credentials을 통해 EC2 접속 및 배포 작업을 진행해보도록 하겠습니다.

stage('deploy-EC2') {
  steps {
    //SSH Agent 플러그인을 사용하여 사전에 등록한 Credentials 지정
    sshagent (credentials: ['EC2_ACCESS_KEY_ID']) {
      sh """
        ### ssh 명령어로 EC2 서버 지정
        ssh -o StrictHostKeyChecking=no ${EC2_USER}@${EC2_IP} '
          ### 실행할 명령어 입력        
          cd ${WORK_DIR}
          docker compose down
          docker pull ${AWS_ECR}/${IMAGE_NAME}:${IMAGE_TAG}
          docker compose up -d
          exit
        '
      """
    }
  }
}

 

  1. sshagent() 구분을 통해 SSH Agent 플러그인을 사용할 수 있도록 지정합니다.
  2. credentials:[] 값에는 사전에 등록한 Credentials을 지정합니다.
  3. ssh 명령어로 접속 및 배포하고자 하는 EC2 서버를 지정합니다.
  4. 실행할 명령어를 입력합니다.
    • 작업 디렉토리 이동
    • 도커 컨테이너 종료
    • 도커 컨테이너 이미지 다운로드
    • 도커 컨테이너 시작

 

위 작업을 통해 Jenkins에서 EC2 접속 및 배포 작업을 진행할 수 있습니다.

실행할 명령어에 따라 배포 작업을 진행하거나, 테스트, 모니터링 등 다양한 작업을 할 수도 있습니다.

 

 

지금까지 Jenkins에서 빌드한 컨테이너 이미지를 EC2에 배포하는 작업을 알아보는 시간이었습니다....! 끝...!

 

 

유익하게 보셨다면 공감을 눌러주고, 댓글로 의견을 공유해 남겨주시면 감사하겠습니다!

 

 

 

[Reference]

 

 

[Docker] error: could not create a builder instance with TLS data loaded from environment 에러 해결 방법

 

아래 docker buildx 명령어 사용 시 에러가 발생하였는데요.

$ docker buildx create --name multiple-arch-builder --use
error: could not create a builder instance with TLS data loaded from environment. Please use `docker context create <context-name>` to create a context for current environment and then create a builder instance with `docker buildx create <context-name>`

 

해당 에러는 docker Buildx 명령어를 사용하여 도커 이미지를 빌드하려고 할 때 발생할 수 있는 문제이며,
TLS 데이터를 환경에서 로드하는 동안 빌더 인스턴스를 생성할 수 없다는 것을 나타냅니다.

 

 

해당 에러를 해결하기 위해서는 docker context create <context-name> 명령을 사용하여 도커 컨텍스트를 생성하고, docker buildx create <context-name> 명령어을 사용하여 도커 컨텍스트를 지정한 후 빌더 인스턴스를 생성해야 TLS 설정과 같은 인증 정보를 제공하면서 에러가 발생하지 않습니다.

 

 

아래와 같이 로직을 수정하면서 해당 에러를 해결하였습니다.

# 도커 컨텍스트 생성
$ docker context create multiple-arch-context
Successfully created context "multiple-arch-context"
multiple-arch-context

# 빌더 인스턴스를 생성 시 도커 컨텍스트 지정
$ docker buildx create multiple-arch-context --name multiple-arch-builder --use
multiple-arch-builder

 

 

지금까지 docker buildx 명령어 사용 시 에러 확인 및 해결 방법에 대해 알아보는 시간이었습니다....! 끝...!

 

 

유익하게 보셨다면 공감을 눌러주고, 댓글로 의견을 공유해 남겨주시면 감사하겠습니다!

'Docker' 카테고리의 다른 글

[Docker] Network 설정  (0) 2022.12.01
[Docker] Logging 설정  (0) 2022.11.07
[Docker] Syslog 서버 구축  (0) 2022.11.01
[Docker] Healthcheck 설정을 통한 컨테이너 상태 점검  (0) 2022.10.19
[Docker] Volumes 설정  (0) 2022.10.11

[AWS] Amazon Elastic Container Registry 알아보기

요즘 IT 업계에서는 테스트 환경, 개발 환경, 서비스 환경 등을 도커 컨테이너를 통해 많이 구현하고 사용하고 있습니다.
이런 도커 컨테이너의 이미지를 관리하기 위해서는 컨테이너 레지스트리를 통해 업로드 및 다운로드하여 사용하고 있는데요. 그 중 가장 많이 사용하고 대표적인 Docker Hub가 있지만 오늘은 Amazon에서 제공하는 Elastic Container Registry(ECR) 서비스에 대해 알아보고자 합니다.

 

 


개요

Amazon Elastic Container Registry (ECR)은 AWS에서 제공하는 관리형 도커 컨테이너 이미지 저장소입니다.


사용자(개발자)들은 ECR을 사용하여 컨테이너 이미지를 안전하게 저장하고 관리할 수 있는데요. ECR은 AWS에서 제공하는 EC2 인스턴스, ECS 클러스터, EKS 클러스터, AWS Fargate 등과 함께 사용할 수 있으며, 이를 통해 개발자들은 ECR에 저장된 컨테이너 이미지를 손쉽게 배포하고 실행할 수 있습니다.

 

 


기능

 

작동 방식

Amazon Elastic Container Registry (ECR)는 사용자가 도커 컨테이너 이미지를 안정적으로 관리하고 배포할 수 있도록 지원하고 있으며, AWS에서 제공하는 다양한 환경 및 On premises 에서 사용할 수 있습니다.

 

상세 기능

Amazon Elastic Container Registry (ECR)의 상세 기능을 정리해봤습니다.

 

  • 컨테이너 이미지 저장 및 관리
    • ECR은 도커 컨테이너 이미지를 중앙 집중화된 저장소에 안전하게 저장하고 관리합니다.
    • 이미지를 ECR에 업로드하여 버전 관리, 보안 및 접근 제어를 적용할 수 있습니다.
  • 보안 및 액세스 제어
    • ECR은 AWS Identity and Access Management (IAM)을 사용하여 액세스 제어를 구현합니다.
    • 사용자는 이미지에 대한 액세스 권한을 정교하게 구성하여 필요한 보안 수준을 유지할 수 있습니다.
  • 통합 및 배포
    • ECR은 다른 AWS에서 제공하는 다양한 서비스 및 환경과 통합되서 사용할 수 있습니다.
    • 예를 들어, EC2 인스턴스, ECS 클러스터, EKS 클러스터, AWS Fargate 등과 함께 사용하여 컨테이너 이미지를 배포하고 실행할 수 있습니다.
  • 이미지 레지스트리 및 태그 관리
    • ECR은 이미지 레지스트리를 제공하여 개발자가 이미지를 조직적으로 구성할 수 있도록 합니다.
    • 또한, 이미지에 태그를 할당하여 버전 관리를 용이하게 할 수 있습니다. 태그를 사용하여 특정 버전의 이미지를 식별하고 추적할 수 있습니다.
  • 이미지 스캔 및 취약점 관리
    • ECR은 컨테이너 이미지를 스캔하고 보안 취약점을 검출할 수 있습니다.
    • 이를 통해 개발자는 이미지의 보안 수준을 유지하고 취약점을 해결할 수 있습니다.
  • 확장성 및 신뢰성
    • ECR은 AWS의 글로벌 인프라스트럭처를 기반으로 하며, 안정적이고 확장 가능한 서비스입니다.
    • 개발자는 필요에 따라 컨테이너 이미지의 저장 용량을 증가시킬 수 있으며, 고가용성과 신뢰성을 보장합니다.

 

 

저는 여러 기능 중 이미지 스캔 및 취약점 관리 기능이 가장 좋다고 생각했는데요.
Private Docker Container Registry를 구축하거나 Docker Hub을 사용한다면 보안 취약점 부분은 쉽게 놓치고 갈 수 있기 때문에 꼭 필요한 기능이라고 생각됩니다.

 

 


요금

Amazon Elastic Container Registry (ECR)의 요금 정보를 정리해봤습니다.

 

 

기본적으로 요금은 데이터 저장 용량과 데이터 전송 용량에 따라 계산되는데요.
데이터 저장 용량은 월 기준 10GB 당 1 USD로 모든 리전에서 동일한 것으로 확인됩니다.

 

 

데이터 전송 용량은 도커 컨테이너 이미지를 업로드하는 경우에는 무료이며, 인터넷 환경이나 다른 리전에서 도커 컨테이너 이미지를 다운로드하는 경우에는 사용량에 따라 요금이 측정됩니다. 같은 리전은 무료이며 리전에 따라 요금은 조금 다른 것으로 확인되며 아래 사진을 통해 추가적인 정보를 확인해보시면 좋을 것 같습니다.

 

 


활용

Amazon Elastic Container Registry (ECR)를 활용하는 방법입니다.


우선 위에서 설명해드린 내용으로 단순하게 도커 컨테이너 이미지를 저장하여 관리할 뿐만 아니라 버전관리, 액세스 제어, 이미지 스캔 및 보안 취약점 점검, 확장 등 다양한 기능을 활용해보실 수 있습니다.

 

실제 도커 컨테이너 이미지를 관리해야 되는 상황이라면 어떤 컨테이너 레지스트리 서비스를 사용할지 고민이 되실 겁니다. 제 개인적인 의견으로는 AWS Cloud 환경에서 서비스를 배포하거나 개발 환경이 있다면 Amazon ECR을 활용하면 좋을 것 같고, 그렇지 않다면 그 외의 Container Registry 서비스를 찾아보시고 비교해보신 다음 사용하시는 것도 좋을 것 같습니다.

 


그 외의 Container Registry 서비스

Amazon Elastic Container Registry (ECR) 외의 다른 Container Registry 서비스를 단간히 알아보겠습니다.

 

 

가장 널리 알려진 오픈 소스 컨테이너 레지스트트리인 Docker Hub부터,
Google에서 제공하는 Google Container Registry,
Azure에서 제공하는 Azure Container Registry,
네이버에서 제공하는 Naver Cloud Container Registry 등이 있습니다.

 

각각의 Container Registry 서비스마다 기능, 특징, 요금이 다르므로
사용하고자하는 환경에 맞는 Container Registry를 선택 후 사용하시기 바랍니다.

 

 

 

지금까지 Amazon의 Elastic Container Registry를 알아보는 시간이었습니다....! 끝...!

 

 

유익하게 보셨다면 공감을 눌러주고, 댓글로 의견을 공유해 남겨주시면 감사하겠습니다!

 

 

 

[Reference]

 

 

'AWS' 카테고리의 다른 글

[AWS] AWS Direct Connect 알아보기  (0) 2023.07.12
[AWS] Amazon SNS 알아보기  (0) 2023.07.11
[AWS] Insufficient capacity error 에러  (0) 2023.05.23
[AWS] Service Quota 알아보기  (0) 2023.05.22
[AWS] AWS Summit Seoul 2023 2일차  (0) 2023.05.04

+ Recent posts