Skip To Content

예시: 사전 학습된 모델을 사용한 추론

딥러닝을 사용하여 영상에서 수동으로 피처 추출 작업을 자동화할 수 있습니다. ArcGIS Pretrained Models를 사용하면 대용량 데이터셋, 상당한 계산 능력, 딥러닝에 대한 지식이나 전문성이 없어도 문제를 해결할 수 있습니다. 이러한 모델은 다양한 공간 데이터를 기반으로 학습되었으며 여러 지역에서 우수한 성능을 제공합니다. ArcGIS Pretrained Models는 ArcGIS Living Atlas of the World 전반에 걸쳐 ArcGIS 계정이 있는 모든 사용자가 사용할 수 있습니다. 다음 워크플로에서는 Car Detection-USA 모델을 사용하여 고해상도 드론 및 항공영상에서 자동차를 식별합니다.

요구사항

이 워크플로를 수행하려면 다음 요구사항이 필요합니다.

  • 모델을 실행할 항공영상.
    비고:

    자동차가 포함된 항공영상은 OpenAerialMap에서 다운로드할 수 있습니다.

  • 딥러닝은 계산이 복잡하기 때문에 강력한 GPU를 사용하여 대용량 데이터셋을 처리하는 것을 권장합니다.

사전 학습된 모델을 사용한 추론

다음 섹션에서는 ArcGIS Pretrained Models를 사용한 추론과 관련된 프로세스를 설명합니다.

Python 라이브러리 가져오기

다음 Python 라이브러리를 가져옵니다.

from arcgis.gis import GIS
from arcgis.learn import detect_objects
from arcgis.raster.analytics import copy_raster
 
gis = GIS("home")

분석할 데이터 및 모델 추가

Notebook에 데이터셋을 추가하는 데 사용할 수 있는 두 가지 방법이 있습니다.

첫 번째 방법은 항공영상을 Notebook 작업 영역에 업로드하고 코드 셀에 추가한 후 copy_raster() 함수를 실행하여 데이터를 추출하는 방법입니다.

dataset = "/arcgis/home/Aerial imagery.tif"
imagery = copy_raster(input_raster=dataset, output_name="Aerial_imagery", raster_type_name="Raster Dataset")

두 번째 방법은 항공영상을 호스팅 영상 레이어로 포털에 추가하고 해당 itemID를 사용하여 Notebook에 영상 레이어를 추가하는 방법입니다.

imagery = gis.content.get("<imagery-layer-item-id>")

딥러닝 패키지 추가

사전 학습된 Car Detection - USA 모델은 ArcGIS Living Atlas에서 다운로드할 수 있습니다. 모델을 다운로드한 후 포털에 항목으로 추가하고 해당 itemID를 사용하여 Notebook에서 접근할 수 있습니다.

model = gis.content.get("<deep-learning-package-item-id>")

모델 실행

Notebook에서 사전 학습된 모델을 실행하려면 arcgis.learn의 detect_objects 모듈을 사용합니다. 이 모듈은 영상을 입력으로 사용하여 영상에 있는 자동차의 수를 감지하고 계산합니다.

비고:

원하는 결과가 나올 때까지 모델의 인수를 다양한 값으로 증강하여 모델의 성능을 잠재적으로 개선할 수 있습니다.

model_arguments = {
	"padding": "100",	# The number of pixels at the border of image tiles from which predictions are blended for adjacent tiles. To smooth the output while reducing artifacts, increase the value
	"batch_size": "16",	# Change batch size as per GPU specifications
	"threshold": "0.5",	# Get detections greater than 50% confidence
	"tile_size": "224",	# The width and height of image tiles into which the imagery is split for prediction
        }

비고:

GPU가 구성된 경우 detect_object() 메소드 내부에 컨텍스트를 설정하여 GPU 환경으로 설정할 수 있습니다.

context = { "processorType": "GPU" }

num_cars = {}
 
detected_cars = detect_objects(
        input_raster=imagery,
        model = model,
        output_name = "detected_cars",
        )
 
num_cars[imagery.name] = len(detected_cars.query(as_df=True))

모델 결과

마지막으로 모델을 실행한 후에는 num_cars의 결과를 표시할 수 있습니다.

print(f"Number of cars is {num_cars}.")