Add coremltools 7.1 as a dependency (#19389)

### Description
<!-- Describe your changes. -->
Setup usage of coremltools via dependencies instead of copying files. 
Pull in some changes from
https://github.com/microsoft/onnxruntime/pull/19347 in preparation for
supporting ML Program and enabling building the ML Model on all
platforms to make development and testing of CoreML EP code easier.

- Update to coremltools 7.1 
- Add patch for changes required for cross platform build of ML Program
related code
- Generate coreml proto files on all platforms
- mainly to test these changes work everywhere, as the proto files will
be used on all platforms when #19347 is checked in
- rename onnxruntime_coreml_proto target to coreml_proto as it contains
purely coreml protobuf code with no ORT related chagnes

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Improve setup.
This commit is contained in:
Scott McKay 2024-02-03 09:42:21 +10:00 committed by GitHub
parent 18c3acb198
commit debd1cab10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 291 additions and 9006 deletions

View file

@ -42,6 +42,16 @@
"comments": "abseil_cpp"
}
},
{
"component": {
"type": "git",
"git": {
"commitHash": "dbb0094fd0cb936469e35320bf37e866ef7a1da4",
"repositoryUrl": "https://github.com/apple/coremltools.git"
},
"comments": "coremltools"
}
},
{
"component": {
"type": "git",

View file

@ -13,6 +13,7 @@
# See https://microsoft.sharepoint.com/teams/ONNX2/_layouts/OneNote.aspx?id=%2Fteams%2FONNX2%2FShared%20Documents%2FNotebooks%2FONNX%20Ecosystem%20Team%20Notebook&wd=target%28Development.one%7C63D3AB47-51D1-4A62-9965-66882234BD44%2FAdd%20or%20update%20a%20dependency%20in%20deps.txt%7C0E9ED71D-89D5-40FA-B05F-C0123289C591%2F%29
#
abseil_cpp;https://github.com/abseil/abseil-cpp/archive/refs/tags/20240116.0.zip;bc2cec6baaad67fcb6c0c38972b687d4797927e9
coremltools;https://github.com/apple/coremltools/archive/refs/tags/7.1.zip;f1bab0f30966f2e217d8e01207d518f230a1641a
cxxopts;https://github.com/jarro2783/cxxopts/archive/3c73d91c0b04e2b59462f0a741be8c07024c1bc0.zip;6c6ca7f8480b26c8d00476e0e24b7184717fe4f0
date;https://github.com/HowardHinnant/date/archive/refs/tags/v3.0.1.zip;2dac0c81dc54ebdd8f8d073a75c053b04b56e159
dlpack;https://github.com/dmlc/dlpack/archive/refs/tags/v0.6.zip;4d565dd2e5b31321e5549591d78aa7f377173445
@ -55,4 +56,4 @@ tensorboard;https://github.com/tensorflow/tensorboard/archive/373eb09e4c5d2b3cc2
cutlass;https://github.com/NVIDIA/cutlass/archive/refs/tags/v3.1.0.zip;757f90a795034a89d4f48a79d1f009f7a04c8dee
utf8_range;https://github.com/protocolbuffers/utf8_range/archive/72c943dea2b9240cd09efde15191e144bc7c7d38.zip;9925739c9debc0efa2adcb194d371a35b6a03156
extensions;https://github.com/microsoft/onnxruntime-extensions/archive/94142d8391c9791ec71c38336436319a2d4ac7a0.zip;4365ac5140338b4cb75a39944a4be276e3829b3c
composable_kernel;https://github.com/ROCmSoftwarePlatform/composable_kernel/archive/5356c4a943a35e74d7cdc69486afcb8703b9a59a.zip;522382c2af437e09124287e5879ab64af5b2e299
composable_kernel;https://github.com/ROCmSoftwarePlatform/composable_kernel/archive/5356c4a943a35e74d7cdc69486afcb8703b9a59a.zip;522382c2af437e09124287e5879ab64af5b2e299

View file

@ -224,8 +224,6 @@ FetchContent_Declare(
URL_HASH SHA1=${DEP_SHA1_mp11}
)
set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install OFF CACHE INTERNAL "")
set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install OFF CACHE INTERNAL "")
@ -541,6 +539,17 @@ if(onnxruntime_ENABLE_TRAINING OR (onnxruntime_ENABLE_TRAINING_APIS AND onnxrunt
onnxruntime_fetchcontent_makeavailable(cxxopts)
endif()
if (onnxruntime_USE_COREML)
FetchContent_Declare(
coremltools
URL ${DEP_URL_coremltools}
URL_HASH SHA1=${DEP_SHA1_coremltools}
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/coremltools/crossplatformbuild.patch
)
# we don't build directly so use Populate. selected files are built from onnxruntime_providers_coreml.cmake
FetchContent_Populate(coremltools)
endif()
message("Finished fetching external dependencies")

View file

@ -67,7 +67,7 @@ if(onnxruntime_USE_CUDA)
endif()
if(onnxruntime_USE_COREML)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(PROVIDERS_COREML onnxruntime_providers_coreml onnxruntime_coreml_proto)
set(PROVIDERS_COREML onnxruntime_providers_coreml coreml_proto)
else()
set(PROVIDERS_COREML onnxruntime_providers_coreml)
endif()

View file

@ -1,107 +1,119 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
if (onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD)
message(FATAL_ERROR "CoreML EP can not be used in a basic minimal build. Please build with '--minimal_build extended'")
endif()
if (onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD)
message(FATAL_ERROR "CoreML EP can not be used in a basic minimal build. Please build with '--minimal_build extended'")
endif()
add_compile_definitions(USE_COREML=1)
add_compile_definitions(USE_COREML=1)
# Compile CoreML proto definition to ${CMAKE_CURRENT_BINARY_DIR}/coreml
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(COREML_PROTO_ROOT ${PROJECT_SOURCE_DIR}/../onnxruntime/core/providers/coreml/mlmodel_format)
file(GLOB coreml_proto_srcs
"${COREML_PROTO_ROOT}/*.proto"
)
onnxruntime_add_static_library(onnxruntime_coreml_proto ${coreml_proto_srcs})
target_include_directories(onnxruntime_coreml_proto PUBLIC $<TARGET_PROPERTY:${PROTOBUF_LIB},INTERFACE_INCLUDE_DIRECTORIES> "${CMAKE_CURRENT_BINARY_DIR}")
target_compile_definitions(onnxruntime_coreml_proto PUBLIC $<TARGET_PROPERTY:${PROTOBUF_LIB},INTERFACE_COMPILE_DEFINITIONS>)
set_target_properties(onnxruntime_coreml_proto PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
set_target_properties(onnxruntime_coreml_proto PROPERTIES COMPILE_FLAGS "-fvisibility-inlines-hidden")
set(_src_sub_dir "coreml/")
onnxruntime_protobuf_generate(
APPEND_PATH
GEN_SRC_SUB_DIR ${_src_sub_dir}
IMPORT_DIRS ${COREML_PROTO_ROOT}
TARGET onnxruntime_coreml_proto
)
# Compile CoreML proto definition to ${CMAKE_CURRENT_BINARY_DIR}/coreml_proto
set(COREML_PROTO_ROOT ${coremltools_SOURCE_DIR}/mlmodel/format)
file(GLOB coreml_proto_srcs "${COREML_PROTO_ROOT}/*.proto")
if (NOT onnxruntime_BUILD_SHARED_LIB)
install(TARGETS onnxruntime_coreml_proto
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
endif()
onnxruntime_add_static_library(coreml_proto ${coreml_proto_srcs})
target_include_directories(coreml_proto
PUBLIC $<TARGET_PROPERTY:${PROTOBUF_LIB},INTERFACE_INCLUDE_DIRECTORIES>
"${CMAKE_CURRENT_BINARY_DIR}")
target_compile_definitions(coreml_proto
PUBLIC $<TARGET_PROPERTY:${PROTOBUF_LIB},INTERFACE_COMPILE_DEFINITIONS>)
set_target_properties(coreml_proto PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
set_target_properties(coreml_proto PROPERTIES COMPILE_FLAGS "-fvisibility-inlines-hidden")
set(_src_sub_dir "coreml_proto/")
# These are shared utils,
# TODO, move this to a separated lib when used by EPs other than NNAPI and CoreML
file(GLOB_RECURSE onnxruntime_providers_shared_utils_cc_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/shared/utils/utils.h"
"${ONNXRUNTIME_ROOT}/core/providers/shared/utils/utils.cc"
onnxruntime_protobuf_generate(
APPEND_PATH
GEN_SRC_SUB_DIR ${_src_sub_dir}
IMPORT_DIRS ${COREML_PROTO_ROOT}
TARGET coreml_proto
)
if (NOT onnxruntime_BUILD_SHARED_LIB)
install(TARGETS coreml_proto
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
# Add the .proto and generated .cc/.h files to the External/coreml_proto folder in Visual Studio.
# Separate source_group for each as the .proto files are in the repo and the .cc/.h files are generated in the build
# output directory.
set_target_properties(coreml_proto PROPERTIES FOLDER "External")
source_group(TREE ${COREML_PROTO_ROOT} PREFIX coreml_proto FILES ${coreml_proto_srcs})
# filter to the generated .cc/.h files
get_target_property(coreml_proto_generated_srcs coreml_proto SOURCES)
list(FILTER coreml_proto_generated_srcs INCLUDE REGEX "\.pb\.(h|cc)$")
source_group(TREE ${CMAKE_CURRENT_BINARY_DIR} PREFIX coreml_proto_generated FILES ${coreml_proto_generated_srcs})
# These are shared utils,
# TODO, move this to a separated lib when used by EPs other than NNAPI and CoreML
file(GLOB_RECURSE onnxruntime_providers_shared_utils_cc_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/shared/utils/utils.h"
"${ONNXRUNTIME_ROOT}/core/providers/shared/utils/utils.cc"
)
file(GLOB
onnxruntime_providers_coreml_cc_srcs_top CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/coreml/*.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/*.cc"
)
# Add builder source code
file(GLOB_RECURSE
onnxruntime_providers_coreml_cc_srcs_nested CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/coreml/builders/*.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/builders/*.cc"
)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(REMOVE_ITEM onnxruntime_providers_coreml_cc_srcs_nested
"${ONNXRUNTIME_ROOT}/core/providers/coreml/builders/model_builder.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/builders/model_builder.cc"
)
endif()
# Add CoreML objective c++ source code
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
file(GLOB
onnxruntime_providers_coreml_cc_srcs_top CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/coreml/*.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/*.cc"
onnxruntime_providers_coreml_objcc_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/coreml/model/model.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/model/model.mm"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/model/host_utils.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/model/host_utils.mm"
)
endif()
# Add builder source code
file(GLOB_RECURSE
onnxruntime_providers_coreml_cc_srcs_nested CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/coreml/builders/*.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/builders/*.cc"
)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(REMOVE_ITEM onnxruntime_providers_coreml_cc_srcs_nested
"${ONNXRUNTIME_ROOT}/core/providers/coreml/builders/model_builder.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/builders/model_builder.cc"
)
endif()
set(onnxruntime_providers_coreml_cc_srcs
${onnxruntime_providers_coreml_cc_srcs_top}
${onnxruntime_providers_coreml_cc_srcs_nested}
${onnxruntime_providers_shared_utils_cc_srcs}
)
# Add CoreML objective c++ source code
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
file(GLOB
onnxruntime_providers_coreml_objcc_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/coreml/model/model.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/model/model.mm"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/model/host_utils.h"
"${ONNXRUNTIME_ROOT}/core/providers/coreml/model/host_utils.mm"
)
endif()
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_coreml_cc_srcs})
onnxruntime_add_static_library(onnxruntime_providers_coreml
${onnxruntime_providers_coreml_cc_srcs} ${onnxruntime_providers_coreml_objcc_srcs}
)
onnxruntime_add_include_to_target(onnxruntime_providers_coreml
onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers::flatbuffers Boost::mp11 safeint_interface
)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
onnxruntime_add_include_to_target(onnxruntime_providers_coreml coreml_proto)
target_link_libraries(onnxruntime_providers_coreml PRIVATE coreml_proto "-framework Foundation" "-framework CoreML")
add_dependencies(onnxruntime_providers_coreml coreml_proto)
endif()
add_dependencies(onnxruntime_providers_coreml ${onnxruntime_EXTERNAL_DEPENDENCIES})
set(onnxruntime_providers_coreml_cc_srcs
${onnxruntime_providers_coreml_cc_srcs_top}
${onnxruntime_providers_coreml_cc_srcs_nested}
${onnxruntime_providers_shared_utils_cc_srcs}
)
set_target_properties(onnxruntime_providers_coreml PROPERTIES CXX_STANDARD_REQUIRED ON)
set_target_properties(onnxruntime_providers_coreml PROPERTIES FOLDER "ONNXRuntime")
target_include_directories(onnxruntime_providers_coreml PRIVATE ${ONNXRUNTIME_ROOT} ${coreml_INCLUDE_DIRS})
set_target_properties(onnxruntime_providers_coreml PROPERTIES LINKER_LANGUAGE CXX)
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_coreml_cc_srcs})
onnxruntime_add_static_library(onnxruntime_providers_coreml
${onnxruntime_providers_coreml_cc_srcs} ${onnxruntime_providers_coreml_objcc_srcs}
)
onnxruntime_add_include_to_target(onnxruntime_providers_coreml
onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers::flatbuffers Boost::mp11 safeint_interface
)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
onnxruntime_add_include_to_target(onnxruntime_providers_coreml onnxruntime_coreml_proto)
target_link_libraries(onnxruntime_providers_coreml PRIVATE onnxruntime_coreml_proto "-framework Foundation" "-framework CoreML")
add_dependencies(onnxruntime_providers_coreml onnxruntime_coreml_proto)
endif()
add_dependencies(onnxruntime_providers_coreml ${onnxruntime_EXTERNAL_DEPENDENCIES})
set_target_properties(onnxruntime_providers_coreml PROPERTIES CXX_STANDARD_REQUIRED ON)
set_target_properties(onnxruntime_providers_coreml PROPERTIES FOLDER "ONNXRuntime")
target_include_directories(onnxruntime_providers_coreml PRIVATE ${ONNXRUNTIME_ROOT} ${coreml_INCLUDE_DIRS})
set_target_properties(onnxruntime_providers_coreml PROPERTIES LINKER_LANGUAGE CXX)
if (NOT onnxruntime_BUILD_SHARED_LIB)
install(TARGETS onnxruntime_providers_coreml
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if (NOT onnxruntime_BUILD_SHARED_LIB)
install(TARGETS onnxruntime_providers_coreml
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

View file

@ -566,7 +566,7 @@ endif()
if(onnxruntime_USE_COREML)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_coreml onnxruntime_coreml_proto)
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_coreml coreml_proto)
else()
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_coreml)
endif()
@ -675,9 +675,9 @@ endif()
if(onnxruntime_USE_COREML)
list(APPEND onnxruntime_test_framework_src_patterns ${TEST_SRC_DIR}/providers/coreml/*)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND onnxruntime_test_framework_libs onnxruntime_providers_coreml onnxruntime_coreml_proto)
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_coreml onnxruntime_coreml_proto)
list(APPEND onnxruntime_test_providers_libs onnxruntime_providers_coreml onnxruntime_coreml_proto)
list(APPEND onnxruntime_test_framework_libs onnxruntime_providers_coreml coreml_proto)
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_coreml coreml_proto)
list(APPEND onnxruntime_test_providers_libs onnxruntime_providers_coreml coreml_proto)
else()
list(APPEND onnxruntime_test_framework_libs onnxruntime_providers_coreml)
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_coreml)

View file

@ -0,0 +1,155 @@
diff --git a/mlmodel/src/MILBlob/Blob/FileWriter.cpp b/mlmodel/src/MILBlob/Blob/FileWriter.cpp
index adc7bfcf..7b2bf9cc 100644
--- a/mlmodel/src/MILBlob/Blob/FileWriter.cpp
+++ b/mlmodel/src/MILBlob/Blob/FileWriter.cpp
@@ -8,8 +8,12 @@
#include <cstdio>
#include <stdexcept>
+
+// ORT_EDIT: Exclude mmap on Windows. Not used in this file anyway.
+#if !defined(_WIN32)
#include <sys/mman.h>
#include <sys/stat.h>
+#endif
using namespace MILBlob;
using namespace MILBlob::Blob;
diff --git a/mlmodel/src/MILBlob/Fp16.cpp b/mlmodel/src/MILBlob/Fp16.cpp
index ae1e71a1..77a7161f 100644
--- a/mlmodel/src/MILBlob/Fp16.cpp
+++ b/mlmodel/src/MILBlob/Fp16.cpp
@@ -5,6 +5,8 @@
#include "MILBlob/Fp16.hpp"
+// ORT_EDIT: Exclude clang specific pragmas from other builds
+#if defined(__clang__)
// fp16 lib code has some conversion warnings we don't want to globally ignore
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
@@ -12,6 +14,9 @@
#pragma clang diagnostic ignored "-Wconversion"
#include "fp16/fp16.h"
#pragma clang diagnostic pop
+#else
+#include "fp16/fp16.h"
+#endif
using namespace MILBlob;
diff --git a/modelpackage/src/ModelPackage.cpp b/modelpackage/src/ModelPackage.cpp
index 8fee56b9..99e0d8d6 100644
--- a/modelpackage/src/ModelPackage.cpp
+++ b/modelpackage/src/ModelPackage.cpp
@@ -26,7 +26,14 @@ namespace std {
#else
#error "missing required header <filesystem>"
#endif
+
+// ORT_EDIT: Use UuidCreate on Windows.
+#if defined(_WIN32)
+#pragma comment(lib, "rpcrt4.lib") // UuidCreate
+#include <windows.h>
+#else
#include <uuid/uuid.h>
+#endif
#include <vector>
#if defined(__cplusplus)
@@ -187,7 +194,10 @@ public:
ModelPackageItemInfo createFile(const std::string& name, const std::string& author, const std::string& description);
};
+// ORT_EDIT: pragma only available on APPLE platforms
+#if defined(__APPLE__)
#pragma mark ModelPackageImpl
+#endif
ModelPackageImpl::ModelPackageImpl(const std::filesystem::path& path, bool createIfNecessary, bool readOnly)
: m_packagePath(path),
@@ -372,6 +382,20 @@ std::filesystem::path ModelPackageImpl::getItemPath(const std::string& name, con
}
std::string ModelPackageImpl::generateIdentifier() const {
+// ORT_EDIT: Use built-in UUID generation on Windows
+#if defined(_WIN32)
+ UUID uuid;
+ UuidCreate(&uuid);
+
+ RPC_CSTR uuidStr;
+ UuidToStringA(&uuid, &uuidStr);
+
+ std::string uuidStrCpp(reinterpret_cast<char*>(uuidStr));
+
+ RpcStringFreeA(&uuidStr);
+
+ return uuidStrCpp;
+#else
uuid_t uuid;
// uuid_unparse generates a 36-character null-terminated string (37 bytes).
@@ -383,6 +407,7 @@ std::string ModelPackageImpl::generateIdentifier() const {
uuid_unparse(uuid, buf);
return std::string(buf);
+#endif
}
ModelPackageItemInfo ModelPackageImpl::createFile(const std::string& name, const std::string& author, const std::string& description) {
@@ -468,7 +493,13 @@ std::shared_ptr<ModelPackageItemInfo> ModelPackageImpl::findItem(const std::stri
auto author = itemInfoEntry->getString(kModelPackageItemInfoAuthorKey);
auto description = itemInfoEntry->getString(kModelPackageItemInfoDescriptionKey);
+// ORT_EDIT: need to use path.string() on Windows
+#if defined(_WIN32)
+ return std::make_shared<ModelPackageItemInfo>(std::make_shared<ModelPackageItemInfoImpl>(identifier, path.string(), name, author, description));
+
+#else
return std::make_shared<ModelPackageItemInfo>(std::make_shared<ModelPackageItemInfoImpl>(identifier, path, name, author, description));
+#endif
}
std::shared_ptr<ModelPackageItemInfo> ModelPackageImpl::findItem(const std::string& name, const std::string& author) const
@@ -514,7 +545,9 @@ void ModelPackageImpl::removeItem(const std::string& identifier)
}
auto path = m_packageDataDirPath / itemInfoEntry->getString(kModelPackageItemInfoPathKey);
- if (0 != std::remove(path.c_str())) {
+ // ORT_EDIT: std::remove doesn't work on Windows. Use std::filesystem::remove instead.
+ // if (0 != std::remove(path.c_str())) {
+ if (!std::filesystem::remove(path)) {
throw std::runtime_error("Failed to remove file at path: " + path.string());
}
@@ -525,13 +558,16 @@ bool ModelPackageImpl::isValid(const std::filesystem::path& path)
{
try {
ModelPackageImpl(path, false, true);
- } catch (std::runtime_error& e) {
+ } catch (std::runtime_error& /*e*/) { // ORT_EDIT: comment out unused variable
return false;
}
return true;
}
+// ORT_EDIT: pragma only available on APPLE platforms
+#if defined(__APPLE__)
#pragma mark ModelPackage
+#endif
ModelPackage::ModelPackage(const std::string& packagePath, bool createIfNecessary, bool readOnly)
: m_modelPackageImpl(std::make_shared<ModelPackageImpl>(packagePath, createIfNecessary, readOnly))
@@ -544,7 +580,12 @@ ModelPackage::~ModelPackage()
std::string ModelPackage::path() const
{
+// ORT_EDIT: Windows doesn't automatically convert to std::string as the native format could be char or wchar.
+#if defined(_WIN32)
+ return m_modelPackageImpl->path().string();
+#else
return m_modelPackageImpl->path();
+#endif
}
std::string ModelPackage::setRootModel(const std::string& path, const std::string& name, const std::string& author, const std::string& description)

View file

@ -9,6 +9,6 @@
#error "This file should only be included when building on Apple platforms."
#endif
#include "coreml/Model.pb.h"
#include "coreml_proto/Model.pb.h"
namespace COREML_SPEC = CoreML::Specification;

View file

@ -11,7 +11,7 @@
#include "core/providers/shared/utils/utils.h"
#include "core/optimizer/initializer.h"
#include "coreml/NeuralNetwork.pb.h"
#include "coreml_proto/NeuralNetwork.pb.h"
namespace onnxruntime {
namespace coreml {

View file

@ -1,19 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* An array feature extractor.
*
* Given an index, extracts the value at that index from its array input.
* Indexes are zero-based.
*/
message ArrayFeatureExtractor {
repeated uint64 extractIndex = 1;
}

View file

@ -1,139 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* A Bayesian probit regressor.
*
* The probit regression model is superficially similar to the more commonly known
* logistic regression, with sampling distribution of the model given by
*
* P(y=+1|x,w) = Φ(<w,x>/β)
*
* where w are the set of weights,
* x are the set of features for the given event,
* β is a model hyper-parameter, and
* Φ is the link function, defined to be the CDF of the normal distribution.
* The weights w[i,j] are Gaussian distributed, with mean μ[i,j] and precision 1/(σ[i,j])^2
* (where i indexes over features and j indexes over the values for the feature).
* The parameter β scales the steepness of the inverse link function.
*
* (see https://en.wikipedia.org/wiki/Probit_model and https://en.wikipedia.org/wiki/Logistic_regression
* for more details on probit model and logistic regression, respectively)
*
* Input: X
* x represents a set of features, each taking on a discrete value (note that continuous values
* would first need to be discretized). x can be represented as a vector where the index i is
* the feature id and x[i] is the feature value. Alternatively, x can be represented as a matrix
* with 2 columns where the first column indicates the feature id and the second column contains
* the feature values, i.e. x[i,0] is the feature id and x[i,1] is the feature value.
*
* additional input features:
* - "optimism": apply a mean shift to the probability, i.e. shift regression mean by o*stdev,
* where o is the "optimism" parameter (see additional output features)
* - "samplingScale": for sampling from posterior, multiply standard deviation by this factor
* - "samplingTruncation": for sampling from posterior, truncate sampling distribution at given multiple of std from mean
*
* Output: Y
* probability P(y|x,w)
*
* additional output features:
* - mean (regression output before applying link function)
* - variance (regression output variance before applying link function)
* - pessimistic probability: P(y|x,w) with a mean shift parameterized by "optimism" feature
* - sampled probability: p ~ P(y|x,w) with standard deviation scaling parametrized by "samplingScale" feature
* and distribution truncated at multiple of standard deviation,
* where multiple parameterized by "samplingTruncation" feature.
*
*/
message BayesianProbitRegressor {
/*
* Parameterization of a Gaussian distribution
*/
message Gaussian {
double mean = 1;
double precision = 2; // inverse of the variance
}
/*
* Weight for a specific feature value
* The weight is represented as a Gaussian distribution
* with a mean and precision (1/variance) to capture
* uncertainty in the weight
*/
message FeatureValueWeight {
uint32 featureValue = 1;
Gaussian featureWeight = 2;
}
/*
* Feature with associated weights (for different values)
* Each feature has a set of weights for the (discrete) values
* it can take
*/
message FeatureWeight {
uint32 featureId = 1;
repeated FeatureValueWeight weights = 2;
}
uint32 numberOfFeatures = 1;
Gaussian bias = 2; // bias term
/*
* Set of features with associated weights
*/
repeated FeatureWeight features = 3; // feature weights
/*
* Set this name to be the same as input feature of type multi-array (1D)
* in the model description you want to use as the regression input
*/
string regressionInputFeatureName = 10;
/*
* Set this name to be the same as optional input feature of type double
* in the model description you want to use as the optimism input
*/
string optimismInputFeatureName = 11;
/*
* Set this name to be the same as optional input feature of type double
* in the model description you want to use as the samplingScale input
*/
string samplingScaleInputFeatureName = 12;
/*
* Set this name to be the same as optional input feature of type double
* in the model description you want to use as the samplingBounds input
*/
string samplingTruncationInputFeatureName = 13;
/*
* name of 'mean' output feature
*/
string meanOutputFeatureName = 20;
/*
* name of 'variance' output feature
*/
string varianceOutputFeatureName = 21;
/*
* name of 'pessimistic' output feature
*/
string pessimisticProbabilityOutputFeatureName = 22;
/*
* name of 'sampled' output feature: samples from the scaled posterior probability distribuiton
*/
string sampledProbabilityOutputFeatureName = 23;
}

View file

@ -1,38 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
* A categorical mapping.
*
* This allows conversion from integers to strings, or from strings to integers.
*/
message CategoricalMapping {
oneof MappingType {
// Conversion from strings to integers
StringToInt64Map stringToInt64Map = 1;
// Conversion from integer to string
Int64ToStringMap int64ToStringMap = 2;
}
/**
* The value returned if an input is not contained in the map above.
* If one of these is not set, then an error is raised on an unknown input.
*/
oneof ValueOnUnknown {
// Default output when converting from an integer to a string.
string strValue = 101;
// Default output when converting from a string to an integer.
int64 int64Value = 102;
}
}

View file

@ -1,30 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* A parameterized model whose function is defined in code
*/
message CustomModel {
message CustomModelParamValue {
oneof value {
double doubleValue = 10;
string stringValue = 20;
int32 intValue = 30;
int64 longValue = 40;
bool boolValue = 50;
bytes bytesValue = 60;
}
}
string className = 10; // The name of the class (conforming to MLCustomModel) corresponding to this model
map<string, CustomModelParamValue> parameters = 30;
string description = 40; // An (optional) description provided by the model creator. This information is displayed when viewing the model, but does not affect the model's execution on device.
}

View file

@ -1,95 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "FeatureTypes.proto";
package CoreML.Specification;
/**
* A mapping from a string
* to a 64-bit integer.
*/
message StringToInt64Map {
map<string, int64> map = 1;
}
/**
* A mapping from a 64-bit integer
* to a string.
*/
message Int64ToStringMap {
map<int64, string> map = 1;
}
/**
* A mapping from a string
* to a double-precision floating point number.
*/
message StringToDoubleMap {
map<string, double> map = 1;
}
/**
* A mapping from a 64-bit integer
* to a double-precision floating point number.
*/
message Int64ToDoubleMap {
map<int64, double> map = 1;
}
/**
* A vector of strings.
*/
message StringVector {
repeated string vector = 1;
}
/**
* A vector of 64-bit integers.
*/
message Int64Vector {
repeated int64 vector = 1;
}
/**
* A vector of floating point numbers.
*/
message FloatVector {
repeated float vector = 1;
}
/**
* A vector of double-precision floating point numbers.
*/
message DoubleVector {
repeated double vector = 1;
}
/**
* A range of int64 values
*/
message Int64Range {
int64 minValue = 1;
int64 maxValue = 2;
}
/**
* A set of int64 values
*/
message Int64Set {
repeated int64 values = 1;
}
/**
* A range of double values
*/
message DoubleRange {
double minValue = 1;
double maxValue = 2;
}

View file

@ -1,36 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
* Uses an index mapping to convert a dictionary to an array.
*
* The output array will be equal in length to the index mapping vector parameter.
* All keys in the input dictionary must be present in the index mapping vector.
*
* For each item in the input dictionary, insert its value in the output array.
* The position of the insertion is determined by the position of the item's key
* in the index mapping. Any keys not present in the input dictionary, will be
* zero in the output array.
*
* For example: if the ``stringToIndex`` parameter is set to ``["a", "c", "b", "z"]``,
* then an input of ``{"a": 4, "c": 8}`` will produce an output of ``[4, 8, 0, 0]``.
*
*/
message DictVectorizer {
oneof Map {
/// String keys to indexes
StringVector stringToIndex = 1;
/// Int keys to indexes
Int64Vector int64ToIndex = 2;
}
}

View file

@ -1,224 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* The 64-bit integer feature type.
*/
message Int64FeatureType {}
/**
* The double-precision floating point number feature type.
*/
message DoubleFeatureType {}
/**
* The string feature type.
*/
message StringFeatureType {}
message SizeRange {
uint64 lowerBound = 1;
int64 upperBound = 2; // negative value means unbound otherwise upperbound is included in range
}
/**
* The image feature type.
*/
message ImageFeatureType {
// Assumes raw (decompressed) format
enum ColorSpace {
INVALID_COLOR_SPACE = 0;
GRAYSCALE = 10; // 8 bits per pixel
RGB = 20; // 32 bits per pixel: RGBA with A channel ignored
BGR = 30; // 32 bits per pixel: BGRA with A channel ignored
}
message ImageSize {
uint64 width = 1;
uint64 height = 2;
}
message EnumeratedImageSizes {
repeated ImageSize sizes = 1;
}
message ImageSizeRange {
SizeRange widthRange = 1;
SizeRange heightRange = 2;
}
// The required or default image size is width x height
//
// If specificationVersion <= 2 or SizeFlexibility is empty,
// width x height is the required fixed image size
//
// If SizeFlexibility is present, width x height indicate a "default"
// image size which must be consistent with the flexibilty specified
int64 width = 1;
int64 height = 2;
// For specification version >= 3 you can specify image size flexibility.
oneof SizeFlexibility {
// Use enumeratedSizes for a set of distinct fixed sizes
// e.g. portrait or landscape: [80 x 100, 100 x 8]
//
// If the width x height fields above are specified then they must be
// one of the sizes listed.
//
// If width and height are not specified above then the default width
// and height will be enumeratedSizes[0]
//
// Must be non-empty
EnumeratedImageSizes enumeratedSizes = 21;
// Use imageSizeRange to allow for ranges of values
// e.g. any image greater than 10 x 20: [10..<max] x [20..<max]
//
// If width and height are specified above they must fall in the range
// specified in imageSizeRange. They will be treated as the default size.
//
// If width and height are not specified above then the default width
// and height will be imageSizeRange.widthRange.lowerBound x imageSizeRange.heightRange.lowerBound
ImageSizeRange imageSizeRange = 31;
}
ColorSpace colorSpace = 3;
}
/**
* The array feature type.
*/
message ArrayFeatureType {
enum ArrayDataType {
INVALID_ARRAY_DATA_TYPE = 0;
FLOAT32 = 65568; // 0x10000 | 32
DOUBLE = 65600; // 0x10000 | 64
INT32 = 131104; // 0x20000 | 32
}
// The required or default shape
//
// If specificationVersion <= 2 or ShapeFlexibility is empty,
// shape is the required fixed shape
//
// If ShapeFlexibility is present, shape indicate a "default"
// shape which must be consistent with the flexibilty specified
repeated int64 shape = 1;
ArrayDataType dataType = 2;
message Shape {
repeated int64 shape = 1;
}
message EnumeratedShapes {
repeated Shape shapes = 1;
}
message ShapeRange {
// sizeRanges.size() must be length 1 or 3
// sizeRanges[d] specifies the allowed range for dimension d
repeated SizeRange sizeRanges = 1;
}
// For specification version >= 3 you can specify image size flexibility.
oneof ShapeFlexibility {
// Use enumeratedShapes for a set of distinct fixed shapes
//
// If the shape field is specified then it must be
// one of the enumerated shapes.
///
// If shape is not specifed, the "default" shape will be considered
// enumeratedShapes[0]
//
// Must be non-empty
EnumeratedShapes enumeratedShapes = 21;
// Use shapeRange to allow the size of each dimension vary within
// indpendently specified ranges
//
// If you specify shape above it must fall in the range
// specified in shapeRanges. It will be treated as the default shape.
//
// If you don't specify shape above then the default shape will
// have shape[d] = shapeRange.sizeRanges[d].lowerBound
ShapeRange shapeRange = 31;
}
oneof defaultOptionalValue {
int32 intDefaultValue = 41;
float floatDefaultValue = 51;
double doubleDefaultValue = 61;
}
}
/**
* The dictionary feature type.
*/
message DictionaryFeatureType {
/**
* Key/value type tags, with the following restrictions:
* - ``keyType`` must be a hashable type
* - ``valueType`` is assumed to be a ``double``
*/
oneof KeyType {
Int64FeatureType int64KeyType = 1;
StringFeatureType stringKeyType = 2;
}
}
/**
* The Sequence feature type.
*/
message SequenceFeatureType {
/**
* Currently only categorical int64 and String sequences are supported
*/
oneof Type {
Int64FeatureType int64Type = 1;
StringFeatureType stringType = 3;
}
// Range of allowed size/length/count of sequence
SizeRange sizeRange = 101;
}
/**
* A feature, which may be optional.
*/
message FeatureType {
oneof Type {
Int64FeatureType int64Type = 1;
DoubleFeatureType doubleType = 2;
StringFeatureType stringType = 3;
ImageFeatureType imageType = 4;
ArrayFeatureType multiArrayType = 5;
DictionaryFeatureType dictionaryType = 6;
SequenceFeatureType sequenceType = 7;
}
bool isOptional = 1000;
}

View file

@ -1,26 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* A FeatureVectorizer puts one or more features into a single array.
*
* The ordering of features in the output array is determined by
* ``inputList``.
*
* ``inputDimensions`` is a zero based index.
*/
message FeatureVectorizer {
message InputColumn {
string inputColumn = 1;
uint64 inputDimensions = 2;
}
repeated InputColumn inputList = 1;
}

View file

@ -1,43 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
* A generalized linear model classifier.
*/
message GLMClassifier {
message DoubleArray {
repeated double value = 1;
}
enum PostEvaluationTransform {
Logit = 0;
Probit = 1; /// Only binary classification is supported for probit
}
enum ClassEncoding {
ReferenceClass = 0; /// First class is the reference class
OneVsRest = 1; /// Also called One vs All
}
repeated DoubleArray weights = 1;
repeated double offset = 2;
PostEvaluationTransform postEvaluationTransform = 3;
ClassEncoding classEncoding = 4;
/**
* Required class label mapping.
*/
oneof ClassLabels {
StringVector stringClassLabels = 100;
Int64Vector int64ClassLabels = 101;
}
}

View file

@ -1,28 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* A generalized linear model regressor.
*/
message GLMRegressor {
message DoubleArray {
repeated double value = 1;
}
enum PostEvaluationTransform {
NoTransform = 0;
Logit = 1;
Probit = 2;
}
repeated DoubleArray weights = 1;
repeated double offset = 2;
PostEvaluationTransform postEvaluationTransform = 3;
}

View file

@ -1,43 +0,0 @@
// Copyright (c) 2019, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification.CoreMLModels;
/**
* A model which uses an efficient probabilistic representation
* for assigning labels to a set of strings.
*/
message Gazetteer {
/*
* Stores the revision number for the model, revision 2 is available on
* iOS, tvOS 13.0+, macOS 10.15+
*/
uint32 revision = 1;
/*
* Stores the language of the model, as specified in BCP-47 format,
* e.g. "en-US". See https://tools.ietf.org/html/bcp47
*/
string language = 10;
/*
* Natural Lanaguge framework's efficient representation of a gazetter.
*/
bytes modelParameterData = 100;
/*
* Stores the set of output class labels
*/
oneof ClassLabels {
StringVector stringClassLabels = 200;
}
}

View file

@ -1,18 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* An identity model.
*
* This model returns given inputs as outputs, unchanged.
* Intended to be used for testing purposes.
*/
message Identity {
}

View file

@ -1,43 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
* A transformer that replaces missing values with a default value,
* such as a statistically-derived value.
*
* If ``ReplaceValue`` is set, then missing values of that type are
* replaced with the corresponding value.
*
* For example: if ``replaceDoubleValue`` is set to ``NaN``
* and a single ``NaN`` double value is provided as input,
* then it is replaced by ``imputedDoubleValue``. However
* if the input is an array of doubles, then any instances
* of ``NaN`` in the array is replaced with the corresponding
* value in ``imputedDoubleArray``.
*/
message Imputer {
oneof ImputedValue {
double imputedDoubleValue = 1;
int64 imputedInt64Value = 2;
string imputedStringValue = 3;
DoubleVector imputedDoubleArray = 4;
Int64Vector imputedInt64Array = 5;
StringToDoubleMap imputedStringDictionary = 6;
Int64ToDoubleMap imputedInt64Dictionary = 7;
}
oneof ReplaceValue {
double replaceDoubleValue = 11;
int64 replaceInt64Value = 12;
string replaceStringValue = 13;
}
}

View file

@ -1,93 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
/**
* Each tree is a collection of nodes,
* each of which is identified by a unique identifier.
*
* Each node is either a branch or a leaf node.
* A branch node evaluates a value according to a behavior;
* if true, the node identified by ``true_child_node_id`` is evaluated next,
* if false, the node identified by ``false_child_node_id`` is evaluated next.
* A leaf node adds the evaluation value to the base prediction value
* to get the final prediction.
*
* A tree must have exactly one root node,
* which has no parent node.
* A tree must not terminate on a branch node.
* All leaf nodes must be accessible
* by evaluating one or more branch nodes in sequence,
* starting from the root node.
*/
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
* Item Similarity Recommender
*
* The Item Similarity recommender takes as input a list of items and scores,
* then uses that information and a table of item similarities to predict similarity
* scores for all items. By default, the items predicted are most similar to the given
* items but not part of that item set.
*
* The predicted score for a given item k is
* sum_(i in observed items) sim_(k,i) * (score_i - shift_k)
*
* Because only the most similar scores for each item i are stored,
* sim_(k,i) is often zero.
*
* For many models, the score adjustment parameter shift_j is zero -- it's occasionally used
* to counteract global biases for popular items.
*
*
* References:
*/
message ItemSimilarityRecommender {
/** The items similar to a given base item.
*/
message ConnectedItem {
uint64 itemId = 1;
double similarityScore = 2;
}
/** The formula for the score of a given model as given above, with shift_k
* parameter given by itemScoreAdjustment, and the similar item list filling in
* all the known sim(k,i) scores for i given by itemID and k given by the itemID parameter in
* the similarItemList.
*/
message SimilarItems {
uint64 itemId = 1;
repeated ConnectedItem similarItemList = 2;
double itemScoreAdjustment = 3;
}
repeated SimilarItems itemItemSimilarities = 1;
/** One or none of these are given. If none are given, then the items must number 0, 1, ..., num_items - 1.
* If either is given, the length must be exactly num_items.
*/
StringVector itemStringIds = 2;
Int64Vector itemInt64Ids = 3;
/** Input parameter names specifying different possible inputs to the recommender.
*/
string itemInputFeatureName = 10; /* Required */
string numRecommendationsInputFeatureName = 11; /* Optional; defaults to all items if not given.*/
string itemRestrictionInputFeatureName = 12; /* Optional. */
string itemExclusionInputFeatureName = 13; /* Optional; defaults to input item list if not given. */
/** The predicted outputs. At least one of these must be specified.
*/
string recommendedItemListOutputFeatureName = 20;
string recommendedItemScoreOutputFeatureName = 21;
}

View file

@ -1,42 +0,0 @@
// Copyright (c) 2019, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "Parameters.proto";
package CoreML.Specification;
/**
* A model which wraps another (compiled) model external to this one
*/
message LinkedModel {
oneof LinkType {
// A model located via a file system path
LinkedModelFile linkedModelFile = 1;
}
}
// Model is referenced by a model file name and search path
message LinkedModelFile {
// Model file name: e.g. "MyFetureExtractor.mlmodelc"
StringParameter linkedModelFileName = 1;
// Search path to find the linked model file
// Multiple paths can be searched using the unix-style path separator ":"
// Each path can be relative (to this model) or absolute
//
// An empty string is the same as teh relative search path "."
// which searches in the same location as this model file
//
// There are some special paths which start with $
// - $BUNDLE_MAIN - Indicates to look in the main bundle
// - $BUNDLE_IDENTIFIER(identifier) - Looks in Bunde with given identifer
StringParameter linkedModelSearchPath = 2;
}

View file

@ -1,322 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
/**
* A Core ML model consists of a specification version
* and a model description,
* and can be any one of the following types:
*
* Neural Networks
* - `NeuralNetwork`
*
* Regressors
* - ``GLMRegressor``
* - ``SupportVectorRegressor``
* - ``TreeEnsembleRegressor``
* - ``NeuralNetworkRegressor``
* - ``BayesianProbitRegressor``
*
* Classifiers
* - `NeuralNetworkClassifier`
* - `TreeEnsembleClassifier`
* - `GLMClassifier`
* - `SupportVectorClassifier`
* - `KNearestNeighborsClassifier`
*
* Other models
* - `CustomModel`
* - `TextClassifier`
* - `WordTagger`
* - `Gazetteer`
* - `WordEmbedding`
* - `VisionFeaturePrint`
* - `LinkedModel`
* - `SoundAnalysisPreprocessing`
* - `ItemSimilarityRecommender`
*
* Feature Engineering
* - `Imputer`
* - `Scaler`
* - `Normalizer`
* - `OneHotEncoder`
* - `CategoricalMapping`
* - `FeatureVectorizer`
* - `DictVectorizer`
* - `ArrayFeatureExtractor`
* - `NonMaximumSuppression`
*
* Pipelines
* - `PipelineClassifier`
* - `PipelineRegressor`
* - `Pipeline`
*
* Simple Mathematical Functions
* - `Identity`
*/
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "VisionFeaturePrint.proto";
import public "TextClassifier.proto";
import public "WordTagger.proto";
import public "Gazetteer.proto";
import public "WordEmbedding.proto";
import public "ArrayFeatureExtractor.proto";
import public "BayesianProbitRegressor.proto";
import public "CategoricalMapping.proto";
import public "CustomModel.proto";
import public "DictVectorizer.proto";
import public "FeatureTypes.proto";
import public "FeatureVectorizer.proto";
import public "GLMRegressor.proto";
import public "GLMClassifier.proto";
import public "NearestNeighbors.proto";
import public "Identity.proto";
import public "Imputer.proto";
import public "NeuralNetwork.proto";
import public "Normalizer.proto";
import public "OneHotEncoder.proto";
import public "Scaler.proto";
import public "NonMaximumSuppression.proto";
import public "SVM.proto";
import public "TreeEnsemble.proto";
import public "Parameters.proto";
import public "ItemSimilarityRecommender.proto";
import public "SoundAnalysisPreprocessing.proto";
import public "LinkedModel.proto";
package CoreML.Specification;
/**
* A pipeline consisting of one or more models.
*/
message Pipeline {
repeated Model models = 1;
// Optional names given for each model
// If not supplied it defaults to ["model0",..., "model"(models.size()-1)]
// These names can be used to disambiguate the scope / domain of a parameter
repeated string names = 2;
}
/**
* A classifier pipeline.
*/
message PipelineClassifier {
Pipeline pipeline = 1;
}
/**
* A regressor pipeline.
*/
message PipelineRegressor {
Pipeline pipeline = 1;
}
/**
* A feature description,
* consisting of a name, short description, and type.
*/
message FeatureDescription {
string name = 1;
string shortDescription = 2;
FeatureType type = 3;
}
/**
* Model metadata,
* consisting of a short description, a version string,
* an author, a license, and any other user defined
* key/value meta data.
*/
message Metadata {
string shortDescription = 1;
string versionString = 2;
string author = 3;
string license = 4;
map<string, string> userDefined = 100;
}
/**
* A description of a model,
* consisting of descriptions of its input and output features.
* Both regressor and classifier models require the name of the
* primary predicted output feature (``predictedFeatureName``).
* Classifier models can specify the output feature containing
* probabilities for the predicted classes
* (``predictedProbabilitiesName``).
*/
message ModelDescription {
repeated FeatureDescription input = 1;
repeated FeatureDescription output = 10;
// [Required for regressor and classifier models]: the name
// to give to an output feature containing the prediction.
string predictedFeatureName = 11;
// [Optional for classifier models]: the name to give to an
// output feature containing a dictionary mapping class
// labels to their predicted probabilities. If not specified,
// the dictionary will not be returned by the model.
string predictedProbabilitiesName = 12;
repeated FeatureDescription trainingInput = 50;
Metadata metadata = 100;
}
message SerializedModel {
// Identifier whose content describes the model type of the serialized protocol buffer message.
string identifier = 1;
// Must be a valid serialized protocol buffer of the above specified type.
bytes model = 2;
}
/**
* A Core ML model,
* consisting of a specification version,
* a model description, and a model type.
*
* Core ML model compatibility is indicated by
* a monotonically increasing specification version number,
* which is incremented anytime a backward-incompatible change is made
* (this is functionally equivalent to the MAJOR version number
* described by `Semantic Versioning 2.0.0 <http://semver.org/>`_).
*
* Specification Versions : OS Availability (Core ML Version)
*
* 1 : iOS 11, macOS 10.13, tvOS 11, watchOS 4 (Core ML 1)
* - Feedforward & Recurrent Neural Networks
* - General Linear Models
* - Tree Ensembles
* - Support Vector Machines
* - Pipelines
* - Feature Engineering
*
* 2 : iOS 11.2, macOS 10.13.2, tvOS 11.2, watchOS 4.2 (Core ML 1.2)
* - Custom Layers for Neural Networks
* - Float 16 support for Neural Network layers
*
* 3 : iOS 12, macOS 10.14, tvOS 12, watchOS 5 (Core ML 2)
* - Flexible shapes and image sizes
* - Categorical sequences
* - Core ML Vision Feature Print, Text Classifier, Word Tagger
* - Non Max Suppression
* - Crop and Resize Bilinear NN layers
* - Custom Models
*
* 4 : iOS 13, macOS 10.15, tvOS 13, watchOS 6 (Core ML 3)
* - Updatable models
* - Exact shape / general rank mapping for neural networks
* - Large expansion of supported neural network layers
* - Generalized operations
* - Control flow
* - Dynamic layers
* - See NeuralNetwork.proto
* - Nearest Neighbor Classifier
* - Sound Analysis Prepreocessing
* - Recommender
* - Linked Model
* - NLP Gazeteer
* - NLP WordEmbedding
*
* 5 : iOS 14, macOS 11, tvOS 14, watchOS 7 (Core ML 4)
* - Model Deployment
* - Model Encryption
* - Unified converter API with PyTorch and Tensorflow 2 Support in coremltools 4
* - MIL builder for neural networks and composite ops in coremltools 4
* - New layers in neural network:
* - CumSum
* - OneHot
* - ClampedReLu
* - ArgSort
* - SliceBySize
* - Convolution3D
* - Pool3D
* - Bilinear Upsample with align corners and fractional factors
* - PixelShuffle
* - MatMul with int8 weights and int8 activations
* - Concat interleave
* - See NeuralNetwork.proto
* - Enhanced Xcode model view with interactive previews
* - Enhanced Xcode Playground support for Core ML models
*
*/
message Model {
int32 specificationVersion = 1;
ModelDescription description = 2;
/*
* Following model types support on-device update:
*
* - NeuralNetworkClassifier
* - NeuralNetworkRegressor
* - NeuralNetwork
* - KNearestNeighborsClassifier
*/
bool isUpdatable = 10;
// start at 200 here
// model specific parameters:
oneof Type {
// pipeline starts at 200
PipelineClassifier pipelineClassifier = 200;
PipelineRegressor pipelineRegressor = 201;
Pipeline pipeline = 202;
// regressors start at 300
GLMRegressor glmRegressor = 300;
SupportVectorRegressor supportVectorRegressor = 301;
TreeEnsembleRegressor treeEnsembleRegressor = 302;
NeuralNetworkRegressor neuralNetworkRegressor = 303;
BayesianProbitRegressor bayesianProbitRegressor = 304;
// classifiers start at 400
GLMClassifier glmClassifier = 400;
SupportVectorClassifier supportVectorClassifier = 401;
TreeEnsembleClassifier treeEnsembleClassifier = 402;
NeuralNetworkClassifier neuralNetworkClassifier = 403;
KNearestNeighborsClassifier kNearestNeighborsClassifier = 404;
// generic models start at 500
NeuralNetwork neuralNetwork = 500;
ItemSimilarityRecommender itemSimilarityRecommender = 501;
// Custom and linked models
CustomModel customModel = 555;
LinkedModel linkedModel = 556;
// feature engineering starts at 600
OneHotEncoder oneHotEncoder = 600;
Imputer imputer = 601;
FeatureVectorizer featureVectorizer = 602;
DictVectorizer dictVectorizer = 603;
Scaler scaler = 604;
CategoricalMapping categoricalMapping = 606;
Normalizer normalizer = 607;
ArrayFeatureExtractor arrayFeatureExtractor = 609;
NonMaximumSuppression nonMaximumSuppression = 610;
// simple mathematical functions used for testing start at 900
Identity identity = 900;
// reserved until 1000
// CoreML provided models
CoreMLModels.TextClassifier textClassifier = 2000;
CoreMLModels.WordTagger wordTagger = 2001;
CoreMLModels.VisionFeaturePrint visionFeaturePrint = 2002;
CoreMLModels.SoundAnalysisPreprocessing soundAnalysisPreprocessing = 2003;
CoreMLModels.Gazetteer gazetteer = 2004;
CoreMLModels.WordEmbedding wordEmbedding = 2005;
// Reserved private messages start at 3000
// These messages are subject to change with no notice or support.
SerializedModel serializedModel = 3000;
}
}

View file

@ -1,132 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
import public "DataStructures.proto";
import public "Parameters.proto";
/**
* A k-Nearest-Neighbor classifier
*/
message KNearestNeighborsClassifier {
/**
* The "core" nearest neighbor model attributes.
*/
NearestNeighborsIndex nearestNeighborsIndex = 1;
/**
* Number of neighbors to use for classification.
*/
Int64Parameter numberOfNeighbors = 3;
/**
* Type of labels supported by the model. Currently supports String or Int64
* labels.
*/
oneof ClassLabels {
StringVector stringClassLabels = 100;
Int64Vector int64ClassLabels = 101;
}
/**
* Default value of class label (useful when prediction is called on an empty kNN classifier)
*/
oneof DefaultClassLabel {
string defaultStringLabel = 110;
int64 defaultInt64Label = 111;
}
/**
* Weighting scheme to be used when computing the majority label of a
* new data point.
*/
oneof WeightingScheme {
UniformWeighting uniformWeighting = 200;
InverseDistanceWeighting inverseDistanceWeighting = 210;
}
}
/**
* The "core" attributes of a Nearest Neighbors model.
*/
message NearestNeighborsIndex {
/**
* Number of dimensions of the input data.
*/
int32 numberOfDimensions = 1;
/**
* Vector of floating point data that makes up the model. Each data point must have 'numberOfDimensions'
* dimensions.
*/
repeated FloatVector floatSamples = 2;
/**
* Backing data structure for the Nearest Neighbors Index. Currently supports
* a linear index or a kd-tree index.
*/
oneof IndexType {
LinearIndex linearIndex = 100;
SingleKdTreeIndex singleKdTreeIndex = 110;
}
/**
* Distance function to be used to find neighbors. Currently only Squared Euclidean
* Distance is supported.
*/
oneof DistanceFunction {
SquaredEuclideanDistance squaredEuclideanDistance = 200;
}
}
/**
* Specifies a uniform weighting scheme (i.e. each neighbor receives equal
* voting power).
*/
message UniformWeighting {
}
/**
* Specifies a inverse-distance weighting scheme (i.e. closest neighbors receives higher
* voting power). A nearest neighbor with highest sum of (1 / distance) is picked.
*/
message InverseDistanceWeighting {
}
/**
* Specifies a flat index of data points to be searched by brute force.
*/
message LinearIndex {
}
/**
* Specifies a kd-tree backend for the nearest neighbors model.
*/
message SingleKdTreeIndex {
/**
* Number of data points contained within a leaf node of the kd-tree.
*/
int32 leafSize = 1;
}
/**
* Specifies the Squared Euclidean Distance function.
*/
message SquaredEuclideanDistance {
}

View file

@ -1,187 +0,0 @@
// Copyright (c) 2018, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/*
* Non-maximum suppression of axis-aligned bounding boxes.
*
* This is used primarily for object detectors that tend to produce multiple
* boxes around a single object. This is a byproduct of the detector's
* robustness to spatial translation. If there are two or more bounding boxes
* that are very similar to one another, the algorithm should return only a
* single representative.
*
* Similarity between two bounding boxes is measured by intersection-over-union
* (IOU), the fraction between the area of intersection and area of the union.
* Here is an example where the areas can be calculated by hand by counting glyphs::
*
* +-------+ +-------+
* | | | |
* | +------+ +--+ | +---+
* | | | | | | | |
* +-------+ | +--+ +----+ |
* | | | |
* +------+ +------+
* Intersection Union
* IOU: 0.16 = 12 / 73
*
* All IOU scores are fractions betwen 0.0 (fully disjoint) and 1.0 (perfect
* overlap). The standard algorithm (PickTop) is defined as follows:
*
* 1. Sort boxes by descending order of confidence
* 2. Take the top one and mark it as keep
* 3. Suppress (mark it as discard) all boxes within a fixed IOU radius of the
* keep box
* 4. Go to 2 and repeat on the subset of boxes not already kept or discarded
* 5. When all boxes are processed, output only the ones marked as keep
*
* Before the algorithm, boxes that fall below the confidence threshold are
* discarded.
*/
message NonMaximumSuppression {
// Suppression methods:
/*
* Pick the bounding box of the top confidence, suppress all within a radius.
*/
message PickTop {
/*
* Suppression is only done among predictions with the same label
* (argmax of the confidence).
*/
bool perClass = 1;
}
/*
* Choose which underlying suppression method to use
*/
oneof SuppressionMethod {
PickTop pickTop = 1;
}
/*
* Optional class label mapping.
*/
oneof ClassLabels {
StringVector stringClassLabels = 100;
Int64Vector int64ClassLabels = 101;
}
/*
* This defines the radius of suppression. A box is considered to be within
* the radius of another box if their IOU score is less than this value.
*/
double iouThreshold = 110;
/*
* Remove bounding boxes below this threshold. The algorithm run-time is
* proportional to the square of the number of incoming bounding boxes
* (O(N^2)). This threshold is a way to reduce N to make the algorithm
* faster. The confidence threshold can be any non-negative value. Negative
* confidences are not allowed, since if the output shape is specified to be
* larger than boxes after suppression, the unused boxes are filled with
* zero confidence. If the prediction is handled by Core Vision, it is also
* important that confidences are defined with the following semantics:
*
* 1. Confidences should be between 0 and 1
* 2. The sum of the confidences for a prediction should not exceed 1, but is
* allowed to be less than 1
* 3. The sum of the confidences will be interpreted as the confidence of
* any object (e.g. if the confidences for two classes are 0.2 and 0.4,
it means there is a 60% (0.2 + 0.4) confidence that an object is
present)
*/
double confidenceThreshold = 111;
/*
* Set the name of the confidence input.
*
* The input should be a multi-array of type double and shape N x C. N is
* the number of boxes and C the number of classes. Each row describes the
* confidences of each object category being present at that particular
* location. Confidences should be nonnegative, where 0.0 means the highest
* certainty the object is not present.
*
* Specifying shape is optional.
*/
string confidenceInputFeatureName = 200;
/*
* Set the name of the coordinates input.
*
* The input should be a multi-array of type double and shape N x 4. The
* rows correspond to the rows of the confidence matrix. The four values
* describe (in order):
*
* - x (center location of the box along the horizontal axis)
* - y (center location of the box along the vertical axis)
* - width (size of box along the horizontal axis)
* - height (size of box on along the vertical axis)
*
* Specifying shape is optional.
*/
string coordinatesInputFeatureName = 201;
/*
* The iouThreshold can be optionally overridden by specifying this string
* and providing a corresponding input of type double. This allows changing
* the value of the parameter during run-time.
*
* The input should be a scalar double between 0.0 and 1.0. Setting it to 1.0
* means there will be no suppression based on IOU.
*/
string iouThresholdInputFeatureName = 202;
/*
* The confidenceThreshold can be optionally overridden by specifying this
* string and providing a corresponding input. This allows changing the
* value of the parameter during run-time, which can aid setting it just
* right for a particular use case.
*
* The input should be a scalar double with nonnegative value.
*/
string confidenceThresholdInputFeatureName = 203;
/*
* Set the name of the confidence output. The output will be the same type
* and shape as the corresponding input. The only difference is that the
* number of rows may have been reduced.
*
* Specifying shape is optional. One reason to specify shape is to limit
* the number of output boxes. This can be done is several ways:
*
* Fixed shape:
* The output can be pinned to a fixed set of boxes. If this number is larger
* than the number of boxes that would have been returned, the output is padded
* with zeros for both confidence and coordinates. Specifying a fixed shape
* can be done by setting either shape (deprecated) or allowedShapes set to
* fixedsize.
*
* Min/max:
* It is also possible to set both a minimum and a maximum. The same zero-padding
* as for fixed shape is applied when necessary. Setting min/max is done by defining
* two allowedShapes, where the first dimension uses a rangeofsizes defining lowerbound
* and upperbound.
*/
string confidenceOutputFeatureName = 210;
/*
* Set the name of the coordinates output. The output will be the same type
* and shape as the corresponding input. The only difference is that the
* number of rows may have been reduced.
*
* Specifying shape is optional. See confidence output for a more detailed
* description. Note that to achieve either fixed shape output or a
* constraint range of boxes, only one of confidence or coordinates need to
* set a shape. Both shapes are allowed to be defined, but in such case they
* have to be consistent along dimension 0.
*/
string coordinatesOutputFeatureName = 211;
}

View file

@ -1,38 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* A normalization preprocessor.
*/
message Normalizer {
/**
* There are three normalization modes,
* which have the corresponding formulas:
*
* Max
* .. math::
* max(x_i)
*
* L1
* .. math::
* z = ||x||_1 = \sum_{i=1}^{n} |x_i|
*
* L2
* .. math::
* z = ||x||_2 = \sqrt{\sum_{i=1}^{n} x_i^2}
*/
enum NormType {
LMax = 0;
L1 = 1;
L2 = 2;
}
NormType normType = 1;
}

View file

@ -1,41 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
* Transforms a categorical feature into an array. The array will be all
* zeros expect a single entry of one.
*
* Each categorical value will map to an index, this mapping is given by
* either the ``stringCategories`` parameter or the ``int64Categories``
* parameter.
*/
message OneHotEncoder {
enum HandleUnknown {
ErrorOnUnknown = 0;
IgnoreUnknown = 1; // Output will be all zeros for unknown values.
}
/**
* Mapping to be used for the encoding. The position of the category in
* the below vector determines where the single one entry will be in the
* output.
*/
oneof CategoryType {
StringVector stringCategories = 1;
Int64Vector int64Categories = 2;
}
// Output can be a dictionary with only one entry, instead of an array.
bool outputSparse = 10;
HandleUnknown handleUnknown = 11;
}

View file

@ -1,52 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
* Int64 parameter,
* consisting of a default int64 value, and allowed range or set of values
* value is unbounded if AllowedValues is not set.
*/
message Int64Parameter {
int64 defaultValue = 1;
oneof AllowedValues {
Int64Range range = 10;
Int64Set set = 11;
}
}
/**
* Double parameter,
* consisting of a default double value, and allowed range of values
* value is unbounded if AllowedValues is not set.
*/
message DoubleParameter {
double defaultValue = 1;
oneof AllowedValues {
DoubleRange range = 10;
}
}
/**
* String parameter,
* A default string value must be provided
*/
message StringParameter {
string defaultValue = 1;
}
/**
* String parameter,
* A default bool value must be provided
*/
message BoolParameter {
bool defaultValue = 1;
}

View file

@ -1,16 +0,0 @@
# Core ML Model Format Specification
This directory contains the protobuf message definitions that comprise the Core ML model document (``.mlmodel``) format.
The top-level message is ``Model``, which is defined in ``Model.proto``.
Other message types describe data structures, feature types, feature engineering model types, and predictive model types.
# Update the Core ML Model Format Specification
Please do not modify protobuf message definitions, they are copied directly from [Core ML Tools](https://github.com/apple/coremltools) repository.
To update the Core ML Model Format Schema schema files to a more recent version:
1. Delete all the protobuf message definitions (`.proto`) from this directory.
2. Copy the new version of protobuf message definitions (`.proto`) from the `mlmodel/format/` directory of preferred coremltools release branch.
# Core ML Model Format Schema version history
## [coremltools 4.0](https://github.com/apple/coremltools/releases/tag/4.0)
[Core ML Model Format Specification](https://github.com/apple/coremltools/tree/4.0/mlmodel/format)

View file

@ -1,195 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/// Kernel Definitions
/// ------------------
/**
* A linear kernel.
*
* This function has the following formula:
*
* .. math::
* K(\boldsymbol{x}, \boldsymbol{x'}) = \boldsymbol{x}^T \boldsymbol{x'}
*/
message LinearKernel {
}
/**
* A Gaussian radial basis function (RBF) kernel.
*
* This function has the following formula:
*
* .. math::
* K(\boldsymbol{x}, \boldsymbol{x'}) = \
* \exp(-\gamma || \boldsymbol{x} - \boldsymbol{x'} ||^2 )
*
*/
message RBFKernel {
double gamma = 1;
}
/**
* A polynomial kernel.
*
* This function has the following formula:
*
* .. math::
* K(\boldsymbol{x}, \boldsymbol{x'}) = \
* (\gamma \boldsymbol{x}^T \boldsymbol{x'} + c)^{degree}
*/
message PolyKernel {
int32 degree = 1;
double c = 2;
double gamma = 3;
}
/**
* A sigmoid kernel.
*
* This function has the following formula:
*
* .. math::
* K(\boldsymbol{x}, \boldsymbol{x'}) = \
* \tanh(\gamma \boldsymbol{x}^T \boldsymbol{x'} + c)
*/
message SigmoidKernel {
double gamma = 1;
double c = 2;
}
/**
* A kernel.
*/
message Kernel {
oneof kernel {
LinearKernel linearKernel = 1;
RBFKernel rbfKernel = 2;
PolyKernel polyKernel = 3;
SigmoidKernel sigmoidKernel = 4;
}
}
/// Support Vector Definitions
/// --------------------------
/**
* A sparse node.
*/
message SparseNode {
int32 index = 1; // 1-based indexes, like libsvm
double value = 2;
}
/**
* A sparse vector.
*/
message SparseVector {
repeated SparseNode nodes = 1;
}
/**
* One or more sparse support vectors.
*/
message SparseSupportVectors {
repeated SparseVector vectors = 1;
}
/**
* A dense vector.
*/
message DenseVector {
repeated double values = 1;
}
/**
* One or more dense support vectors.
*/
message DenseSupportVectors {
repeated DenseVector vectors = 1;
}
/**
* One or more coefficients.
*/
message Coefficients {
repeated double alpha = 1;
}
/**
* A support vector regressor.
*/
message SupportVectorRegressor {
Kernel kernel = 1;
// Support vectors, either sparse or dense format
oneof supportVectors {
SparseSupportVectors sparseSupportVectors = 2;
DenseSupportVectors denseSupportVectors = 3;
}
// Coefficients, one for each support vector
Coefficients coefficients = 4;
double rho = 5;
}
/**
* A support vector classifier
*/
message SupportVectorClassifier {
Kernel kernel = 1;
/**
* The number of support vectors for each class.
*/
repeated int32 numberOfSupportVectorsPerClass = 2;
/**
* The support vectors, in either sparse or dense format.
*/
oneof supportVectors {
SparseSupportVectors sparseSupportVectors = 3;
DenseSupportVectors denseSupportVectors = 4;
}
/**
* The coefficients, essentially a two dimensional array of
* size: (numberOfClasses-1) by (total number of support vectors)
*/
repeated Coefficients coefficients = 5;
/**
* Constants for decision function,
* with K*(K-1) / 2 elements,
* where K is the number of classes.
*/
repeated double rho = 6;
/**
* Pairwise probability information for A vs B classifier.
* Total of K*(K-1)/2 elements where K is the number of classes.
* These fields are optional,
* and only required if you want probabilities or multi class predictions.
*/
repeated double probA = 7;
repeated double probB = 8;
/**
* Class label mapping.
*/
oneof ClassLabels {
StringVector stringClassLabels = 100;
Int64Vector int64ClassLabels = 101;
}
}

View file

@ -1,34 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification;
/**
* A scaling operation.
*
* This function has the following formula:
*
* .. math::
* f(x) = scaleValue \cdot (x + shiftValue)
*
* If the ``scaleValue`` is not given, the default value 1 is used.
* If the ``shiftValue`` is not given, the default value 0 is used.
*
* If ``scaleValue`` and ``shiftValue`` are each a single value
* and the input is an array, then the scale and shift are applied
* to each element of the array.
*
* If the input is an integer, then it is converted to a double to
* perform the scaling operation. If the output type is an integer,
* then it is cast to an integer. If that cast is lossy, then an
* error is generated.
*/
message Scaler {
repeated double shiftValue = 1;
repeated double scaleValue = 2;
}

View file

@ -1,60 +0,0 @@
// Copyright (c) 2019, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification.CoreMLModels;
/**
* A model which takes audio signal samples as input and outputs an array of
* preprocessed samples according to the specified preprocessing types
*/
message SoundAnalysisPreprocessing {
// Specific preprocessing types for sound analysis
/* Vggish preprocesses input audio samples and makes them ready to
be fed to Vggish feature extractor.
c.f. https://arxiv.org/pdf/1609.09430.pdf
The preprocessing takes input a single channel (monophonic) audio samples
975 miliseconds long, sampled at 16KHz, i.e., 15600 samples 1D multiarray
and produces preprocessed samples in multiarray of shape [1, 96, 64]
(1) Splits the input audio samples into overlapping frames, where each
frame is 25 milliseconds long and hops forward by 10 milliseconds.
Any partial frames at the end are dropped.
(2) Hann window: apply a periodic Hann with a window_length of
25 milliseconds, which translates to 400 samples in 16KHz sampling rate
w(n) = 0.5 - 0.5 * cos(2*pi*n/window_length_sample),
where 0 <= n <= window_lenth_samples - 1 and window_lenth_samples = 400
Then, the Hann window is applied to each frame as below
windowed_frame(n) = frame(n) * w(n)
where 0 <= n <= window_lenth_samples - 1 and window_lenth_samples = 400
(3) Power spectrum: calculate short-time Fourier transfor magnitude, with
an FFT length of 512
(4) Log Mel filter bank: calculates a log magnitude mel-frequency
spectrogram minimum frequency of 125Hz and maximum frequency of 7500Hz,
number of mel bins is 64, log_offset is 0.01, number of spectrum bins
is 64.
*/
message Vggish {
// no specific parameter
}
// Vision feature print type
oneof SoundAnalysisPreprocessingType {
Vggish vggish = 20;
}
}

View file

@ -1,43 +0,0 @@
// Copyright (c) 2018, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification.CoreMLModels;
/**
* A model which takes a single input string and outputs a
* label for the input.
*/
message TextClassifier {
/*
* Stores the resivion number for the model, revision 1 is available on
* iOS, tvOS 12.0+, macoOS 10.14+
*/
uint32 revision = 1;
/*
* Stores the language of the model, as specified in BCP-47 format,
* e.g. "en-US". See https://tools.ietf.org/html/bcp47
*/
string language = 10;
/*
* Stores the byte representation of learned model parameters
*/
bytes modelParameterData = 100;
/*
* Stores the set of output class labels
*/
oneof ClassLabels {
StringVector stringClassLabels = 200;
}
}

View file

@ -1,161 +0,0 @@
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
/**
* Each tree is a collection of nodes,
* each of which is identified by a unique identifier.
*
* Each node is either a branch or a leaf node.
* A branch node evaluates a value according to a behavior;
* if true, the node identified by ``true_child_node_id`` is evaluated next,
* if false, the node identified by ``false_child_node_id`` is evaluated next.
* A leaf node adds the evaluation value to the base prediction value
* to get the final prediction.
*
* A tree must have exactly one root node,
* which has no parent node.
* A tree must not terminate on a branch node.
* All leaf nodes must be accessible
* by evaluating one or more branch nodes in sequence,
* starting from the root node.
*/
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
* A tree ensemble post-evaluation transform.
*/
enum TreeEnsemblePostEvaluationTransform {
NoTransform = 0;
Classification_SoftMax = 1;
Regression_Logistic = 2;
Classification_SoftMaxWithZeroClassReference = 3;
}
/**
* Tree ensemble parameters.
*/
message TreeEnsembleParameters {
message TreeNode {
uint64 treeId = 1;
uint64 nodeId = 2;
enum TreeNodeBehavior {
BranchOnValueLessThanEqual = 0;
BranchOnValueLessThan = 1;
BranchOnValueGreaterThanEqual = 2;
BranchOnValueGreaterThan = 3;
BranchOnValueEqual = 4;
BranchOnValueNotEqual = 5;
LeafNode = 6;
}
/**
* The branch mode parameters.
*
* If branch is false,
* then the parameters in this section must be filled in
* to determine how the branching functions.
*/
TreeNodeBehavior nodeBehavior = 3;
/**
* If the node behavior mode is a branch mode,
* then these values must be filled in.
*/
uint64 branchFeatureIndex = 10;
double branchFeatureValue = 11;
uint64 trueChildNodeId = 12;
uint64 falseChildNodeId = 13;
bool missingValueTracksTrueChild = 14;
/**
* The leaf mode.
*
* If ``nodeBahavior`` == ``LeafNode``,
* then the evaluationValue is added to the base prediction value
* in order to get the final prediction.
* To support multiclass classification
* as well as regression and binary classification,
* the evaluation value is encoded here as a sparse vector,
* with evaluationIndex being the index of the base vector
* that evaluation value is added to.
* In the single class case,
* it is expected that evaluationIndex is exactly 0.
*/
message EvaluationInfo {
uint64 evaluationIndex = 1;
double evaluationValue = 2;
}
repeated EvaluationInfo evaluationInfo = 20;
/**
* The relative hit rate of a node for optimization purposes.
*
* This value has no effect on the accuracy of the result;
* it allows the tree to optimize for frequent branches.
* The value is relative,
* compared to the hit rates of other branch nodes.
*
* You typically use a proportion of training samples
* that reached this node
* or some similar metric to derive this value.
*/
double relativeHitRate = 30;
}
repeated TreeNode nodes = 1;
/**
* The number of prediction dimensions or classes in the model.
*
* All instances of ``evaluationIndex`` in a leaf node
* must be less than this value,
* and the number of values in the ``basePredictionValue`` field
* must be equal to this value.
*
* For regression,
* this is the dimension of the prediction.
* For classification,
* this is the number of classes.
*/
uint64 numPredictionDimensions = 2;
/**
* The base prediction value.
*
* The number of values in this must match
* the default values of the tree model.
*/
repeated double basePredictionValue = 3;
}
/**
* A tree ensemble classifier.
*/
message TreeEnsembleClassifier {
TreeEnsembleParameters treeEnsemble = 1;
TreeEnsemblePostEvaluationTransform postEvaluationTransform = 2;
// Required class label mapping
oneof ClassLabels {
StringVector stringClassLabels = 100;
Int64Vector int64ClassLabels = 101;
}
}
/**
* A tree ensemble regressor.
*/
message TreeEnsembleRegressor {
TreeEnsembleParameters treeEnsemble = 1;
TreeEnsemblePostEvaluationTransform postEvaluationTransform = 2;
}

View file

@ -1,63 +0,0 @@
// Copyright (c) 2018, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package CoreML.Specification.CoreMLModels;
/**
* A model which takes an input image and outputs array(s) of features
* according to the specified feature types
*/
message VisionFeaturePrint {
// Specific vision feature print types
// Scene extracts features useful for identifying contents of natural images
// in both indoor and outdoor environments
message Scene {
enum SceneVersion {
SCENE_VERSION_INVALID = 0;
// VERSION_1 is available on iOS,tvOS 12.0+, macOS 10.14+
// It uses a 299x299 input image and yields a 2048 float feature vector
SCENE_VERSION_1 = 1;
}
SceneVersion version = 1;
}
// Objects extracts features useful for identifying and localizing
// objects in natural images
message Objects {
enum ObjectsVersion {
OBJECTS_VERSION_INVALID = 0;
// VERSION_1 is available on iOS,tvOS 14.0+, macOS 11.0+
// It uses a 299x299 input image and yields two multiarray
// features: one at high resolution of shape (288, 35, 35)
// the other at low resolution of shape (768, 17, 17)
OBJECTS_VERSION_1 = 1;
}
ObjectsVersion version = 1;
/*
* Stores the names of the output features according to the
* order of them being computed from the neural network, i.e.,
* the first element in the output is the earliest being
* computed, while the last is the latest being computed. In
* general, the order reflects the resolution of the feature.
* The earlier it is computed, the higher the feature resolution.
*/
repeated string output = 100;
}
// Vision feature print type
oneof VisionFeaturePrintType {
Scene scene = 20;
Objects objects = 21;
}
}

View file

@ -1,35 +0,0 @@
// Copyright (c) 2019, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification.CoreMLModels;
/**
* A model which maps a set of strings into a finite-dimensional real vector space.
*/
message WordEmbedding {
/*
* Stores the revision number for the model, revision 2 is available on
* iOS, tvOS 13.0+, macOS 10.15+
*/
uint32 revision = 1;
/*
* Stores the language of the model, as specified in BCP-47 format,
* e.g. "en-US". See https://tools.ietf.org/html/bcp47
*/
string language = 10;
/*
* Stores efficient representation of emebedding as encoded by the Natural Language Framework
*/
bytes modelParameterData = 100;
}

View file

@ -1,75 +0,0 @@
// Copyright (c) 2018, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification.CoreMLModels;
/**
* A model which takes a single input string and outputs a
* sequence of tokens, tags for tokens, along with their
* locations and lengths, in the original string.
*/
message WordTagger {
/*
* Stores the resivion number for the model, revision 1 is available on
* iOS, tvOS 12.0+, macoOS 10.14+
*/
uint32 revision = 1;
/*
* Stores the language of the model, as specified in BCP-47 format,
* e.g. "en-US". See https://tools.ietf.org/html/bcp47
*/
string language = 10;
/*
* Stores the name of tokens output. The output will be
* a sequence of strings that contains the tokens in the
* input string
*/
string tokensOutputFeatureName = 20;
/*
* Stores the name of token tags output. The output will be
* a sequence of strings that contains the tags for each
* token in the input string
*/
string tokenTagsOutputFeatureName = 21;
/*
* Stores the name of token locations output. The output will be
* a sequence of integers that contains the locations (indices)
* for each token in the input string, location starts from 0
*/
string tokenLocationsOutputFeatureName = 22;
/*
* Stores the name of token lengths output. The output will be
* a sequence of integers that contains the lengths for each
* token in the input string
*/
string tokenLengthsOutputFeatureName = 23;
/*
* Stores the byte representation of learned model parameters
*/
bytes modelParameterData = 100;
/*
* Stores the set of output tags
*/
oneof Tags {
StringVector stringTags = 200;
}
}

View file

@ -11,7 +11,7 @@ steps:
packageType: upack
feed: '/7424c8e4-5c62-490e-95c4-79446f31017c'
definition: '517c4f6f-5437-4392-a70d-4f15ec5be2f0'
version: 1.0.132
version: 1.0.133
downloadPath: $(Build.BinariesDirectory)/deps
# The private ADO project
@ -22,7 +22,7 @@ steps:
packageType: upack
feed: '/4c7631f5-24c0-4307-8822-1aa8f180c325'
definition: 'fd9dd5ad-b73e-4678-890e-edcf680dbc1a'
version: 1.0.132
version: 1.0.133
downloadPath: $(Build.BinariesDirectory)/deps
# You can add more ADO accounts at here.