Skip to content

Instantly share code, notes, and snippets.

@santi-pdp
Created January 24, 2018 17:53
Show Gist options
  • Save santi-pdp/d0e9002afe74db04aa5bbff6d076e8fe to your computer and use it in GitHub Desktop.
Save santi-pdp/d0e9002afe74db04aa5bbff6d076e8fe to your computer and use it in GitHub Desktop.
Toy example in pytorch for binary classification
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sharmavaruns
Copy link

sharmavaruns commented May 27, 2019

Hello Santi, thank you for this code snippet! It really helped me start understanding how to implement pytorch for classification.

I wanted to point out an error in your code regarding the train_epoch function:

  1. for the Forward function call, you write:
    y_hat = net(x_batch)
    Where 'net' should actually be 'model' (since this was the argument passed into train_epoch function).
  2. It would be better if you actually had the argument X,Y defined as arguments in the train_epoch function rather than calling the global variables X and Y.

Anyway, thanks for putting this up!

@mnauf
Copy link

mnauf commented Sep 21, 2019

BCEWithLogitsLoss() expects logits as inputs and not probabilities, so you shouldnt do y = self.out_act(a3)

@mdja
Copy link

mdja commented Sep 27, 2020

BCEWithLogitsLoss() expects logits as inputs and not probabilities, so you shouldnt do y = self.out_act(a3)

But he's using BCELoss not BCEWithLogitsLoss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment