Last active
April 11, 2019 03:37
-
-
Save jamesonthecrow/587790165c36c9dafc8a473cbb1f4539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from coremltools.models.neural_network import flexible_shape_utils | |
def make_mlmodel_flexible(spec, size_range=(100, 1920): | |
"""Make input and output sizes of a Core ML model flexible. | |
Args: | |
spec (NeuralNetwork_pb2): a Core ML neural network spec | |
size_range ([Int]): a tuple containing the min and max input sizes. | |
""" | |
size_range_spec = flexible_shape_utils.NeuralNetworkImageSizeRange() | |
size_range_spec.add_width_range(size_range) | |
size_range_spec.add_height_range(size_range) | |
flexible_shape_utils.update_image_size_range( | |
spec, feature_name='image', size_range=size_range_spec | |
) | |
size_range_spec = flexible_shape_utils.NeuralNetworkImageSizeRange() | |
size_range_spec.add_width_range(size_range) | |
size_range_spec.add_height_range(size_range) | |
flexible_shape_utils.update_image_size_range( | |
spec, feature_name='stylizedImage', size_range=size_range_spec | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment