Posts

Post not yet marked as solved
1 Replies
In case it is helpful, here is my code for generating the toy regression.mlmodel model from Pytorch: import torch import torch.optim as optim import torch.nn as nn import coremltools as ct # Define a simple neural network with two layers class SimpleRegressionModel(nn.Module): def __init__(self): super(SimpleRegressionModel, self).__init__() self.layer1 = nn.Linear(2, 5) # 2 inputs, 5 outputs self.layer2 = nn.Linear(5, 1) # 5 inputs, 1 output def forward(self, x): x = torch.relu(self.layer1(x)) x = self.layer2(x) return x # Create the model model = SimpleRegressionModel() # Create a sample input tensor sample_input = torch.rand(1, 2) # Trace the model with a sample input traced_model = torch.jit.trace(model, sample_input) # Convert the traced model to Core ML format input_features = [ct.TensorType(shape=(1, 2))] output_features = ["output"] mlmodel = ct.convert( traced_model, inputs=input_features, convert_to="neuralnetwork" ) mlmodel.save("regression.mlmodel")