leetcode
leetcode copied to clipboard
Bug Report for handwritten-digit-classifier
Bug Report for https://neetcode.io/problems/handwritten-digit-classifier
After trying for several times, it didn't work, finally I took the code from the solutions tab, and upon copy-pasting that and runnig, still output pane said this:
Input:
images=torch.randn(1, 28 * 28) Your Output: [[0.607,0.4426,0.494,0.4634,0.5263,0.5707,0.5564,0.4835,0.3663,0.5077]]
Expected output: [[0.565,0.4828,0.5203,0.471,0.5244,0.5394,0.5588,0.4864,0.4046,0.5196]]
Please find my code below for reference, also try executing the code from the solutions tab.
import torch
import torch.nn as nn
from torchtyping import TensorType
class Solution(nn.Module):
def __init__(self):
super().__init__()
torch.manual_seed(0)
self.fc1 = nn.Linear(784,512)
self.relu = nn.ReLU()
self.dropout = nn.Dropout(0.2)
self.fc2 = nn.Linear(512,10)
self.sigmoid = nn.Sigmoid()
# Define the architecture here
def forward(self, images: TensorType[float]) -> TensorType[float]:
torch.manual_seed(0)
images = self.relu(self.fc1(images))
images = self.dropout(images)
images = self.fc2(images)
out = self.sigmoid(images)
return torch.round(out,decimals=4)
# Return the model's prediction to 4 decimal places