Skip to content

Commit 37e619d

Browse files
authored
coremltools-4.0b2 (#812)
* coremltools-4.0b2 * coremltools-4.0b2 * coremltools-4.0b2 * coremltools-4.0b2 * coremltools-4.0b2 * coremltools-4.0b2 * coremltools-4.0b2 * Generate 11.0 wheels instead of 10.16 * coremltools-4.0b2 * coremltools-4.0b2 * coremltools-4.0b2 * coremltools-4.0b2 * coremltools 4.0b2 * coremltools 4.0b2 * coremltools 4.0b2 * coremltools 4.0b2 * coremltools 4.0b2 * coremltools 4.0b2 * coremltools 4.0b2 * coremltools 4.0b2 * coremltools 4.0b2
1 parent 4082a20 commit 37e619d

File tree

78 files changed

+3984
-3203
lines changed

Some content is hidden

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

78 files changed

+3984
-3203
lines changed

.gitlab-ci.yml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ check_python_flake8:
2020
- pip install flake8
2121
- flake8 ./coremltools --count --select=E9,F63,F7,F82 --show-source --statistics
2222

23-
2423
########################################################################
2524
#
2625
# linux - Build & Test
@@ -33,7 +32,7 @@ check_python_flake8:
3332
stage: build
3433
script:
3534
- export PATH=$PATH:$HOME/miniconda3/condabin
36-
- bash -e scripts/build.sh --num-procs=4 --python=$PYTHON --dist
35+
- zsh -e scripts/build.sh --num-procs=4 --python=$PYTHON --dist
3736
artifacts:
3837
expire_in: 2 weeks
3938
paths:
@@ -45,7 +44,6 @@ build_wheel_linux_py27:
4544
variables:
4645
PYTHON: "2.7"
4746

48-
4947
#########################################################################
5048
##
5149
## macOS - Build & Test
@@ -57,7 +55,7 @@ build_wheel_linux_py27:
5755
- macos10.15
5856
stage: build
5957
script:
60-
- bash -e scripts/build.sh --num-procs=4 --python=$PYTHON --dist
58+
- zsh -e scripts/build.sh --num-procs=4 --python=$PYTHON --dist
6159
artifacts:
6260
expire_in: 2 weeks
6361
paths:
@@ -93,31 +91,27 @@ build_wheel_macos_py38:
9391
variables:
9492
PYTHON: "3.8"
9593

96-
.test_macos_coremltools_test: &test_macos_coremltools_test
97-
stage: test
98-
script:
99-
- bash -e scripts/test.sh --wheel-path=${WHEEL_PATH} --python=${PYTHON} --fast
100-
10194
.test_macos_pkg: &test_macos_pkg
10295
stage: test
10396
script:
104-
- bash -e scripts/test.sh --wheel-path=${WHEEL_PATH} --python=${PYTHON}
97+
- zsh -e scripts/test.sh --wheel-path=${WHEEL_PATH} --python=${PYTHON}
10598
--test-package=${TEST_PACKAGE} --fast
10699

107100
.test_macos_pkg_with_reqs: &test_macos_pkg_with_reqs
108101
stage: test
109102
script:
110-
- bash -e scripts/test.sh --wheel-path=${WHEEL_PATH} --python=${PYTHON}
103+
- zsh -e scripts/test.sh --wheel-path=${WHEEL_PATH} --python=${PYTHON}
111104
--test-package=${TEST_PACKAGE} --requirements=${REQUIREMENTS} --fast
112105

113106
test_macos11_py27_coremltools_test:
114-
<<: *test_macos_coremltools_test
107+
<<: *test_macos_pkg
115108
tags:
116109
- macos11
117110
dependencies:
118111
- build_wheel_macos_py27
119112
variables:
120113
WHEEL_PATH: build/dist/*cp27*10_16*
114+
TEST_PACKAGE: coremltools.test
121115
PYTHON: "2.7"
122116
only:
123117
changes:
@@ -131,13 +125,14 @@ test_macos11_py27_coremltools_test:
131125
- coremltools/converters/xgboost/**/*.{py}
132126

133127
test_macos11_py37_coremltools_test:
134-
<<: *test_macos_coremltools_test
128+
<<: *test_macos_pkg
135129
tags:
136130
- macos11
137131
dependencies:
138132
- build_wheel_macos_py37
139133
variables:
140134
WHEEL_PATH: build/dist/*cp37*10_16*
135+
TEST_PACKAGE: coremltools.test
141136
PYTHON: "3.7"
142137
only:
143138
changes:
@@ -181,7 +176,7 @@ test_macos11_py37_pytorch:
181176
- coremltools/converters/mil/mil/**/*.{py}
182177
- coremltools/converters/mil/backend/**/*.{py}
183178

184-
test_macos11_py27_tensorflow1:
179+
test_macos11_py27_tf1:
185180
<<: *test_macos_pkg
186181
tags:
187182
- macos11
@@ -197,7 +192,7 @@ test_macos11_py27_tensorflow1:
197192
- coremltools/converters/mil/mil/**/*.{py}
198193
- coremltools/converters/mil/backend/**/*.{py}
199194

200-
test_macos11_py37_tensorflow1:
195+
test_macos11_py37_tf1:
201196
<<: *test_macos_pkg
202197
tags:
203198
- macos11
@@ -213,7 +208,7 @@ test_macos11_py37_tensorflow1:
213208
- coremltools/converters/mil/mil/**/*.{py}
214209
- coremltools/converters/mil/backend/**/*.{py}
215210

216-
test_macos11_py27_tensorflow2:
211+
test_macos11_py27_tf2:
217212
<<: *test_macos_pkg_with_reqs
218213
tags:
219214
- macos11
@@ -230,7 +225,7 @@ test_macos11_py27_tensorflow2:
230225
- coremltools/converters/mil/mil/**/*.{py}
231226
- coremltools/converters/mil/backend/**/*.{py}
232227

233-
test_macos11_py37_tensorflow2:
228+
test_macos11_py37_tf2:
234229
<<: *test_macos_pkg_with_reqs
235230
tags:
236231
- macos11
@@ -277,8 +272,6 @@ test_macos11_py37_mil:
277272
- coremltools/converters/mil/mil/**/*.{py}
278273
- coremltools/converters/mil/backend/**/*.{py}
279274

280-
281-
282275
#########################################################################
283276
##
284277
## Make docs
@@ -305,7 +298,6 @@ build_documentation:
305298
changes:
306299
- docs/**/*
307300

308-
309301
#########################################################################
310302
##
311303
## Collect artifacts
@@ -321,6 +313,7 @@ collect_artifacts:
321313
script:
322314
echo "Collect artifacts (wheels and documentation)"
323315
dependencies:
316+
- build_wheel_linux_py27
324317
- build_wheel_macos_py27
325318
- build_wheel_macos_py35
326319
- build_wheel_macos_py36

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ With coremltools, you can do the following:
2929
To get the latest version of coremltools:
3030

3131
```shell
32-
pip install coremltools==4.0b1
32+
pip install coremltools==4.0b2
3333
```
3434

3535
For the latest changes please see the [release notes](https://github.com/apple/coremltools/releases/).

coremltools/converters/mil/backend/nn/load.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,32 @@ def _set_symbolic_inputs(proto, symbolic_inputs):
165165
proto, input_name, lower_bounds=lb, upper_bounds=ub
166166
)
167167

168+
def _set_optional_inputs(proto, input_types):
169+
# Set default values for optional input_types
170+
default_map = {}
171+
for input_type in input_types:
172+
if isinstance(input_type, ImageType):
173+
continue
174+
is_optional = input_type.is_optional
175+
optional_value = input_type.optional_value
176+
shape = input_type.shape
177+
if not is_optional:
178+
continue
179+
msg = "Not support optional inputs for flexible input shape."
180+
if not isinstance(shape, Shape):
181+
raise NotImplementedError(msg)
182+
if any([isinstance(s, RangeDim) for s in shape.shape]):
183+
raise NotImplementedError(msg)
184+
185+
default_map[input_type.name] = optional_value
186+
187+
for idx, input in enumerate(proto.description.input):
188+
name = proto.description.input[idx].name
189+
if name in default_map:
190+
proto.description.input[idx].type.isOptional = True
191+
default_value = default_map[name] if default_map[name] is not None else 0.
192+
proto.description.input[idx].type.multiArrayType.floatDefaultValue = default_value
193+
168194

169195
@_profile
170196
def load(prog, **kwargs):
@@ -260,5 +286,6 @@ def load(prog, **kwargs):
260286

261287
_set_user_inputs(proto, input_types)
262288
_set_symbolic_inputs(proto, symbolic_inputs)
289+
_set_optional_inputs(proto, input_types)
263290

264291
return proto
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2020, Apple Inc. All rights reserved.
2+
#
3+
# Use of this source code is governed by a BSD-3-clause license that can be
4+
# found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5+
6+
MIL_TO_NN_MAPPING_REGISTRY = {}
7+
8+
def register_mil_to_nn_mapping(func=None, override=False):
9+
def func_wrapper(_func):
10+
f_name = _func.__name__
11+
if not override and f_name in MIL_TO_NN_MAPPING_REGISTRY:
12+
raise ValueError("MIL to NN mapping for MIL op {} is already registered.".format(f_name))
13+
MIL_TO_NN_MAPPING_REGISTRY[f_name] = _func
14+
return _func
15+
16+
if func is None:
17+
# decorator called without argument
18+
return func_wrapper
19+
return func_wrapper(func)

0 commit comments

Comments
 (0)