-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Optimised the guassian sampling function. #2336
Optimised the guassian sampling function. #2336
Conversation
Reviewer's Guide by SourceryThis PR optimises the Gaussian noise sampling process by replacing the inefficient numpy operations with cv2 operations, and by simplifying the sampling of constant mean and standard deviation values. Additionally, a seed parameter has been integrated and propagated across various functions to ensure consistent random number generation using cv2's RNG. Sequence diagram for Gaussian Noise Sampling ProcesssequenceDiagram
participant Caller
participant generate_noise
participant sample_noise
participant sample_gaussian
participant CV2
Caller->>generate_noise: call generate_noise(seed)
generate_noise->>sample_noise: call sample_noise(seed)
sample_noise->>sample_gaussian: call sample_gaussian(seed)
sample_gaussian->>CV2: cv2.setRNGSeed(seed)
sample_gaussian->>CV2: cv2.randn(dst, mean_vector, std_dev_vector)
CV2-->>sample_gaussian: noise array
sample_gaussian-->>sample_noise: gaussian noise array
sample_noise-->>generate_noise: noise array
generate_noise-->>Caller: noise array
Class diagram for Seed Propagation in Augmentation TransformsclassDiagram
class Composition {
-seed: int | None
-random_generator: np.random.Generator
-py_random: Random
+__init__(seed)
+set_random_seed(seed)
}
class TransformsInterface {
-seed: int | None
-random_generator: np.random.Generator
-py_random: Random
+__init__(seed)
+set_random_seed(seed)
}
note for Composition "Calls cv2.setRNGSeed(seed) in __init__ and set_random_seed"
note for TransformsInterface "Calls cv2.setRNGSeed(seed) during initialization and seed updates"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @vedantdalimkar - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider checking if 'seed' is not None before calling cv2.setRNGSeed to prevent potential errors when seed is None.
- Centralize or abstract the repeated cv2.setRNGSeed calls to reduce duplication across functions and classes.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Tries to address #2295
The "sample_gaussian" was using a numpy function to sample gaussian noise. Changed it to the equivalent cv2 operation.
Also noticed that the "mean_range" and "std_range" parameters for GaussNoise is always a tuple of 2 equal values. "sample_gaussian" function randomly samples the mean and standard deviation from these 2 tuples. This is redudant and as sampling from an interval having one point always returns that point itself. This is also relatively expensive as compared to simply selecting that one point, as sampling uses a numpy generator object.
Summary by Sourcery
Replace the NumPy-based Gaussian noise sampling with an equivalent OpenCV (cv2) implementation. Simplify the mean and standard deviation selection process by directly using the provided values when the ranges consist of identical elements, improving efficiency.
New Features:
Enhancements: