Skip to content

Instantly share code, notes, and snippets.

@omarsar
Created December 29, 2019 16:09
Show Gist options
  • Save omarsar/4fd38b3c6a25888bbb0a516a559d617f to your computer and use it in GitHub Desktop.
Save omarsar/4fd38b3c6a25888bbb0a516a559d617f to your computer and use it in GitHub Desktop.
## model pretesting
x, y = next(iter(train_dataset))
## flatten/transform the data
x_flatten = x.T
y = y.unsqueeze(0)
## num_px is the dimension of the images
dim = x_flatten.shape[0]
## model instance
model = LR(dim)
model.to(device)
yhat = model.forward(x_flatten.to(device))
yhat = yhat.data.cpu()
## calculate loss
cost = loss(yhat, y)
prediction = predict(yhat, y)
print("Cost: ", cost)
print("Accuracy: ", prediction)
## backpropagate
model.backward(x_flatten.to(device), yhat.to(device), y.to(device))
model.optimize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment