-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize PyTorch Classifiers and Object Detectors #2180
Conversation
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
This may also potentially resolve #1943 but other issues may still persist. |
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## dev_1.15.0 #2180 +/- ##
==============================================
+ Coverage 80.96% 85.68% +4.71%
==============================================
Files 306 306
Lines 27067 27022 -45
Branches 4980 4962 -18
==============================================
+ Hits 21914 23153 +1239
+ Misses 3927 2599 -1328
- Partials 1226 1270 +44
|
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @f4str Thank you very much for these improvements to the estimators! They will be very useful for many users of ART. I have one suggestion, what do you think?
|
||
# Convert labels into tensor | ||
if y is not None and isinstance(y, list) and isinstance(y[0]["boxes"], np.ndarray): | ||
y_tensor = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we be able to remove the "type: ignore" in line 139 if we add more specific typing here in line 122 like
y_tensor = [] | |
y_tensor: List[Dict[str, "torch.Tensor"]] = [] |
If yes, should we move this initialization before this if-block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mypy
issue is actually due to the None
type that y
can be. The type: ignore
was actually here before, I've just abstracted this segment of code out (since it is now reused) and made it a function.
Attempting to make the typing changes to correct this needs to go a couple levels upwards which can makes thing overcomplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should now be resolved
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Hi @beat-buesser thank you for approving the PR. I have reverted the changes to the I've also responded to your comment about the mypy issue. |
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
@f4str Thank you very much! |
Description
Use PyTorch datasets and dataloaders to optimize the
fit
andpredict
methods for the following PyTorch estimators:PyTorchClassifier
,PyTorchRegressor
,PyTorchRandomizedSmoothing
,PyTorchObjectDetector
,PyTorchYolo
. This not only speeds up the batching process, but also will only move the current batch to the GPU rather than the entire dataset. This will significantly reduce the VRAM usage.Optimize thepredict
method for theTensorFlowV2Classifier
by using a TensorFlow dataset and the@tf.function
decorator to speed up inference.Significant changes to the
PyTorchObjectDetector
estimator:channels_first
property is now properly used to transpose inputs accordingly.PyTorchYolo
estimator does. This simplifies the implementation and reduces redundant code.torch>=1.10
so the entire batch can be processed at once now. Due to batch processing rather an one sample at a time, the loss gradients have now changed. The unit tests have been adjusted accordingly.Also removed the PyTorch version checking from the
PyTorchYolo
estimator as the bug only applies to the torchvision models and does not affect the external YOLO models.Fixes #2157
Fixes #1637
Fixes #2173
Type of change
Please check all relevant options.
Testing
Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.
PyTorchObjectDetector
PyTorchFasterRCNN
Test Configuration:
Checklist