Hello.
I’m an iOS/macOS developer who’s very new to AI.
I’d like to integrate to test some radiology-related AI models in a Swift environment, but I’m having issues converting them to CoreML.
Specifically, I’m encountering this error: AssertionError: tensor value not consistent between torch ir and state_dict
, for which I’ve found no information anywhere.
This is my full Jupyter notebook for conversion:
import torchxrayvision as xrv
import skimage, torch, torchvision
model = xrv.models.DenseNet(weights="densenet121-res224-rsna")
model.eval()
example_input = torch.rand(1, 1, 224, 224)
traced_model = torch.jit.trace(model, example_input)
out = traced_model(example_input)
import coremltools as ct
scale = 1/(0.226*255.0)
bias = [- 0.485/(0.229) , - 0.456/(0.224), - 0.406/(0.225)]
image_input = ct.ImageType(name="input_1",
shape=example_input.shape,
scale=scale, bias=bias)
model = ct.convert(
traced_model,
inputs=[image_input],
compute_units=ct.ComputeUnit.CPU_ONLY,
)