Skip to content

Instantly share code, notes, and snippets.

@jamesonthecrow
Last active April 11, 2019 03:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamesonthecrow/587790165c36c9dafc8a473cbb1f4539 to your computer and use it in GitHub Desktop.
Save jamesonthecrow/587790165c36c9dafc8a473cbb1f4539 to your computer and use it in GitHub Desktop.
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