<aside> 🔥
가설을 세우고 어디가 문제인지 확인합니다.
</aside>
coremltools로 변환한 .mlpackage 파일을 Xcode에 파일을 옮기면 알아서 컴파일이 되는데 컴파일한 .mlmodelc 파일 내에 manifest.json이 포함되지 않아 모델을 읽는 과정에서 오류가 발생함.
이때, 모델 경로를 불러오는 방법은 Bundle을 이용해서 불러옴. Bundle은 Xcode 프로젝트 내에 json 등 파일들을 저장하는 경로
bundleModelURL = Bundle.main.url(
forResource: modelNameOrPath, withExtension: "mlmodelc")
{
.mlpackage 확장자를 인식함. (이럴거면 왜 .mlmodelc로 컴파일을 하는지 잘 모르겠음)let absolutePath = "/Users/seonjong/workspace/challenge_4/MyModelTest/MyModelTest/mymodel_250727.mlpackage"
if FileManager.default.fileExists(atPath: absolutePath) {
modelURL = URL(fileURLWithPath: absolutePath)
.mlpackage로 변환이 가능할때가 있고 불가능할때가 있음명확한 버전 명시가 안되어 있어서 어떤 버전이 가능한지 확인이 어려움
문제 아님. 여전히 에러 발생

→ 동일한 문제 발생

이건 아닌듯.. 모델 패키지가 동일함. 심지어 createML은 mlmodel이라서 옛날 확장자임
xcrun coremlcompiler compile ./OpenELM-270M-Instruct.mlpackage ./OpenELM-270M-Instruct.modelc
위 명령어로 컴파일하면 아래와 같이 파일이 떨어짐
.
└── OpenELM-270M-Instruct.mlmodelc
├── analytics
│ └── coremldata.bin
├── coremldata.bin
├── metadata.json
├── model.mil
└── weights
└── weight.bin
4 directories, 5 files
여기에 어디에도 Manifest.json이 없음
그런데 Xcode에서는 계속해서 Manifest.json을 찾고 있음. 왜 이러는지 ㄹㅇ 모르겠음
<aside> 🔥
진짜 Apple 좀 맞아야겠다.
</aside>
공식문서를 봅시다.
Creates a Core ML model instance asynchronously from a compiled model file, a custom configuration, and a completion handler.
iOS 14.0+iPadOS 14.0+Mac Catalyst 14.0+macOS 11.0+tvOS 14.0+visionOS 1.0+watchOS 7.0+
class func load(
contentsOf url: [URL](<https://developer.apple.com/documentation/Foundation/URL>),
configuration: [MLModelConfiguration](<https://developer.apple.com/documentation/coreml/mlmodelconfiguration>) = MLModelConfiguration(),
completionHandler handler: @escaping ([Result](<https://developer.apple.com/documentation/Swift/Result>)<[MLModel](<https://developer.apple.com/documentation/coreml/mlmodel>), any [Error](<https://developer.apple.com/documentation/Swift/Error>)>) -> [Void](<https://developer.apple.com/documentation/Swift/Void>)
)
url : The path to a compiled model file (ModelName.mlmodelc), typically with the URL that compileModel(at:) returns.configuration : The runtime settings for the new model instance.handler : A closure the method calls when it finishes loading the model.여기서 공식문서에 URL은 분명히 typically with the URL that compileModel(at:) returns. 라고 적혀있다. 그래서 그렇게 했다.
그런데 위처럼 하면 오히려 에러가 발생한다.
let bundleModelURL = Bundle.main.url(
forResource: modelNameOrPath, withExtension: "mlmodelc")
let compiledModelURL = try await MLModel.compileModel(at: bundleModelURL!)
self.model = try MLModel(contentsOf: compiledModelURL!)
let bundleModelURL = Bundle.main.url(
forResource: modelNameOrPath, withExtension: "mlmodelc")
self.model = try MLModel(contentsOf: modelURL!)
왜 이런 현상이 발생하는지는 잘 모르겠는데 아마 Xcode에서 build할때 이미 mlmodelc로 컴파일이 된 파일이 들어가버려서 굳이 MLModel.compileModel을 할 필요가 없는 것으로 추측된다. 진짜 팀쿡 머리 콕 박아버리고 싶네
⬅️ 이전 페이지
➡️ 다음 페이지
<aside>
</aside>