Skip to content

Commit

Permalink
Add custom_setting data-format for Core ML
Browse files Browse the repository at this point in the history
  • Loading branch information
anhappdev committed Sep 27, 2024
1 parent bbbbc5d commit 7abb44e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
34 changes: 29 additions & 5 deletions mobile_back_apple/cpp/backend_coreml/coreml_settings.pbtxt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ benchmark_setting {
model_checksum: "39483b20b878d46144ab4cfe9a3e5600"
}
}
delegate_choice: {
delegate_choice: {
delegate_name: "CPU & ANE"
accelerator_name: "cpu&ane"
accelerator_desc: "CPU and Neural Engine"
Expand Down Expand Up @@ -57,7 +57,7 @@ benchmark_setting {
model_checksum: "39483b20b878d46144ab4cfe9a3e5600"
}
}
delegate_choice: {
delegate_choice: {
delegate_name: "CPU & ANE"
accelerator_name: "cpu&ane"
accelerator_desc: "CPU and Neural Engine"
Expand All @@ -81,6 +81,10 @@ benchmark_setting {
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.1-coreml/mobilenetv4_fp32_NCHW.mlpackage.zip"
model_checksum: "164c504eb3e9af6c730c1765b8b81b32"
}
custom_setting {
id: "data-format"
value: "NCHW"
}
}
delegate_choice: {
delegate_name: "CPU & GPU"
Expand All @@ -90,6 +94,10 @@ benchmark_setting {
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.1-coreml/mobilenetv4_fp32_NCHW.mlpackage.zip"
model_checksum: "164c504eb3e9af6c730c1765b8b81b32"
}
custom_setting {
id: "data-format"
value: "NCHW"
}
}
delegate_choice: {
delegate_name: "CPU & ANE"
Expand All @@ -99,6 +107,10 @@ benchmark_setting {
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.1-coreml/mobilenetv4_fp32_NCHW.mlpackage.zip"
model_checksum: "164c504eb3e9af6c730c1765b8b81b32"
}
custom_setting {
id: "data-format"
value: "NCHW"
}
}
delegate_selected: "CPU & GPU & ANE"
}
Expand All @@ -115,6 +127,10 @@ benchmark_setting {
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.1-coreml/mobilenetv4_fp32_NCHW.mlpackage.zip"
model_checksum: "164c504eb3e9af6c730c1765b8b81b32"
}
custom_setting {
id: "data-format"
value: "NCHW"
}
}
delegate_choice: {
delegate_name: "CPU & GPU"
Expand All @@ -125,6 +141,10 @@ benchmark_setting {
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.1-coreml/mobilenetv4_fp32_NCHW.mlpackage.zip"
model_checksum: "164c504eb3e9af6c730c1765b8b81b32"
}
custom_setting {
id: "data-format"
value: "NCHW"
}
}
delegate_choice: {
delegate_name: "CPU & ANE"
Expand All @@ -135,6 +155,10 @@ benchmark_setting {
model_path: "https://github.com/mlcommons/mobile_models/releases/download/v4.1-coreml/mobilenetv4_fp32_NCHW.mlpackage.zip"
model_checksum: "164c504eb3e9af6c730c1765b8b81b32"
}
custom_setting {
id: "data-format"
value: "NCHW"
}
}
delegate_selected: "CPU & GPU & ANE"
}
Expand All @@ -160,7 +184,7 @@ benchmark_setting {
model_checksum: "ef849fbf2132e205158f05ca42db25f4"
}
}
delegate_choice: {
delegate_choice: {
delegate_name: "CPU & ANE"
accelerator_name: "cpu&ane"
accelerator_desc: "CPU and Neural Engine"
Expand Down Expand Up @@ -217,7 +241,7 @@ benchmark_setting {
model_checksum: "362d6b5bb1b8e10ae5b4e223f60d4d10"
}
}
delegate_choice: {
delegate_choice: {
delegate_name: "CPU & ANE"
accelerator_name: "cpu&ane"
accelerator_desc: "CPU and Neural Engine"
Expand Down Expand Up @@ -250,7 +274,7 @@ benchmark_setting {
model_checksum: "62489706f20b0c2ae561fb2204eefb61"
}
}
delegate_choice: {
delegate_choice: {
delegate_name: "CPU & ANE"
accelerator_name: "cpu&ane"
accelerator_desc: "CPU and Neural Engine"
Expand Down
5 changes: 3 additions & 2 deletions mobile_back_apple/cpp/backend_coreml/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ mlperf_backend_ptr_t mlperf_backend_create(

CoreMLBackendData *backend_data = new CoreMLBackendData();
backendExists = true;
// quick hack for checking if model expects NCHW input.
if (strcasestr(model_path, "NCHW") != nullptr) {
std::string dataFormat =
mlperf::mobile::GetConfigValue(configs, "data-format", std::string(""));
if (dataFormat == "NCHW") {
backend_data->expectNCHW = true;
LOG(INFO) << "Will convert inputs from NHWC to NCHW!";
}
Expand Down
2 changes: 1 addition & 1 deletion mobile_back_apple/dev-utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ tflite-run-sd:

coreml-build:
cd ${REPO_ROOT_DIR} && \
bazel build -c opt --cxxopt=-fobjc-arc --cxxopt=-xobjective-c++ --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 \
bazel build -c opt --cxxopt=-fobjc-arc --cxxopt=-xobjective-c++ --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --macos_minimum_os=13.0 \
//flutter/cpp/binary:main //mobile_back_apple:coremlbackend

coreml-run-ic:
Expand Down

0 comments on commit 7abb44e

Please sign in to comment.