Yolov5 convert to TorchScript

Describe

hi,guys,i want to convert yolov5 pytorch model to TorchScript,then i find source code have if else in forward function,so i decide to use torch.jit.script rather than torch.jit.trace,bacause i know it is not support control statement for example if else,and i change many details to fit torchScript,but i failed,so i google how to convert yolov5 to torchScript and find it has a export.py,which can convert to torchScript or onnx,i find it uses torch.jit.trace,why?torchScript support if else?

No, as you’ve already said, tracing a model will not capture data-dependent control flow, conditions etc.
I don’t know how the export.py method is defined, but I would guess that model.eval() might be a requirement and the traced model will then use the not self.training code path only.

yes,you are right,self.training is false,you means if i define a global variable to control if else conditions will be success,right?