1

I have a detect_model.mlmodel which is trained by myself. I want to use it in xcode, but I don't wanna to add it into my xcode project manually. I have tried to write CMakeLists.txt to manage my xcode project. But how can I write in the CMake file to add detect_model.mlmodel into my xcode project and generate the detect_model.h header file?

I have tried to use set(mlmodel detect_model.mlmodel) and add_library(dst ${mlmodel}), but it is not correct.

The expected result is that I can use CMake to add detect_model.mlmodel into xcode project and generate the detect_model.h automatically.

Kevin
  • 16,549
  • 8
  • 60
  • 74

1 Answers1

2

You will probably need to add a custom rule that calls coremlc to generate the .h abd .m files and the .mlmodelc folder.

This is how you'd do it from Terminal:

mkdir output
xcrun coremlc compile YourModel.mlmodel output
xcrun coremlc generate Model.mlmodel output

You also need to add a rule to copy the .mlmodelc folder into the app bundle.

Matthijs Hollemans
  • 7,706
  • 2
  • 16
  • 23
  • Great! It worked. Thanks for your help. Furthermore, whether there is a tool to do the time profile of mlmodel's each layer, I want to know which network layer takes the most time. The Apple coreml tools don't have this function. – YiZhaoYanBo Jan 10 '20 at 09:06
  • 1
    Furthermore, 《Core ML Survival Guide》is really a proper book. It help me to learn much about coreml. Great job! – YiZhaoYanBo Jan 10 '20 at 09:09
  • @YiZhaoYanBo do you by chance have the XCode you wrote to handle this ? –  Jul 21 '21 at 17:04