fix: replace bare except with extension-based dispatch in TorchScript model loading#537
Open
AdityaX18 wants to merge 1 commit intoJdeRobot:masterfrom
Open
fix: replace bare except with extension-based dispatch in TorchScript model loading#537AdityaX18 wants to merge 1 commit intoJdeRobot:masterfrom
AdityaX18 wants to merge 1 commit intoJdeRobot:masterfrom
Conversation
Fixes JdeRobot#419 Three bugs fixed across two files: 1. torch_detection.py: bare 'except Exception' caused valid .torchscript files to trigger the except block on an internal PyTorch UserWarning, printing 'Model is not a TorchScript model' even for valid TorchScript. 2. torch_segmentation.py TorchImageSegmentationModel: bare 'except:' with no exception type — catches KeyboardInterrupt, SystemExit, everything. Also missing weights_only=False on torch.load(). 3. torch_segmentation.py TorchLiDARSegmentationModel: same bare except Exception pattern + missing weights_only=False. Fix: primary dispatch by file extension (.torchscript -> torch.jit.load, .pt/.pth -> torch.load with weights_only=False). Unknown extensions probe TorchScript first, catch only RuntimeError, fall back to torch.load() and emit warnings.warn() with actionable guidance instead of print(). Added tests/test_torch_model_loading.py covering all 4 loading paths.
Collaborator
|
Closing since #419 has already been resolved. Thaks for your interest! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Body:
Fixes #419
pytest tests/test_torch_model_loading.py -v
4 passed