

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# SageMaker AI 객체 감지 - TensorFlow 알고리즘 사용 방법
<a name="object-detection-tensorflow-how-to-use"></a>

객체 감지 - TensorFlow를 Amazon SageMaker AI 기본 제공 알고리즘으로 사용할 수 있습니다. 다음 섹션에서는 SageMaker AI Python SDK로 객체 감지 - TensorFlow를 사용하는 방법을 설명합니다. Amazon SageMaker Studio Classic UI에서 객체 감지 - TensorFlow를 사용하는 방법에 대한 자세한 내용은 [SageMaker JumpStart 사전 훈련된 모델](studio-jumpstart.md) 섹션을 참조하세요.

객체 감지 - TensorFlow 알고리즘은 호환 가능하며 사전 훈련된 TensorFlow 모델 중 무엇이든 사용하여 전이 학습을 지원합니다. 사전 훈련된 모든 가용 모델의 목록은 [TensorFlow 모델](object-detection-tensorflow-Models.md)를 참조하세요. 모든 사전 훈련 모델에는 고유의 `model_id`가 있습니다. 다음 예제에서는 ResNet50(`model_id`: `tensorflow-od1-ssd-resnet50-v1-fpn-640x640-coco17-tpu-8`)을 이용하여 사용자 지정 데이터세트를 미세 조정합니다. 사전 훈련 모델 모두 TensorFlow Hub에서 사전 다운로드되고 Amazon S3 버킷에 저장됩니다. 따라서 훈련 작업을 네트워크 격리 상태에서 실행할 수 있습니다. 이처럼 사전 생성된 모델 훈련 아티팩트를 사용하여 SageMaker AI Estimator를 구문화합니다.

먼저 도커 이미지 URI, 훈련 스크립트 URI, 사전 훈련 모델 URI를 검색하세요. 그런 다음 상황에 맞게 하이퍼파라미터를 변경하세요. `hyperparameters.retrieve_default`를 사용하면 모든 가용 하이퍼파라미터와 해당 하이퍼파라미터의 기본값으로 구성된 Python 사전을 볼 수 있습니다. 자세한 내용은 [객체 감지 - TensorFlow 하이퍼파라미터](object-detection-tensorflow-Hyperparameter.md) 단원을 참조하십시오. 이 값들을 사용하여 SageMaker AI Estimator를 구문화합니다.

**참고**  
기본 하이퍼파라미터 값은 모델마다 다릅니다. 그 예로 대형 모델일수록 기본 에포크 수가 적습니다.

이 예제에서는 거리의 보행자가 담긴 이미지를 포함하는 [https://www.cis.upenn.edu/~jshi/ped_html/#pub1](https://www.cis.upenn.edu/~jshi/ped_html/#pub1) 데이터세트를 사용합니다. 데이터세트를 사전 다운로드하여 Amazon S3로 사용할 수 있도록 설정했습니다. 모델을 미세 조정하려면 훈련 데이터세트의 Amazon S3 위치를 이용하여 `.fit`를 호출하세요.

```
from sagemaker import image_uris, model_uris, script_uris, hyperparameters
from sagemaker.estimator import Estimator

model_id, model_version = "tensorflow-od1-ssd-resnet50-v1-fpn-640x640-coco17-tpu-8", "*"
training_instance_type = "ml.p3.2xlarge"

# Retrieve the Docker image
train_image_uri = image_uris.retrieve(model_id=model_id,model_version=model_version,image_scope="training",instance_type=training_instance_type,region=None,framework=None)

# Retrieve the training script
train_source_uri = script_uris.retrieve(model_id=model_id, model_version=model_version, script_scope="training")

# Retrieve the pretrained model tarball for transfer learning
train_model_uri = model_uris.retrieve(model_id=model_id, model_version=model_version, model_scope="training")

# Retrieve the default hyperparameters for fine-tuning the model
hyperparameters = hyperparameters.retrieve_default(model_id=model_id, model_version=model_version)

# [Optional] Override default hyperparameters with custom values
hyperparameters["epochs"] = "5"

# Sample training data is available in this bucket
training_data_bucket = f"jumpstart-cache-prod-{aws_region}"
training_data_prefix = "training-datasets/PennFudanPed_COCO_format/"

training_dataset_s3_path = f"s3://{training_data_bucket}/{training_data_prefix}"

output_bucket = sess.default_bucket()
output_prefix = "jumpstart-example-od-training"
s3_output_location = f"s3://{output_bucket}/{output_prefix}/output"

# Create an Estimator instance
tf_od_estimator = Estimator(
    role=aws_role,
    image_uri=train_image_uri,
    source_dir=train_source_uri,
    model_uri=train_model_uri,
    entry_point="transfer_learning.py",
    instance_count=1,
    instance_type=training_instance_type,
    max_run=360000,
    hyperparameters=hyperparameters,
    output_path=s3_output_location,
)

# Launch a training job
tf_od_estimator.fit({"training": training_dataset_s3_path}, logs=True)
```

사용자 지정 데이터세트에서의 전이 학습을 위한 SageMaker AI 객체 감지 - TensorFlow 알고리즘을 사용하는 방법에 대한 자세한 내용은 [Introduction to SageMaker TensorFlow - Object Detection](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/object_detection_tensorflow/Amazon_Tensorflow_Object_Detection.ipynb) 노트북을 참조하세요.