Couldn't convert MobileNet V2 PyTorch to mlmodel using CoreML tools
I want to convert PyTorch MobileNet V2 pre-trained model to .mlmodel using coremltools. here is my code:
    import torchvision
    import torch
    import coremltools as ct

    # Load a pre-trained version of MobileNetV2
    torch_model = torchvision.models.mobilenet_v2(pretrained=True)
    # Set the model in evaluation mode.
    torch_model.eval()

    # Trace the model with random data.
    example_input = torch.rand(1, 3, 224, 224) 
    traced_model = torch.jit.trace(torch_model, example_input)
    out = traced_model(example_input)

    # Using image_input in the inputs parameter:
    # Convert to Core ML using the Unified Conversion API.
    model = ct.convert(
        traced_model,
        inputs=[ct.TensorType(shape=example_input.shape)]
     )

    # Save the converted model.
    model.save(&quot;mobilenet_v2.mlmodel&quot;)

It worked well on Google Colab, but when I run it my local machine (MacBook), I've got the following error
Converting Frontend ==&gt; MIL Ops: 100%|▉| 390/391 [00:00&lt;00:00, 647.56
Running MIL Common passes:   0%|         | 0/34 [00:00&lt;?, ? passes/s]anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/mil/passes/name_sanitization_utils.py:101: UserWarning: Input, 'input.1', of the source model, has been renamed to 'input_1' in the Core ML model.
  warnings.warn(msg.format(var.name, new_name))
anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/mil/passes/name_sanitization_utils.py:129: UserWarning: Output, '830', of the source model, has been renamed to 'var_830' in the Core ML model.
  warnings.warn(msg.format(var.name, new_name))
Running MIL Common passes: 100%|█| 34/34 [00:00&lt;00:00, 41.87 passes/s
Running MIL Clean up passes: 100%|█| 9/9 [00:00&lt;00:00, 80.15 passes/s
Translating MIL ==&gt; NeuralNetwork Ops: 100%|█| 495/495 [00:00&lt;00:00, 
Traceback (most recent call last):
  File &quot;convert_models.py&quot;, line 24, in &lt;module&gt;
    model = ct.convert(
  File &quot;anaconda3/lib/python3.8/site-packages/coremltools/converters/_converters_entry.py&quot;, line 352, in convert
    mlmodel = mil_convert(
  File &quot;anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/converter.py&quot;, line 183, in mil_convert
    return _mil_convert(model, convert_from, convert_to, ConverterRegistry, MLModel, compute_units, **kwargs)
  File &quot;anaconda3/lib/python3.8/site-packages/coremltools/converters/mil/converter.py&quot;, line 231, in _mil_convert
    return modelClass(proto,
  File &quot;anaconda3/lib/python3.8/site-packages/coremltools/models/model.py&quot;, line 346, in __init__
    self.__proxy__, self._spec, self._framework_error = _get_proxy_and_spec(
  File &quot;anaconda3/lib/python3.8/site-packages/coremltools/models/model.py&quot;, line 123, in _get_proxy_and_spec
    specification = _load_spec(filename)
  File &quot;/anaconda3/lib/python3.8/site-packages/coremltools/models/utils.py&quot;, line 210, in load_spec
    raise Exception(
Exception: Unable to load libmodelpackage. Cannot make save spec.

I am using the following versions of libraries:

torchvision: '0.9.0'
torch: '1.8.0'
coremltools: '5.2.0'


I solved this problem by updating the macOS from 10.14.6 Mojave to 11.5.2 MacOS Big Sur. From the Github issue that I have created, they explained to me that the version &quot;5.2&quot; of coremltools is not supported in my previous MacOS version. So, by updating your macOS it should work.
