Hi, you can try this way.
Make sure that, x = torch.mean(x,dim=1,keepdim=True), is the first statement in the forward method of pytorch model.
Then,
example = torch.rand(1, 3, 28, 28)
trace = torch.jit.trace(net, example)
trace.save(“mymodel.pt”)