iOS/Framework

Core ML - Converting Trained Models to Core ML 번역

DevBabamba 2017. 12. 27. 01:21
반응형


※의역 오역 많습니다. 참고하시고 보세요~

원문: https://developer.apple.com/documentation/coreml/converting_trained_models_to_core_ml


Converting Trained Models to Core ML

  • 서드파티 머신러닝 툴로 생성된 학습된 모델을 Core ML 모델 포멧으로 컨버팅

Overview

  • 지원되는 서드파티 머신러닝 툴로 모델이 생성되고 훈련된 경우, Core ML 모델 포멧으로 컨버팅하기 위해 Core ML Tools를 사용할 수 있다.

  • 표 1은 지원되는 모델과 서드 파티툴의 목록이다.

Core ML Tools은 Python Package Index(PyPI)로 호스팅된 Python 패키지(coremltools)이다. Python 패키지 정보는 Python Packaging User Guide를 확인하라.

표 1 Core ML Tools에 의해 지원되는 모델들과 서드파티 툴

Model typeSupported modelsSupported tools
Neural networksFeedforward, convolutional, recurrentCaffe v1 Keras 1.2.2+
Tree ensemblesRandom forests, boosted trees, decision treesscikit-learn 0.18 XGBoost 0.6
Support vector machinesScalar regression, multiclass classificationscikit-learn 0.18 LIBSVM 3.22
Generalized linear modelsLinear regression, logistic regressionscikit-learn 0.18
Feature engineeringSparse vectorization, dense vectorization, categorical processingscikit-learn 0.18
Pipeline modelsSequentially chained modelsscikit-learn 0.18

Convert Your Model

  • 모델을 모델의 서드파티 툴과 일치하는 Core ML 컨버터를 사용해 컨버팅 한다.
  • 컨버터의 convert 메소드를 호출하고 Core ML 모델 포멧(.mlmodel)으로 결과 모델을 저장한다.
  • 예를 들면, Caffe를 사용하여 모델이 생성되었다면, coremltools.converters.caffe.convert 메소드로 Caffe(.caffemodel) 모델을 전달한다.
import coremltools
coreml_model = coremltools.converters.caffe.convert('my_caffe_model.caffemodel')
  • Core ML model 포멧으로 결과 모델을 저장한다.
coremltools.utils.save_spec(coreml_model, 'my_model.mlmodel')
  • 모델에 따라 input, output, 그리고 label을 업데이트가 필요하거나 image names, types 그리고 formats을 선언할 필요한 경우가 있다.
  • 사용가능한 옵션들은 툴마다 다르기 때문에, 변환 툴들은 자세한 문서와 번들로 제공된다.
  • Core ML Tools에 대한 자세한 정보는, Package Documentation을 확인하라.

Alternatively, Write a Custom Conversion Tool

  • 표 1에 열거된 툴들에 의해 지원되는 포멧이 아닌 모델을 컨버팅하려는 때 자신만의 conversion tool로 생성하는것이 가능하다.
  • 자신만의 conversion tool로 작성하려면, 모델의 입력, 출력, 아키텍처 표현을 Core ML 모델 포멧으로 변환하는 것을 포함한다.
  • 모델의 아키텍처의 각 레이어와 다른 레이어의 연결을 정의하는것에 의해 위의 변환을 수행 할 수 있다.
  • Core ML Tools에 의해 제공되는 conversion tools를 예제로 사용하라.
    • Core ML 모델 포멧으로 변환 하는 서드 파티 tool로 생성된 다양한 모델 타입들을 보여준다.

Core ML 모델 포멧은 프로토콜 버퍼 파일들의 세트로 정의 되고 자세한 것은 Core ML Model Specification에 설명되어 있다.


반응형