Created
December 29, 2019 16:09
-
-
Save omarsar/4fd38b3c6a25888bbb0a516a559d617f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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