compiler error: Espresso exception: "Invalid blob shape": Cannot broadcast blobs
🐞Describe the bug
-
A clear and brief description of what the bug is. I successfully converted my ONNX model to mlmodel without any issue. Then I dragged my mlmodel into my Swift project and the project failed at compiling the model:
-
Is this a converter issue? If yes, please specify which converter (sci-kit, keras, xgboost etc.) Not sure. I use ONNX converter.
Trace
If applicable, please paste the error trace.

To Reproduce
- If a python script can reproduce the error, please paste the code snippet
from pathlib import Path
import coremltools as ct
root = Path(__file__).parent
model = ct.converters.onnx.convert(
model = "BiSeNetV2_op12_sim_output_fixed.onnx",
minimum_ios_deployment_target = '13',
image_input_names=["x"],
preprocessing_args={
"image_scale": 1./(255.0),
"red_bias": - 0.5/(0.5),
"green_bias":- 0.5/(0.5),
"blue_bias": - 0.5/(0.5)
}
)
saved_model_path = root.parent / "output/bisenetv2_op12_ios13"
model.save("./output/bisenetv2_op12_ios13_outout_fixed_sim.mlmodel")
- If applicable, please attach the source model
And here is the ONNX model(on Microsoft OneDrive): https://1drv.ms/u/s!Asflam6BEzhjgbM4b82jgr-_iALyLA?e=im3LKz
- create a Swift UI project
- drag this model into the XCode : https://1drv.ms/u/s!Asflam6BEzhjgbM3PGRG2h_jCY-4tA?e=EEPXno
- Build and run the app
System environment (please complete the following information):
- coremltools version (e.g., 3.0b5): 5.2.0
- OS (e.g., MacOS, Linux): MacOS
- macOS version (if applicable): 10.15.7
- XCode version (if applicable): 12.4
- How you install python (anaconda, virtualenv, system): anaconda
- python version (e.g. 3.7): 3.8
- any other relevant information:
- ONNX Operator version12.
I wrote an Python script to test the ml model and found more details of the same issue:

Here is the code, helpfully it helps to figure out the issue:
import coremltools as ct
import numpy as np
import cv2
from paddle.vision.transforms import Compose, Resize, Normalize, Transpose
loaded_model = ct.models.MLModel("./output/bisenetv2_op12_ios13_outout_fixed_sim.mlmodel")
def load_image_cv(path):
img = cv2.imread(path)
return img
img = load_image_cv("boxhill_079.jpeg")
scaled_img = img.astype("float32") / 255.0
trfms = Compose([
Resize(size=(1024, 1024)),
Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5), data_format="HWC"),
Transpose()
])
transformed_img = trfms(scaled_img)
transformed_img = transformed_img[np.newaxis, :]
out_dict = loaded_model.predict({"x": transformed_img})
print(out_dict)
The error happens on the line:
out_dict = loaded_model.predict({"x": transformed_img})
@TobyRoseman just wondering any update for this one?
@TobyRoseman just wondering any update for this one?
No update. Please note: our onnx converter is deprecated. We're planning on removing it in our next major release. I think it's unlikely this will be fixed.
ONNX support has been removed in coremltools 6.0.