[QUESTION] Progress calss out of context manager
See original GitHub issueI’m trying to print the progress of a deep model training.
Since I cannot directly modify the training loop I need to use a class CustomLogger
method which is called at each iteration.
This class stores the total length train_data_len
of the loop and the called method on_batch_end
.
I would like to define a progress class attribute and update it everytime the method is called, like the following:
class CustomLogger(Callback):
def __init__(
self, train_data_len=None, eval_data_len=None, logging_step=50
):
self.train_data_len = train_data_len
self.eval_data_len = eval_data_len
# define the progress class and add train and eval
self.progress = Progress()
self.train_p = self.progress.add_task("Train", total=self.train_data_len)
self.eval_p = self.progress.add_task("Eval", total=self.eval_data_len)
def on_epoch_end(self, loss: float, logs: Interaction, epoch: int):
# at the end of the epoch reset the tasks progress
self.train_p.reset(total=self.train_data_len)
self.eval_p.reset(total=self.eval_data_len)
# called on every loop iteration
def on_batch_end(
self, logs: Interaction, loss: float, batch_id: int, is_training: bool
):
# update the relative task
if is_training:
self.progress.update(self.train_p, advance=1)
else:
self.progress.update(self.eval_p, advance=1)
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Context Managers and Python's with Statement
In this step-by-step tutorial, you'll learn what the Python with statement is and how to use it with existing context managers.
Read more >context manager exit called before code in body
Here is my simple context manager class: class ProgressBar(object): """Progress bar that normalizes progress to [0 - 100] scale" ...
Read more >A Gentle Introduction to Context Managers: The Pythonic Way ...
Explore with statements and the context manager protocol; Implement context manager class to query MongoDB; Convert try...finally block to ...
Read more >Context manager in Python - python coding challenges
So the first question that I wanna talk about is what is the "with" statement actually good for? The "with" statement is great...
Read more >Using python context managers instead of passing arguments
This PyCon 2012 talk summarized several patterns that you'd consider context manager: Open - Close; Lock - Release; Change - Reset ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Indeed it was a Pycharm problem and the solution reported in a previous issue
Ah. There is a note here about a potential fix. But you will probably get better results with a terminal.