This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update setup_env and config to use PathManager
Summary: Enables use of PathManager in pycls and updates config to make use of it Reviewed By: vaibhava0 Differential Revision: D24163964 fbshipit-source-id: b9075e5eb4a167065351d348696bf923e65b1c92
- Loading branch information
1 parent
ca89a79
commit b5063a6
Showing
4 changed files
with
53 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import random | ||
|
||
import numpy as np | ||
import pycls.core.config as config | ||
import pycls.core.distributed as dist | ||
import pycls.core.logging as logging | ||
import torch | ||
from iopath.common.file_io import g_pathmgr | ||
from pycls.core.config import cfg | ||
|
||
|
||
logger = logging.get_logger(__name__) | ||
|
||
|
||
def setup_env(): | ||
"""Sets up environment for training or testing.""" | ||
if dist.is_master_proc(): | ||
# Ensure that the output dir exists | ||
g_pathmgr.mkdirs(cfg.OUT_DIR) | ||
# Save the config | ||
config.dump_cfg() | ||
# Setup logging | ||
logging.setup_logging() | ||
# Log torch, cuda, and cudnn versions | ||
version = [torch.__version__, torch.version.cuda, torch.backends.cudnn.version()] | ||
logger.info("PyTorch Version: torch={}, cuda={}, cudnn={}".format(*version)) | ||
# Log the config as both human readable and as a json | ||
logger.info("Config:\n{}".format(cfg)) if cfg.VERBOSE else () | ||
logger.info(logging.dump_log_data(cfg, "cfg", None)) | ||
# Fix the RNG seeds (see RNG comment in core/config.py for discussion) | ||
np.random.seed(cfg.RNG_SEED) | ||
torch.manual_seed(cfg.RNG_SEED) | ||
random.seed(cfg.RNG_SEED) | ||
# Configure the CUDNN backend | ||
torch.backends.cudnn.benchmark = cfg.CUDNN.BENCHMARK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters