How to get the first dimension size of tensor with onnx?

I want to check if the size of tensor x.
But when I used len(x), I got error:

ONNX export failed on ATen operator len because torch.onnx.symbolic_opset11.len does not exist

and

KeyError: 'len'

When I used x.size(0), I got error:

RuntimeError: ONNX export failed on ne, which is not implemented for opset 11. Try exporting with other opset versions

When I used x.shape[0], I got error:

UserWarning: ONNX export failed on ATen operator __getitem_ because torch.onnx.symbolic_opset11.__getitem_ does not exist

and

KeyError: '__getitem_'

What can I do to solve this problem? Looking forward to your reply.