Closed Michelvl92 closed 2 years ago
This is caused by some contraflow within the forward-pass of YoloV5. RFA-Toolbox uses the JIT-Compiler to extract the graph of a model, which only evaluated the parts of the control flow touched by the forward-pass during the trace. For some reason this requires any YoloV5-model to be in train-mode in order to be traceable by the JIT-Compiler of PyTorch.
If you put the model in train mode it works. Here is some example code, that fixed the issue:
import torch
from rfa_toolbox import create_graph_from_pytorch_model, visualize_architecture
# Model
model_name = "YoloV5s"
model = torch.hub.load('ultralytics/yolov5', f'{model_name.lower()}') # or yolov5m, yolov5l, yolov5x, custom
#model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5s.onnx') # or yolov5m, yolov5l, yolov5x, custom
model.train()
graph = create_graph_from_pytorch_model(model.cpu(), (4, 3, 640, 640))
visualize_architecture(graph, model_name=f"{model_name}", input_res=10000).render(f"{model_name}")
@Michelvl92 errors generated by 3rd party tools should be reported directly to their authors, they are outside of the scope of our work and support.
@Michelvl92 errors generated by 3rd party tools should be reported directly to their authors, they are outside of the scope of our work and support.
ya but if you're going to use 3rd party tools in your work use them properly. I've been spending an hour over this ridiculous issue
@pranavraja99 OP's tools are not related to YOLOv5, they are not used in this repository
Search before asking
YOLOv5 Component
When loading any model with torch.hub, default ones, and custom models, I always getting the same error when create_graph_from_pytorch_model with the ReceptiveFieldAnalysisToolbox
Bug
Environment
Default Yolov5 latest docker
Minimal Reproducible Example
Additional
No response
Are you willing to submit a PR?