Skip to content
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

[Enhance] Distinguish training/testing saving directory #1036

Conversation

shufanwu
Copy link
Contributor

@shufanwu shufanwu commented Apr 1, 2023

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Distinguish training/testing saving directory.

Modification

add suffix for log_dir in Runner after call train() val() test() functions.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Apr 1, 2023

CLA assistant check
All committers have signed the CLA.

'the value of task type must be one of ["train", "val", "test"]')
previous_log_dir = self._log_dir
self._log_dir = '_'.join([self._log_dir, task_type])
shutil.move(previous_log_dir, self._log_dir)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, will the FileHandler in the logger still save logs to the old log file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can fix this if it should modify the log file in FileHandles, and I wonder whether the save_dir in visualizer should modify in the same time.

Copy link
Collaborator

@HAOCHENYE HAOCHENYE Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all opened files should be closed and redirected to the new directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we close the files opened by TensorboardVisBackend, when we want to use it once again, we must to create a new instance of TensorboardVisBackend and it may create two events.out file in the log dir. Is this what we expect?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emm, resuming a visualization seems weird and dirty more or less. A more reasonable workaround is that we should lazy initialize the visualizer in test, train, val rather than __init__ , but I'm not sure will it has a side effect.

Besides, if I first run runner.train(), and then run runer.test(), does it mean we need to create a new visualizer and logger during test? What is the lifespan of the logger and visualization? Maybe we need to rethink it carefully. What do you think of it?

Copy link
Contributor Author

@shufanwu shufanwu Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can record which function has been called and change the log dir in magic fuc __del__ when the instance of runner is finished.

Copy link
Collaborator

@HAOCHENYE HAOCHENYE Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this: We maintain the current logic of runner.train, keeping the output log file names unchanged. However, we add a condition in runner.test. If the train_loop has already been initialized (indicating that testing is being conducted immediately after training), we will not change the log path. On the other hand, if the train_loop has not been initialized (meaning the test is being run directly), we can simply rename the folder at the end of the testing process. This way, there is no need to modify the output paths for FileHandler and Visualizer. Does this approach sound reasonable to you?

@shufanwu shufanwu requested a review from HAOCHENYE April 6, 2023 13:12
@shufanwu shufanwu force-pushed the sfwu/create_differentiated_logdir_name branch from 7966b63 to c5c3424 Compare April 17, 2023 13:40
@HAOCHENYE HAOCHENYE added this to the 0.7.3 milestone Apr 23, 2023
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@a7d4b7c). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1036   +/-   ##
=======================================
  Coverage        ?   77.78%           
=======================================
  Files           ?      139           
  Lines           ?    11307           
  Branches        ?     2278           
=======================================
  Hits            ?     8795           
  Misses          ?     2118           
  Partials        ?      394           
Flag Coverage Δ
unittests 77.78% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Using different names when saving training and testing log.
3 participants