-
Notifications
You must be signed in to change notification settings - Fork 346
Refactored Eth_Mnist #273
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
Refactored Eth_Mnist #273
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,12 @@ | |
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| from torchvision import transforms | ||
|
|
||
| from time import time as t | ||
|
|
||
| from bindsnet.datasets import MNIST | ||
| from bindsnet.encoding import PoissonEncoder | ||
| from bindsnet.encoding import poisson_loader | ||
| from bindsnet.models import DiehlAndCook2015 | ||
| from bindsnet.network.monitors import Monitor | ||
|
|
@@ -80,11 +83,30 @@ | |
| network.add_monitor(inh_voltage_monitor, name="inh_voltage") | ||
|
|
||
| # Load MNIST data. | ||
| images, labels = MNIST( | ||
| path=os.path.join("..", "..", "data", "MNIST"), download=True | ||
| ).get_train() | ||
| images = images.view(-1, 784) | ||
| images *= intensity | ||
| # images, labels | ||
| dataset = MNIST( | ||
| None, | ||
| None, | ||
| root=os.path.join("..", "..", "data", "MNIST"), | ||
| download=True, | ||
| transform=transforms.Compose( | ||
| [ | ||
| transforms.ToTensor(), | ||
| transforms.Lambda(lambda x: x * intensity), | ||
| transforms.Lambda(lambda x: x.view(784)), | ||
| ] | ||
| ), | ||
| ) | ||
| # .get_train() | ||
|
|
||
| images = [] | ||
| labels = [] | ||
|
|
||
| for i in range(len(dataset)): | ||
| sample = dataset[i] | ||
| images.append(sample["image"]) | ||
| labels.append(sample["label"]) | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how I feel about this refactor. It would be difficult for somebody to take this and apply it to a larger dataset because of the extraction of this data ahead of time. I'll leave the final call on this to somebody else though.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this doesn't make sense. @coopersigrist You should pass a
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed! I'm gonna start redoing this now. I'll close this request and make the changes |
||
|
|
||
| # Lazily encode data as Poisson spike trains. | ||
| data_loader = poisson_loader(data=images, time=time, dt=dt) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can be
Noneas the order of the arguments matter in this case. The point is to split the requirements. First we take care of Bindsnet requirementsimage_encoderandlabel_encoderthen we take care of specific dataset requirements*argsand**kwargs. I think forcing these (even if somebody putsNone) keeps the consistency. @djsaunde thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense. @coopersigrist can you remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does make sense, the requirements need to be split.
But, the default of the encoders need to be
None, if the specific dataset require different encoder it will be specified later on in*argsand**kwargsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to seperate them while keeping a default value? I agree that it's not necessary at all to make this change so if the preferred style is no default values I think we should definitely change it back.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hananel-Hazan The problem is not that the default Encoder should be
None(it should be, and still is!), it's that if no arguments are specified forimage_encoderandlabel_encoder, then theTorchvisionDatasetWrapperconstructor won't know which argument to pass for the requiredrootargument of the dataset class it wraps.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@k-chaney What about the following?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something important to remember is that this is a wrapper only for the datasets provided by
torchvision. There won't be any other formats and one shouldn't arbitrarily use this wrapper on other datasets. Second, if a default is provided forimage_encoderandlabel_encoderwithout moving them to the keyword section of the function signature you'll see the following. In this toy example I mirror what is seen in the proposed argument structure:Most of the time people would provide an argument for
aand you would see (this is ideal case):But some people would skip providing an argument for
aand that would result in the following:Even further some people would provide
aas a keyword argument later on: