question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use TimeMetricsHook in a train task?

See original GitHub issue

❓ Questions and Help

I want use TimeMetricsHook to get the training performance, but I face the following error:

Traceback (most recent call last):
  File "main.py", line 255, in <module>
    main()
  File "main.py", line 111, in main
    train(datasets, model, loss, optimizer, meters, args)
  File "main.py", line 145, in train
    trainer.train(task)
  File "/home/xiaobinz/anaconda3/envs/pytorch-bw/lib/python3.6/site-packages/classy_vision/trainer/classy_trainer.py", line 78, in train
    task.step(self.use_gpu)
  File "/home/xiaobinz/anaconda3/envs/pytorch-bw/lib/python3.6/site-packages/classy_vision/tasks/classy_task.py", line 178, in step
    hook.on_step(self)
  File "/home/xiaobinz/anaconda3/envs/pytorch-bw/lib/python3.6/site-packages/classy_vision/hooks/time_metrics_hook.py", line 50, in on_step
    self._log_performance_metrics(task)
  File "/home/xiaobinz/anaconda3/envs/pytorch-bw/lib/python3.6/site-packages/classy_vision/hooks/time_metrics_hook.py", line 84, in _log_performance_metrics
    get_rank(), task.perf_stats.report_str()
  File "/home/xiaobinz/anaconda3/envs/pytorch-bw/lib/python3.6/site-packages/classy_vision/generic/perf_stats.py", line 217, in report_str
    name_width = max(len(k) for k in self._host_stats.keys())
ValueError: max() arg is an empty sequence

The following code is how do I use TimeMetricsHook in my model:

def train(datasets, model, loss, optimizer, meters, args):
     task = (ClassificationTask()
             .set_num_epochs(args.num_epochs)
             .set_loss(loss)
             .set_model(model)
             .set_optimizer(optimizer)
             .set_meters(meters))
     for phase in ["train", "test"]:
         task.set_dataset(datasets[phase], phase)

     hooks = [LossLrMeterLoggingHook(log_freq=args.print_freq)]
     # show progress
     hooks.append(ProgressBarHook())
     # show time bar
     hooks.append(TimeMetricsHook(log_freq=args.print_freq))

     checkpoint_dir = f"{args.video_dir}/checkpoint/classy_checkpoint_{time.time()}"
     os.mkdir(checkpoint_dir)
     hooks.append(CheckpointHook(checkpoint_dir, input_args={}))

     task = task.set_hooks(hooks)
     trainer = LocalTrainer(use_gpu = args.cuda)
     trainer.train(task)

The LossLrMeterLoggingHook , ProgressBarHook, and CheckpointHook can works, but add TimeMetricsHook, will get the error.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mannatsinghcommented, Mar 26, 2020

Yes, the TimeMetricsHook doesn’t work with ClassificationTask anymore. I think it was preserved for when users wanted to add the perf stats logic in the task for debugging. @vreis maybe we can remove the hook / add a warning to the docs if we still want to retain that hook.

@XiaobingSuper to get the training performance, you can just use the TensorboardPlotHook. We plot the training time per epoch. A sample run looks like this - image

1reaction
XiaobingSupercommented, Mar 27, 2020

Thanks for all your help, now, I will try to use TensorboardPlotHook to get the training performance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generalizations and Extensions to the Hexagon Train Task
Many students create a table of perimeters of the hexagons by simply counting the number of sides or by visualizing the perimeter as...
Read more >
Hexagon Train Task
Train. Number. Perimeter. Compute the perimeter for the first 4 trains, then organize your data in the table. Write the NOW-NEXT Rule: Is...
Read more >
Creating a Train Using an ADF Bounded Task Flow
This tutorial shows you how to create bounded task flows with a train sequence that represents activities in a multistep page flow. To...
Read more >
How to Create Trains and Bounded Task Flows in Oracle ADF
This video tutorial from https://www.fireboxtraining.com demonstrates how to create a bounded task flow that uses a train.
Read more >
The role of cue utilisation in reducing the workload in a train ...
Practitioner Summary: This study was designed to explain differences in the way in which people learn, particularly when tasks involve recurring patterns. Using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found