Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test_py37_pytorch:
WHEEL_PATH: build/dist/*cp37*10_15*

test_py37_tf1:
<<: *test_macos_pkg
<<: *test_macos_pkg_with_reqs
tags:
- macos12
dependencies:
Expand All @@ -107,9 +107,10 @@ test_py37_tf1:
PYTHON: "3.7"
TEST_PACKAGE: coremltools.converters.mil.frontend.tensorflow
WHEEL_PATH: build/dist/*cp37*10_15*
REQUIREMENTS: reqs/test_tf1.pip

test_py37_tf2:
<<: *test_macos_pkg_with_reqs
<<: *test_macos_pkg
tags:
- macos12
dependencies:
Expand All @@ -118,7 +119,6 @@ test_py37_tf2:
PYTHON: "3.7"
TEST_PACKAGE: coremltools.converters.mil.frontend.tensorflow2
WHEEL_PATH: build/dist/*cp37*10_15*
REQUIREMENTS: reqs/test_tf2.pip

test_py37_mil:
<<: *test_macos_pkg
Expand Down
17 changes: 6 additions & 11 deletions coremltools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
from enum import Enum as _Enum
from logging import getLogger as _getLogger


# Backup root logger handlers
_root_logger = _getLogger()
_root_logger_handlers_backup = _root_logger.handlers.copy()

from .version import __version__

_logger = _getLogger(__name__)

# This is the basic Core ML specification format understood by iOS 11.0
SPECIFICATION_VERSION = 1

Expand Down Expand Up @@ -63,6 +60,9 @@
# New versions for iOS 16.0
_SPECIFICATION_VERSION_IOS_16 = 7

# New versions for iOS 17.0
_SPECIFICATION_VERSION_IOS_17 = 8

class ComputeUnit(_Enum):
'''
The set of processing-unit configurations the model can use to make predictions.
Expand All @@ -79,6 +79,7 @@ class ComputeUnit(_Enum):
_SPECIFICATION_VERSION_IOS_14: "CoreML4",
_SPECIFICATION_VERSION_IOS_15: "CoreML5",
_SPECIFICATION_VERSION_IOS_16: "CoreML6",
_SPECIFICATION_VERSION_IOS_17: "CoreML7",
}

# Default specification version for each backend
Expand Down Expand Up @@ -122,9 +123,3 @@ class ComputeUnit(_Enum):

if _ENABLE_PROFILING:
_sys.setprofile(_profiler)

# Restore root logger handlers
_root_logger = _getLogger()
_coreml_logger = _getLogger(__name__)
_coreml_logger.handlers = _root_logger.handlers.copy()
_root_logger.handlers = _root_logger_handlers_backup
18 changes: 10 additions & 8 deletions coremltools/_deps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
List of all external dependancies for this package. Imported as
optional includes
"""
from distutils.version import StrictVersion as _StrictVersion
import logging as _logging
from packaging import version
import platform as _platform
import re as _re
import sys as _sys
from distutils.version import StrictVersion as _StrictVersion

from packaging import version

from coremltools import _logger as logger


def _get_version(version):
Expand All @@ -24,7 +26,7 @@ def _get_version(version):

def _warn_if_above_max_supported_version(package_name, package_version, max_supported_version):
if _get_version(package_version) > _StrictVersion(max_supported_version):
_logging.warning(
logger.warning(
"%s version %s has not been tested with coremltools. You may run into unexpected errors. "
"%s %s is the most recent version that has been tested."
% (package_name, package_version, package_name, max_supported_version)
Expand Down Expand Up @@ -64,7 +66,7 @@ def __get_sklearn_version(version):
_SKLEARN_MIN_VERSION
) or _SKLEARN_VERSION > _StrictVersion(_SKLEARN_MAX_VERSION):
_HAS_SKLEARN = False
_logging.warning(
logger.warning(
(
"scikit-learn version %s is not supported. Minimum required version: %s. "
"Maximum required version: %s. "
Expand Down Expand Up @@ -100,7 +102,7 @@ def __get_sklearn_version(version):
_TF_1_MIN_VERSION = "1.12.0"
_TF_1_MAX_VERSION = "1.15.4"
_TF_2_MIN_VERSION = "2.1.0"
_TF_2_MAX_VERSION = "2.8.0"
_TF_2_MAX_VERSION = "2.10.0"

try:
import tensorflow
Expand All @@ -116,7 +118,7 @@ def __get_sklearn_version(version):

if _HAS_TF_1:
if tf_ver < _StrictVersion(_TF_1_MIN_VERSION):
_logging.warning(
logger.warning(
(
"TensorFlow version %s is not supported. Minimum required version: %s ."
"TensorFlow conversion will be disabled."
Expand All @@ -126,7 +128,7 @@ def __get_sklearn_version(version):
_warn_if_above_max_supported_version("TensorFlow", tensorflow.__version__, _TF_1_MAX_VERSION)
elif _HAS_TF_2:
if tf_ver < _StrictVersion(_TF_2_MIN_VERSION):
_logging.warn(
logger.warning(
(
"TensorFlow version %s is not supported. Minimum required version: %s ."
"TensorFlow conversion will be disabled."
Expand Down
47 changes: 20 additions & 27 deletions coremltools/converters/_converters_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,42 @@
import collections
import gc
import os
import warnings

from coremltools import (
ComputeUnit as _ComputeUnit,
__version__ as _ct_version,
_LOWEST_ALLOWED_SPECIFICATION_VERSION_FOR_NEURALNETWORK,
_LOWEST_ALLOWED_SPECIFICATION_VERSION_FOR_MILPROGRAM,
)
from coremltools.converters.mil.mil.passes.quantization_passes import (
AbstractQuantizationPass,
ComputePrecision as precision,
FP16ComputePrecision
)
from coremltools.converters.mil.input_types import (
ClassifierConfig,
ImageType,
InputType,
TensorType,
)
_LOWEST_ALLOWED_SPECIFICATION_VERSION_FOR_NEURALNETWORK)
from coremltools import ComputeUnit as _ComputeUnit
from coremltools import __version__ as _ct_version
from coremltools._deps import _HAS_TF_1, _HAS_TF_2, _HAS_TORCH
from coremltools.converters._profile_utils import _profile
from coremltools.converters.mil._deployment_compatibility import (
AvailableTarget, check_deployment_compatibility)
from coremltools.converters.mil.converter import mil_convert
from coremltools.converters.mil.input_types import (ClassifierConfig,
ImageType, InputType,
TensorType)
from coremltools.converters.mil.mil import Program, types
from coremltools._deps import _HAS_TORCH, _HAS_TF_1, _HAS_TF_2
from coremltools.converters._profile_utils import _profile

from coremltools.models import _METADATA_VERSION, _METADATA_SOURCE
from coremltools.converters.mil.mil.passes.quantization_passes import \
ComputePrecision as precision
from coremltools.converters.mil.mil.passes.quantization_passes import \
FP16ComputePrecision
from coremltools.models import _METADATA_SOURCE, _METADATA_VERSION
from coremltools.models.utils import _MLPACKAGE_EXTENSION
from coremltools.converters.mil._deployment_compatibility import (
AvailableTarget,
check_deployment_compatibility,
)

if _HAS_TF_1:
import tensorflow as tf

from coremltools.converters.mil.frontend.tensorflow.load import TF1Loader
if _HAS_TF_2:
import tensorflow as tf

from coremltools.converters.mil.frontend.tensorflow2.load import TF2Loader

if _HAS_TORCH:
import torch
from coremltools.converters.mil.frontend.torch.load import (
_torchscript_from_model as pytorch_load,
)

from coremltools.converters.mil.frontend.torch.load import \
_torchscript_from_model as pytorch_load

@_profile
def convert(
Expand Down
4 changes: 1 addition & 3 deletions coremltools/converters/libsvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
# found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause


from . import _libsvm_converter
from . import _libsvm_util

from ..._deps import _HAS_LIBSVM
from . import _libsvm_converter, _libsvm_util

if _HAS_LIBSVM:
from libsvm import svmutil as _svmutil
Expand Down
10 changes: 5 additions & 5 deletions coremltools/converters/libsvm/_libsvm_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# Use of this source code is governed by a BSD-3-clause license that can be
# found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause

from coremltools import __version__ as ct_version
from coremltools.models import _METADATA_SOURCE, _METADATA_VERSION

from ... import SPECIFICATION_VERSION
from ..._deps import _HAS_LIBSVM
from coremltools import __version__ as ct_version
from coremltools.models import _METADATA_VERSION, _METADATA_SOURCE


def _infer_min_num_features(model):
Expand Down Expand Up @@ -55,10 +56,9 @@ def convert(libsvm_model, feature_names, target, input_length, probability):
raise RuntimeError("libsvm not found. libsvm conversion API is disabled.")

from libsvm import svm as _svm
from ...proto import SVM_pb2
from ...proto import Model_pb2
from ...proto import FeatureTypes_pb2

from ...models import MLModel
from ...proto import Model_pb2

svm_type_enum = libsvm_model.param.svm_type

Expand Down
3 changes: 2 additions & 1 deletion coremltools/converters/libsvm/_libsvm_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def load_model(model_path):
if not (_HAS_LIBSVM):
raise RuntimeError("libsvm not found. libsvm conversion API is disabled.")

from svmutil import svm_load_model # From libsvm
import os

from svmutil import svm_load_model # From libsvm

if not os.path.exists(model_path):
raise IOError("Expected a valid file path. %s does not exist" % model_path)
return svm_load_model(model_path)
50 changes: 10 additions & 40 deletions coremltools/converters/mil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,14 @@
# Use of this source code is governed by a BSD-3-clause license that can be
# found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause

from .mil import (
Block,
builder,
Builder,
curr_block,
DefaultInputs,
Function,
get_existing_symbol,
get_new_symbol,
get_new_variadic_symbol,
InputSpec,
InternalVar,
ListInputType,
ListVar,
mil_list,
Operation,
Placeholder,
Program,
register_op,
SPACES,
SUPPORT_FLOAT_TYPES,
SUPPORT_INT_TYPES,
Symbol,
TupleInputType,
Var,
)

from .frontend.torch import register_torch_op

from .input_types import (
ClassifierConfig,
ColorLayout,
InputType,
TensorType,
ImageType,
RangeDim,
Shape,
EnumeratedShapes,
)

from coremltools.converters.mil.frontend.tensorflow.tf_op_registry import register_tf_op
from .mil import (SPACES, SUPPORT_FLOAT_TYPES, SUPPORT_INT_TYPES, Block,
Builder, DefaultInputs, Function, InputSpec, InternalVar,
ListInputType, ListVar, Operation, Placeholder, Program,
Symbol, TupleInputType, Var, builder, curr_block,
get_existing_symbol, get_new_symbol, get_new_variadic_symbol,
mil_list, register_op)
from .input_types import (ClassifierConfig, ColorLayout, EnumeratedShapes,
ImageType, InputType, RangeDim, Shape, TensorType)
from .frontend.tensorflow.tf_op_registry import register_tf_op
from .frontend.torch import register_torch_op
15 changes: 9 additions & 6 deletions coremltools/converters/mil/_deployment_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

from enum import IntEnum

from coremltools import (
_SPECIFICATION_VERSION_IOS_13,
_SPECIFICATION_VERSION_IOS_14,
_SPECIFICATION_VERSION_IOS_15,
_SPECIFICATION_VERSION_IOS_16,
)
from coremltools import (_SPECIFICATION_VERSION_IOS_13,
_SPECIFICATION_VERSION_IOS_14,
_SPECIFICATION_VERSION_IOS_15,
_SPECIFICATION_VERSION_IOS_16,
_SPECIFICATION_VERSION_IOS_17)


class AvailableTarget(IntEnum):
Expand All @@ -19,6 +18,7 @@ class AvailableTarget(IntEnum):
iOS14 = _SPECIFICATION_VERSION_IOS_14
iOS15 = _SPECIFICATION_VERSION_IOS_15
iOS16 = _SPECIFICATION_VERSION_IOS_16
iOS17 = _SPECIFICATION_VERSION_IOS_17

# macOS versions (aliases of iOS versions)
macOS15 = _SPECIFICATION_VERSION_IOS_13
Expand All @@ -28,18 +28,21 @@ class AvailableTarget(IntEnum):
macOS11 = _SPECIFICATION_VERSION_IOS_14
macOS12 = _SPECIFICATION_VERSION_IOS_15
macOS13 = _SPECIFICATION_VERSION_IOS_16
macOS14 = _SPECIFICATION_VERSION_IOS_17

# watchOS versions (aliases of iOS versions)
watchOS6 = _SPECIFICATION_VERSION_IOS_13
watchOS7 = _SPECIFICATION_VERSION_IOS_14
watchOS8 = _SPECIFICATION_VERSION_IOS_15
watchOS9 = _SPECIFICATION_VERSION_IOS_16
watchOS10 = _SPECIFICATION_VERSION_IOS_17

# tvOS versions (aliases of iOS versions)
tvOS13 = _SPECIFICATION_VERSION_IOS_13
tvOS14 = _SPECIFICATION_VERSION_IOS_14
tvOS15 = _SPECIFICATION_VERSION_IOS_15
tvOS16 = _SPECIFICATION_VERSION_IOS_16
tvOS17 = _SPECIFICATION_VERSION_IOS_17

# customized __str__
def __str__(self):
Expand Down
4 changes: 3 additions & 1 deletion coremltools/converters/mil/backend/backend_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause

from coremltools.converters.mil.input_types import ColorLayout
from coremltools.converters.mil.mil.passes.name_sanitization_utils import NameSanitizer
from coremltools.converters.mil.mil.passes.name_sanitization_utils import \
NameSanitizer
from coremltools.proto import FeatureTypes_pb2 as ft


def _get_probability_var_for_classifier(prog, classifier_config):
'''
Return the var which will be used to construct the dictionary for the classifier.
Expand Down
14 changes: 6 additions & 8 deletions coremltools/converters/mil/backend/mil/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@

import numpy as np

from coremltools.converters.mil.mil import types
from coremltools.converters.mil.mil.types import builtin_to_proto_types
from coremltools.models.utils import _WEIGHTS_DIR_NAME, _WEIGHTS_FILE_NAME
import coremltools.proto.FeatureTypes_pb2 as ft
import coremltools.proto.MIL_pb2 as pm
from coremltools.converters.mil.mil.types import (
type_to_builtin_type,
numpy_type_to_builtin_type,
builtin_to_string
)
from coremltools.converters.mil.mil import types
from coremltools.converters.mil.mil.types import (builtin_to_proto_types,
builtin_to_string,
numpy_type_to_builtin_type,
type_to_builtin_type)
from coremltools.converters.mil.mil.types.type_mapping import np_val_to_py_type
from coremltools.models.utils import _WEIGHTS_DIR_NAME, _WEIGHTS_FILE_NAME


def create_valuetype_scalar(data_type):
Expand Down
Loading