Skip to content

Add LeNet Implementation in PyTorch #7070

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

Merged
merged 14 commits into from
Apr 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions computer_vision/lenet_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,28 @@ def forward(self, image_array: numpy.ndarray) -> numpy.ndarray:
return image_array


def test_model() -> bool:
def test_model(image_tensor: torch.tensor) -> bool:
"""
Test the model on a random input of size [64, 1, 32, 32]
Test the model on an input batch of 64 images

>>> test_model()
Args:
image_tensor (torch.tensor): Batch of Images for the model

>>> test_model(torch.randn(64, 1, 32, 32))
True

"""
random_image = torch.randn(64, 1, 32, 32)
model = LeNet()
output = model(random_image)
try:
model = LeNet()
output = model(image_tensor)
except:
return False

return output.shape == torch.zeros([64, 10]).shape


if __name__ == "__main__":
print(f"Model Passed: {test_model()}")
random_image_1 = torch.randn(64, 1, 32, 32)
random_image_2 = torch.randn(1, 32, 32)

print(f"random_image_1 Model Passed: {test_model(random_image_1)}")
print(f"random_image_2 Model Passed: {test_model(random_image_2)}")