Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kausthub-kannan
Copy link
Contributor

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Oct 5, 2023
Comment on lines +12 to 15
# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
numpy array of maxpooled matrix
The max pooled matrix

Comment on lines +68 to 71
# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

Comment on lines 76 to 77
Returns:
numpy array of avgpooled matrix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Returns:
numpy array of avgpooled matrix
Returns:
The average pooled matrix

Comment on lines +123 to +131
# 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test with Images

if __name__ == "__main__":
from doctest import testmod

testmod(name="avgpooling", verbose=True)
testmod(name="average_pooling", verbose=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

@tianyizheng02 tianyizheng02 added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes A maintainer has requested changes to this PR enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants