-
-
Notifications
You must be signed in to change notification settings - Fork 656
Add quickstart guide and concepts, issue #108 #142
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
Conversation
alykhantejani
left a comment
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.
Looks great @vfdev-5! Thanks!
docs/source/quickstart.rst
Outdated
| }) | ||
| @trainer.on(Events.ITERATION_COMPLETED) | ||
| def log_training_loss(engine): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
docs/source/quickstart.rst
Outdated
| print("Epoch[{}] Loss: {:.2f}".format(engine.state.epoch, len(train_loader), engine.state.output)) | ||
| @trainer.on(Events.EPOCH_COMPLETED) | ||
| def log_validation_results(engine): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
docs/source/quickstart.rst
Outdated
| Next we define trainer and evaluator engines. The main component of Ignite is the :class:`Engine`, an abstraction over your | ||
| training loop. Getting started with the engine is easy, the constructor only requires one things: | ||
|
|
||
| - `update_function`: a function which is passed a batch and passes data through and updates your model |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
docs/source/quickstart.rst
Outdated
| y_pred = model(x) | ||
| return to_tensor(y_pred, cpu=not cuda), to_tensor(y, cpu=not cuda) | ||
| Remark that the helper function :meth:`create_supervised_evaluator` to create an evaluator accepts an |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
docs/source/quickstart.rst
Outdated
|
|
||
|
|
||
| The most interesting part of the code snippet is adding event handlers. :class:`Engine` allows to add handlers on | ||
| various events that fired during the run. When event is fired, attached handlers (functions) are executed. Thus, for |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| When an epoch ends we want to run model validation, therefore we attach another handler to the trainer on epoch complete | ||
| event: | ||
|
|
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
@alykhantejani thanks for the comments! I updated the text according to your comments and added a "(!) Note" as here about "passing other args to handlers". |
|
Added basic concepts |
| ------ | ||
|
|
||
| The **essence** of the framework is the class :class:`Engine`, an abstraction that loops given number of times over | ||
| provided data, executes a processing and returns a result: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| Engine | ||
| ------ | ||
|
|
||
| The **essence** of the framework is the class :class:`Engine`, an abstraction that loops given number of times over |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
Thanks @vfdev-5! |
|
@alykhantejani do you still want me to integrate your comments, as you merged the branch ? |
|
@vfdev-5 if you don't mind, it was very minor though so didn't want to delay merging this. I need to get the docs ready to be hosted and start building the conda tar + wheels for release |
|
@alykhantejani no problems, go ahead with your tasks. Thanks! |
|
@vfdev-5 Thanks a lot! These both look great. I think the only other thing I would maybe add is a mention in the "State" section of "concepts" about the ability to add arbitrary data to the state object in handlers. |
|
@jasonkriss yes, this is an important point that completly missed, thanks! At the begining I thought we would fix the scope of the state, especially when talking about engine checkpointing and restoration. As it is more or less fixed, I can add this in another PR. |
|
@jasonkriss rethinking about what you said:
Do you talk about this (same with handler functions): import numpy as np
from torch.utils.data import DataLoader
from ignite.engines import Engine
def update(engine, batch):
engine.state.new_attribute = 12345
engine = Engine(update)
data = np.arange(100)
data = DataLoader(data, batch_size=10)
state = engine.run(data, max_epochs=2)
for attr, value in state.__dict__.items():
print(attr, value)with the output: if yes, we can add a new attribute to I thought also to add the method def __repr__(self):
s = "State:\n"
for attr, value in self.__dict__.items():
value = value if not torch.is_tensor(value) else "{} {}".format(type(value), value.shape)
s += "\t{}: {}\n".format(attr, value)
return s@alykhantejani @jasonkriss what do you think about ? |
|
@jasonkriss can you please take a look on the previous comment ? |
|
Sorry for the delay on this @vfdev-5 . The @vfdev-5 Did you have another question there? I'm not 100% sure I understood. |
|
@jasonkriss no problem, my question was actually about your comment:
Did you talk about this ? import numpy as np
from torch.utils.data import DataLoader
from ignite.engines import Engine
def update(engine, batch):
engine.state.new_attribute = 12345
engine = Engine(update)
data = np.arange(100)
data = DataLoader(data, batch_size=10)
state = engine.run(data, max_epochs=2)
for attr, value in state.__dict__.items():
print(attr, value) |
|
yep exactly. Setting that |
|
Right, but actually this is not only ability of |
|
@vfdev-5 yes, I think we want to note that this is the preferred way to pass state between handlers. When we get to serializing the engine + state, we may have to re-visit this. But for now I think if we establish this user pattern it will be easier |
|
@alykhantejani nailed it. I should have made that more clear. The important point is not that you can attach attributes to |
|
Talking about attaching user attributes in |
|
I've been using this feature successfully since we added it. If my attribute is a list or a dict, I will initialize it if its |
|
Sure, I agree with what you say. However, for me |
I propose to address the issue 108 in multiple PRs. Here is the first one with "Quickstart" notes.
Other notes can be added later.
@alykhantejani @jasonkriss could you review this note, please ?