Thanks for the code.
Your model isn’t working with the specified shape in PyTorch-only, so this issue doesn’t seem to be ONNX specific.
DenseCapsule seems to raise the size mismatch in:
x_hat = torch.squeeze(torch.matmul(self.weight, x[:, None, :, :, None]), dim=-1)

as
RuntimeError: The size of tensor a (1152) must match the size of tensor b (800) at non-singleton dimension 2