-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sweep (sandbox): src/main.py #95
Labels
Comments
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID:
a3f34edc0d )Actions (click)
📖 Reading FileRunning sandbox for src/main.py. Current Code: Lines 1 to 48 in 7284908
🛠️ Executing SandboxSandbox logs
Updated Code: import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from PIL import Image
from torch.utils.data import DataLoader
from torchvision import datasets, transforms
# Step 1: Load MNIST Data and Preprocess
transform = transforms.Compose(
[transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))]
)
trainset = datasets.MNIST(".", download=True, train=True, transform=transform)
trainloader = DataLoader(trainset, batch_size=64, shuffle=True)
# Step 2: Define the PyTorch Model
class Net(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(28 * 28, 128)
self.fc2 = nn.Linear(128, 64)
self.fc3 = nn.Linear(64, 10)
def forward(self, x):
x = x.view(-1, 28 * 28)
x = nn.functional.relu(self.fc1(x))
x = nn.functional.relu(self.fc2(x))
x = self.fc3(x)
return nn.functional.log_softmax(x, dim=1)
# Step 3: Train the Model
model = Net()
optimizer = optim.SGD(model.parameters(), lr=0.01)
criterion = nn.NLLLoss()
# Training loop
epochs = 3
for epoch in range(epochs):
for images, labels in trainloader:
optimizer.zero_grad()
output = model(images)
loss = criterion(output, labels)
loss.backward()
optimizer.step()
torch.save(model.state_dict(), "mnist_model.pth") Diff: ---
+++
@@ -1,19 +1,19 @@
-from PIL import Image
+import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
+from PIL import Image
+from torch.utils.data import DataLoader
from torchvision import datasets, transforms
-from torch.utils.data import DataLoader
-import numpy as np
# Step 1: Load MNIST Data and Preprocess
-transform = transforms.Compose([
- transforms.ToTensor(),
- transforms.Normalize((0.5,), (0.5,))
-])
+transform = transforms.Compose(
+ [transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))]
+)
-trainset = datasets.MNIST('.', download=True, train=True, transform=transform)
+trainset = datasets.MNIST(".", download=True, train=True, transform=transform)
trainloader = DataLoader(trainset, batch_size=64, shuffle=True)
+
# Step 2: Define the PyTorch Model
class Net(nn.Module):
@@ -22,13 +22,14 @@
self.fc1 = nn.Linear(28 * 28, 128)
self.fc2 = nn.Linear(128, 64)
self.fc3 = nn.Linear(64, 10)
-
+
def forward(self, x):
x = x.view(-1, 28 * 28)
x = nn.functional.relu(self.fc1(x))
x = nn.functional.relu(self.fc2(x))
x = self.fc3(x)
return nn.functional.log_softmax(x, dim=1)
+
# Step 3: Train the Model
model = Net()
🎉 Latest improvements to Sweep:
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Details
No response
The text was updated successfully, but these errors were encountered: