-
-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
Added Global average pooling #9863
base: master
Are you sure you want to change the base?
Added Global average pooling #9863
Conversation
# Max pooling Function | ||
def max_pooling(arr: np.ndarray, size: int, stride: int) -> np.ndarray: | ||
""" | ||
This function is used to perform maxpooling on the input array of 2D matrix(image) |
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.
# Max pooling Function | |
def max_pooling(arr: np.ndarray, size: int, stride: int) -> np.ndarray: | |
""" | |
This function is used to perform maxpooling on the input array of 2D matrix(image) | |
def max_pooling(arr: np.ndarray, size: int, stride: int) -> np.ndarray: | |
""" | |
Performs max pooling on the input image matrix |
The comment at the top of the function is unnecessary because we already have the docstring to explain what the algorithm does
@@ -15,10 +20,10 @@ def maxpooling(arr: np.ndarray, size: int, stride: int) -> np.ndarray: | |||
Returns: | |||
numpy array of maxpooled matrix |
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.
numpy array of maxpooled matrix | |
The max pooled matrix |
# Average pooling Function | ||
def avg_pooling(arr: np.ndarray, size: int, stride: int) -> np.ndarray: | ||
""" | ||
This function is used to perform avgpooling on the input array of 2D matrix(image) |
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.
# Average pooling Function | |
def avg_pooling(arr: np.ndarray, size: int, stride: int) -> np.ndarray: | |
""" | |
This function is used to perform avgpooling on the input array of 2D matrix(image) | |
def avg_pooling(arr: np.ndarray, size: int, stride: int) -> np.ndarray: | |
""" | |
Perform average pooling on the input image matrix |
Returns: | ||
numpy array of avgpooled matrix |
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.
Returns: | |
numpy array of avgpooled matrix | |
Returns: | |
The average pooled matrix |
# Global Average pooling Function | ||
def global_average_pooling(arr: np.ndarray) -> np.ndarray: | ||
""" | ||
This function performs global average pooling on the input 2D matrix (image). | ||
Args: | ||
arr: numpy array | ||
The input 2D matrix. | ||
Returns: | ||
numpy array of the global average pooled matrix. |
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.
# Global Average pooling Function | |
def global_average_pooling(arr: np.ndarray) -> np.ndarray: | |
""" | |
This function performs global average pooling on the input 2D matrix (image). | |
Args: | |
arr: numpy array | |
The input 2D matrix. | |
Returns: | |
numpy array of the global average pooled matrix. | |
def global_avg_pooling(arr: np.ndarray) -> np.ndarray: | |
""" | |
Performs global average pooling on the input image matrix. | |
Args: | |
arr: the input 2D matrix. | |
Returns: | |
The global average pooled matrix |
Changed name from "...average..." to "...avg..." for consistency with avg_pooling
return global_avg_pooled_matrix | ||
|
||
|
||
# Test with Images |
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.
# Test with Images |
if __name__ == "__main__": | ||
from doctest import testmod | ||
|
||
testmod(name="avgpooling", verbose=True) | ||
testmod(name="average_pooling", verbose=True) |
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.
testmod(name="average_pooling", verbose=True) | |
testmod(name="pooling_functions", verbose=True) |
image = Image.open("path_to_image") | ||
image = Image.open("/path_to_image") | ||
|
||
# Converting the image to numpy array and max_pooling, displaying the result |
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.
# Converting the image to numpy array and max_pooling, displaying the result | |
# Converting the image to numpy array and max pooling, displaying the result |
|
||
# Converting the image to numpy array and maxpooling, displaying the result | ||
# Converting the image to numpy array and average_pooling, displaying the result |
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.
# Converting the image to numpy array and average_pooling, displaying the result | |
# Converting the image to numpy array and average pooling, displaying the result |
|
||
# Converting the image to numpy array and averagepooling, displaying the result | ||
# Converting the image to numpy array and average_pooling, displaying the result |
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.
# Converting the image to numpy array and average_pooling, displaying the result | |
# Converting the image to numpy array and global average pooling, displaying the result |
Describe your change:
Checklist: