티스토리 뷰
Integrating a Core ML Model into Your App
Core ML 모델 앱으로 통합하기
* 예제 앱 다운로드 링크
Overview
개요
해당 샘플 앱은 화성의 서식지 가격을 예측하기 위해서 학습된 ML Model인 MarsHabitatPricer.mlmodel을 사용합니다.
Add a Model to Your Xcode Project
모델을 당신의 Xcode Project에 추가하세요
Xcode 프로젝트의 Project Navigator에 모델을 드래그해서 프로젝트 내에 모델을 추가할 수 있습니다.
당신은 Xcode의 모델을 열어서 모델에 대한 정보를 볼 수 있습니다.
ML Model 의 타입, 해당 모델의 예상 입력값과 출력값
해당 샘플 앱에서 사용하는 모델의 입력값, 출력값은 아래와 같습니다.
- 입력값 : 태양전지판(solarPanels)의 수, 온실(greenhouses)의 수, 또한 서식지의 크기(size, 에이커)
- 출력값 : 서식지의 가격(price)
Create the Model in Code
코드로 모델 생성하기
MarsHabitatPricer.mlmodel에 대해서, Xcode는 해당 모델(MarsHabitatPricer), 모델의 입력값(MarsHabitatPricerInput), 모델의 결과값(MarsHabitatPricerInput)을 대표하는 인터페이스를 생성합니다.
모델 생성을 위해 MarsHabitatPricer 클래스의 생성자를 생성하세요.
let model = MarsHabitatPricer()
Get Input Values to Pass to the Model
모델로 전달할 입력값 가져오기
해당 샘플 앱에서는 모델의 입력값을 사용자로부터 받기 위해 ViewController 파일 내에서 UIPickerView를 사용합니다.
Use the Model to Make Predictions
예측을 위해 모델 사용하기
예측된 가격과 해당 결과값에대한 UI 표출을 위해서 marsHabitatPricerOutput 프로퍼티의 price 프로퍼티에 접근합니다.
Note
생성된 prediction(solarPanels:greenhouses:size: 메서드는 error를 throw할 수 있습니다. 입력 상세 값에 대한 예상되는 결과값이 없을 때, 마주칠 수 있는 에러에 대해서 보편적으로 대응할 수 있는 방법이 throw 방식입니다.
Build and Run a Core ML App
Core ML 앱 빌드 및 실행하기
Xcode에서는 현재 기기에서 작동이 최적화 될 수 있는 자원이 되도록 Core ML 모델을 컴파일 합니다. 이렇게 최적화된 모델은 당신의 앱 번들에 포함되며, 이는 앱이 기기에서 돌아가는 동안 예측 처리를 하기 위해 사용되게 됩니다.
그렇게 결과적으로 모델에 입력된 입력값에 따라 반환되는 예측된 결과가 앱에 나오는 화면은 아래와 같습니다.
See Also
First Steps
Converting Trained Models to Core ML
학습된 모델을 CoreML로 변환하기
- 제 3의 머신러닝 모델을 Core ML 모델 포맷으로 변환할 수 있습니다.
Integrating a Core ML Model into Your App | Apple Developer Documentation
Sample Code Integrating a Core ML Model into Your App Add a simple model to an app, pass input data to the model, and process the model’s predictions. Download OverviewThis sample app uses a trained model, MarsHabitatPricer.mlmodel, to predict habitat pr
developer.apple.com
'iOS 개발 > 개발자문서 정보' 카테고리의 다른 글
iOS swift Dictionary, 딕셔너리 값 순회탐색하는 방법 (0) | 2020.06.14 |
---|---|
iOS swift Dictionary, 딕셔너리 값 읽고 쓰고 제거하는 방법 (0) | 2020.06.12 |
iOS앱에 사용할 CoreML Model 얻고 활용하기 (0) | 2020.05.30 |
iOS NLLanguageRecognizer로 문자열 언어 분석하기 (0) | 2020.05.27 |
iOS Vision, VNImageRequestHandler 개발자문서 개요 (0) | 2020.05.24 |
- Total
- Today
- Yesterday
- swift 문자열
- publisher
- 컬렉션
- 부스트코스
- Protocol
- swift
- 자연어처리
- swift알고리즘
- 백준swift
- 프로토콜
- 김프매매
- 알고리즘
- swift언어
- 백준알고리즘
- 프로그래머스swift
- swift 기초
- 스위프트
- swift reduce
- swift문제
- 개발자문서
- Swift 알고리즘
- swift string
- uikit
- SwiftUI
- Collection
- 알고리즘문제
- ios
- CoreML
- 프로그래머스
- createML
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |