Skip to content

Commit 973eae6

Browse files
authored
6.0b1 Release (#1508)
1 parent 6adf95b commit 973eae6

File tree

262 files changed

+8671
-31435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+8671
-31435
lines changed

.gitlab-ci.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ check_python_flake8:
3838
paths:
3939
- build/dist/
4040

41-
build_wheel_linux_py35:
42-
<<: *build_linux
43-
image: registry.gitlab.com/zach_nation/coremltools/build-image-ubuntu-18.04:1.0.0
44-
variables:
45-
PYTHON: "3.5"
46-
4741
build_wheel_linux_py36:
4842
<<: *build_linux
4943
image: registry.gitlab.com/zach_nation/coremltools/build-image-ubuntu-18.04:1.0.0
@@ -85,11 +79,6 @@ build_wheel_linux_py39:
8579
paths:
8680
- build/dist/
8781

88-
build_wheel_macos_py35:
89-
<<: *build_macos
90-
variables:
91-
PYTHON: "3.5"
92-
9382
build_wheel_macos_py36:
9483
<<: *build_macos
9584
variables:

.pylintrc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ ignore-on-opaque-inference=yes
316316
ignored-classes=
317317
optparse.Values,
318318
sympy.core.mul.Mul,
319-
test.model_zoo.onnx.test_latham_lstm.TestLathamLSTM,
320-
test.model_zoo.onnx.test_transformer.TestMT,
321319
thread._local,
322320
_thread._local
323321

@@ -328,7 +326,6 @@ ignored-classes=
328326
ignored-modules=
329327
LazyLoader,
330328
matplotlib.cm,
331-
onnx.onnx_*_ml_pb2,
332329
tensorflow,
333330
tensorflow.core.framework.*_pb2,
334331
tensorflow.tools.api.generator.api.contrib,

BUILDING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Follow these steps:
1919
1. Fork and clone the GitHub [coremltools repository](https://github.com/apple/coremltools).
2020

2121
2. Run the [build.sh](scripts/build.sh) script to build `coremltools`.
22-
* By default this script uses Python 3.7, but you can include `--python=3.5` (or `3.6`, `3.8`, and so on) as a argument to change the Python version.
22+
* By default this script uses Python 3.7, but you can include `--python=3.6` (or `3.7`, `3.8`, `3.9`) as a argument to change the Python version.
2323
* The script creates a new `build` folder with the coremltools distribution, and a `dist` folder with Python wheel files.
2424

2525
3. Run the [test.sh](scripts/test.sh) script to test the build.
@@ -45,7 +45,7 @@ The following build targets help you configure the development environment. If y
4545
* `test_slow` | Run all non-fast tests.
4646
* `wheel` | Build wheels in release mode.
4747

48-
The script uses Python 3.7, but you can include `--python=3.5` (or `3.6`, `3.8`, and so on) as a argument to change the Python version.
48+
The script uses Python 3.7, but you can include `--python=3.6` (or `3.7`, `3.8`, `3.9`) as a argument to change the Python version.
4949

5050
## Resources
5151

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Use *coremltools* to convert machine learning models from third-party libraries
1010
* [TensorFlow 1.x](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf)
1111
* [TensorFlow 2.x](https://www.tensorflow.org/api_docs)
1212
* [PyTorch](https://pytorch.org/)
13-
* [TensorFlow's Keras APIs](https://keras.io/)
1413
* Non-neural network frameworks:
1514
* [scikit-learn](https://scikit-learn.org/stable/)
1615
* [XGBoost](https://xgboost.readthedocs.io/en/latest/)

coremlpython/CoreMLPython.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace CoreML {
2626
Model& operator=(const Model&) = delete;
2727
~Model();
2828
explicit Model(const std::string& urlStr, const std::string& computeUnits);
29-
py::dict predict(const py::dict& input, bool useCPUOnly);
29+
py::dict predict(const py::dict& input);
3030
static py::bytes autoSetSpecificationVersion(const py::bytes& modelBytes);
3131
static int32_t maximumSupportedSpecificationVersion();
3232
std::string toString() const;

coremlpython/CoreMLPython.mm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,12 @@
7878
}
7979
}
8080

81-
py::dict Model::predict(const py::dict& input, bool useCPUOnly) {
81+
py::dict Model::predict(const py::dict& input) {
8282
@autoreleasepool {
8383
NSError *error = nil;
8484
MLDictionaryFeatureProvider *inFeatures = Utils::dictToFeatures(input, &error);
8585
Utils::handleError(error);
86-
MLPredictionOptions *options = [[MLPredictionOptions alloc] init];
87-
options.usesCPUOnly = useCPUOnly;
8886
id<MLFeatureProvider> outFeatures = [m_model predictionFromFeatures:static_cast<MLDictionaryFeatureProvider * _Nonnull>(inFeatures)
89-
options:options
9087
error:&error];
9188
Utils::handleError(error);
9289
return Utils::featuresToDict(outFeatures);

coremlpython/CoreMLPythonUtils.mm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ static size_t sizeOfArrayElement(MLMultiArrayDataType type) {
433433
case MLMultiArrayDataTypeInt32:
434434
return sizeof(int32_t);
435435
case MLMultiArrayDataTypeFloat32:
436+
case MLMultiArrayDataTypeFloat16:
436437
return sizeof(float);
437438
case MLMultiArrayDataTypeDouble:
438439
return sizeof(double);
@@ -449,7 +450,7 @@ static size_t sizeOfArrayElement(MLMultiArrayDataType type) {
449450
MLMultiArrayDataType type = value.dataType;
450451
std::vector<size_t> shape = Utils::convertNSArrayToCpp(value.shape);
451452
std::vector<size_t> strides = Utils::convertNSArrayToCpp(value.strides);
452-
453+
453454
// convert strides to numpy (bytes) instead of mlkit (elements)
454455
for (size_t& stride : strides) {
455456
stride *= sizeOfArrayElement(type);
@@ -460,6 +461,16 @@ static size_t sizeOfArrayElement(MLMultiArrayDataType type) {
460461
return py::array(shape, strides, static_cast<const int32_t*>(value.dataPointer));
461462
case MLMultiArrayDataTypeFloat32:
462463
return py::array(shape, strides, static_cast<const float*>(value.dataPointer));
464+
case MLMultiArrayDataTypeFloat16:
465+
{
466+
// create a float32 array, cast float16 values and copy into it
467+
// TODO: rdar://92239209 : return np.float16 instead of np.float32 when multiarray type is Float16
468+
std::vector<float> value_fp32(value.count, 0.0);
469+
for (size_t i=0; i<value.count; i++) {
470+
value_fp32[i] = [value[i] floatValue];
471+
}
472+
return py::array(shape, strides, value_fp32.data());
473+
}
463474
case MLMultiArrayDataTypeDouble:
464475
return py::array(shape, strides, static_cast<const double*>(value.dataPointer));
465476
default:

coremltools/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
Core MLTools in a python package for creating, examining, and testing models in the .mlmodel
1515
format. In particular, it can be used to:
1616
17-
* Convert existing models to .mlmodel format from popular machine learning tools including:
18-
Keras, scikit-learn, libsvm, and XGBoost.
17+
* Convert existing models to .mlpackage or .mlmodel formats from popular machine learning tools including:
18+
PyTorch, TensorFlow, scikit-learn, XGBoost and libsvm.
1919
* Express models in .mlmodel format through a simple API.
2020
* Make predictions with an .mlmodel (on select platforms for testing purposes).
2121
@@ -60,6 +60,9 @@
6060
# New versions for iOS 15.0
6161
_SPECIFICATION_VERSION_IOS_15 = 6
6262

63+
# New versions for iOS 16.0
64+
_SPECIFICATION_VERSION_IOS_16 = 7
65+
6366
class ComputeUnit(_Enum):
6467
'''
6568
The set of processing-unit configurations the model can use to make predictions.
@@ -68,16 +71,29 @@ class ComputeUnit(_Enum):
6871
CPU_AND_GPU = 2 # Allows the model to use both the CPU and GPU, but not the neural engine
6972
CPU_ONLY = 3 # Limit the model to only use the CPU
7073

74+
# A dictionary that maps the CoreML model specification version to the MLProgram/MIL opset string
75+
_OPSET = {
76+
_SPECIFICATION_VERSION_IOS_15: "CoreML5",
77+
_SPECIFICATION_VERSION_IOS_16: "CoreML6",
78+
}
79+
80+
# Default specification version for each backend
81+
_LOWEST_ALLOWED_SPECIFICATION_VERSION_FOR_NEURALNETWORK = _SPECIFICATION_VERSION_IOS_13
82+
_LOWEST_ALLOWED_SPECIFICATION_VERSION_FOR_MILPROGRAM = _SPECIFICATION_VERSION_IOS_15
83+
84+
7185
# expose sub packages as directories
7286
from . import converters
7387
from . import proto
7488
from . import models
7589
from .models import utils
90+
from .models.ml_program import compression_utils
7691

7792
# expose unified converter in coremltools package level
7893
from .converters import convert
7994
from .converters import (
8095
ClassifierConfig,
96+
ColorLayout as colorlayout,
8197
TensorType,
8298
ImageType,
8399
RangeDim,

coremltools/_deps/__init__.py

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __get_sklearn_version(version):
100100
_TF_1_MIN_VERSION = "1.12.0"
101101
_TF_1_MAX_VERSION = "1.15.0"
102102
_TF_2_MIN_VERSION = "2.1.0"
103-
_TF_2_MAX_VERSION = "2.6.2"
103+
_TF_2_MAX_VERSION = "2.8.0"
104104

105105
try:
106106
import tensorflow
@@ -143,82 +143,9 @@ def __get_sklearn_version(version):
143143
MSG_TF1_NOT_FOUND = "TensorFlow 1.x not found."
144144
MSG_TF2_NOT_FOUND = "TensorFlow 2.x not found."
145145

146-
# ---------------------------------------------------------------------------------------
147-
_HAS_KERAS_TF = True
148-
_HAS_KERAS2_TF = True
149-
_KERAS_MIN_VERSION = "1.2.2"
150-
_KERAS_MAX_VERSION = "2.6.0"
151-
MSG_KERAS1_NOT_FOUND = "Keras 1 not found."
152-
MSG_KERAS2_NOT_FOUND = "Keras 2 not found."
153-
154-
try:
155-
# Prevent keras from printing things that are not errors to standard error.
156-
import sys
157-
158-
import io
159-
160-
temp = io.StringIO()
161-
stderr = sys.stderr
162-
try:
163-
sys.stderr = temp
164-
import keras
165-
except:
166-
# Print out any actual error message and re-raise.
167-
sys.stderr = stderr
168-
sys.stderr.write(temp.getvalue())
169-
raise
170-
finally:
171-
sys.stderr = stderr
172-
import tensorflow
173-
174-
k_ver = _get_version(keras.__version__)
175-
176-
# keras 1 version too old
177-
if k_ver < _StrictVersion(_KERAS_MIN_VERSION):
178-
_HAS_KERAS_TF = False
179-
_HAS_KERAS2_TF = False
180-
_logging.warning(
181-
(
182-
"Keras version %s is not supported. Minimum required version: %s ."
183-
"Keras conversion will be disabled."
184-
)
185-
% (keras.__version__, _KERAS_MIN_VERSION)
186-
)
187-
# keras version too new
188-
if k_ver > _StrictVersion(_KERAS_MAX_VERSION):
189-
_HAS_KERAS_TF = False
190-
_logging.warning(
191-
(
192-
"Keras version %s has not been tested with coremltools. You may run into unexpected errors. "
193-
"Keras %s is the most recent version that has been tested."
194-
)
195-
% (keras.__version__, _KERAS_MAX_VERSION)
196-
)
197-
# Using Keras 2 rather than 1
198-
if k_ver >= _StrictVersion("2.0.0"):
199-
_HAS_KERAS_TF = False
200-
_HAS_KERAS2_TF = True
201-
# Using Keras 1 rather than 2
202-
else:
203-
_HAS_KERAS_TF = True
204-
_HAS_KERAS2_TF = False
205-
if keras.backend.backend() != "tensorflow":
206-
_HAS_KERAS_TF = False
207-
_HAS_KERAS2_TF = False
208-
_logging.warning(
209-
(
210-
"Unsupported Keras backend (only TensorFlow is currently supported). "
211-
"Keras conversion will be disabled."
212-
)
213-
)
214-
215-
except:
216-
_HAS_KERAS_TF = False
217-
_HAS_KERAS2_TF = False
218-
219146
# ---------------------------------------------------------------------------------------
220147
_HAS_TORCH = True
221-
_TORCH_MAX_VERSION = "1.10.2"
148+
_TORCH_MAX_VERSION = "1.11.0"
222149
try:
223150
import torch
224151
_warn_if_above_max_supported_version("Torch", torch.__version__, _TORCH_MAX_VERSION)
@@ -228,13 +155,6 @@ def __get_sklearn_version(version):
228155

229156

230157
# ---------------------------------------------------------------------------------------
231-
_HAS_ONNX = True
232-
try:
233-
import onnx
234-
except:
235-
_HAS_ONNX = False
236-
MSG_ONNX_NOT_FOUND = "ONNX not found."
237-
238158
try:
239159
import scipy
240160
except:

coremltools/converters/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
from . import libsvm
88
from . import sklearn
99
from . import xgboost
10-
from . import keras
11-
from . import onnx
1210
from ._converters_entry import convert
1311
from .mil import (
1412
ClassifierConfig,
13+
ColorLayout,
1514
TensorType,
1615
ImageType,
1716
RangeDim,

0 commit comments

Comments
 (0)