Skip to content
Merged
Changes from all commits
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
8 changes: 4 additions & 4 deletions examples/mnist/reservoir.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def forward(self, x):


# Create and train logistic regression model on reservoir outputs.
model = NN(n_neurons, 10).to(device_id)
model = NN(n_neurons, 10).to(device)
criterion = torch.nn.MSELoss(reduction="sum")
optimizer = torch.optim.SGD(model.parameters(), lr=1e-4, momentum=0.9)

Expand All @@ -193,7 +193,7 @@ def forward(self, x):
# Forward + Backward + Optimize
optimizer.zero_grad()
outputs = model(s)
label = torch.zeros(1, 1, 10).float().to(device_id)
label = torch.zeros(1, 1, 10).float().to(device)
label[0, 0, l] = 1.0
loss = criterion(outputs.view(1, 1, -1), label)
avg_loss += loss.data
Expand All @@ -211,7 +211,7 @@ def forward(self, x):
for (i, dataPoint) in pbar:
if i > n_iters:
break
datum = dataPoint["encoded_image"].view(time, 1, 1, 28, 28).to(device_id)
datum = dataPoint["encoded_image"].view(time, 1, 1, 28, 28).to(device)
label = dataPoint["label"]
pbar.set_description_str("Testing progress: (%d / %d)" % (i, n_iters))

Expand Down Expand Up @@ -250,7 +250,7 @@ def forward(self, x):
outputs = model(s)
_, predicted = torch.max(outputs.data.unsqueeze(0), 1)
total += 1
correct += int(predicted == label.long().to(device_id))
correct += int(predicted == label.long().to(device))

print(
"\n Accuracy of the model on %d test images: %.2f %%"
Expand Down