本文整理汇总了Python中utils.util.mkdirs方法的典型用法代码示例。如果您正苦于以下问题:Python util.mkdirs方法的具体用法?Python util.mkdirs怎么用?Python util.mkdirs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.util
的用法示例。
在下文中一共展示了util.mkdirs方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import mkdirs [as 别名]
def __init__(self, opt, save_dir, filename='loss_log.txt'):
self.display_id = opt.display_id
self.use_html = not opt.no_html
self.win_size = opt.display_winsize
self.save_dir = save_dir
self.name = os.path.basename(self.save_dir)
self.saved = False
self.display_single_pane_ncols = opt.display_single_pane_ncols
# Error plots
self.error_plots = dict()
self.error_wins = dict()
if self.display_id > 0:
import visdom
self.vis = visdom.Visdom(port=opt.display_port)
if self.use_html:
self.web_dir = os.path.join(self.save_dir, 'web')
self.img_dir = os.path.join(self.web_dir, 'images')
print('create web directory %s...' % self.web_dir)
util.mkdirs([self.web_dir, self.img_dir])
self.log_name = os.path.join(self.save_dir, filename)
with open(self.log_name, "a") as log_file:
now = time.strftime("%c")
log_file.write('================ Training Loss (%s) ================\n' % now)
示例2: initialize
# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import mkdirs [as 别名]
def initialize(self, opt):
self.opt = opt
self.training = opt.isTrain
self.gpu_ids = opt.gpu_ids
self.isTrain = opt.isTrain
self.num_classes = opt.label_nc
self.Tensor = torch.cuda.FloatTensor if self.gpu_ids else torch.Tensor
self.save_dir = os.path.join(opt.checkpoints_dir, opt.name)
self.tensorborad_dir = os.path.join(self.opt.checkpoints_dir, 'tensorboard', opt.dataset_mode)
self.model_dir = os.path.join(self.opt.checkpoints_dir, self.opt.name, 'model')
util.mkdirs([self.tensorborad_dir, self.model_dir])
示例3: parse
# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import mkdirs [as 别名]
def parse(self):
if not self.initialized:
self.initialize()
self.opt = self.parser.parse_args()
# str_ids = self.opt.gpu_ids.split(',')
# self.opt.gpu_ids = []
# for str_id in str_ids:
# id = int(str_id)
# if id >= 0:
# self.opt.gpu_ids.append(id)
args = vars(self.opt)
print('------------ Options -------------')
for k, v in sorted(args.items()):
print('%s: %s' % (str(k), str(v)))
print('-------------- End ----------------')
# save to the disk
if self.opt.exp_id == '':
print('Please set the experimental ID with option --exp_id')
exit()
exp_dir = os.path.join(self.opt.exp_dir, self.opt.exp_id)
util.mkdirs(exp_dir)
if self.opt.resume_prefix != '':
trunc_index = self.opt.resume_prefix.index('pth')
self.opt.resume_prefix = self.opt.resume_prefix[0:trunc_index - 1]
self.opt.resume_prefix += '-'
file_name = os.path.join(exp_dir, 'opt.txt')
with open(file_name, 'wt') as opt_file:
opt_file.write('------------ Options -------------\n')
for k, v in sorted(args.items()):
opt_file.write('%s: %s\n' % (str(k), str(v)))
opt_file.write('-------------- End ----------------\n')
return self.opt
示例4: _save
# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import mkdirs [as 别名]
def _save(self, args):
expr_dir = os.path.join(self._opt.checkpoints_dir, self._opt.name)
print(expr_dir)
util.mkdirs(expr_dir)
file_name = os.path.join(expr_dir, 'opt_%s.txt' % ('train' if self.is_train else 'test'))
with open(file_name, 'wt') as opt_file:
opt_file.write('------------ Options -------------\n')
for k, v in sorted(args.items()):
opt_file.write('%s: %s\n' % (str(k), str(v)))
opt_file.write('-------------- End ----------------\n')
示例5: parse
# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import mkdirs [as 别名]
def parse(self, save=True):
if not self.initialized:
self.initialize()
self.opt = self.parser.parse_args()
self.opt.isTrain = self.isTrain # train or test
str_ids = self.opt.gpu_ids.split(',')
self.opt.gpu_ids = []
for str_id in str_ids:
id = int(str_id)
if id >= 0:
self.opt.gpu_ids.append(id)
str_sizes = self.opt.fineSize.split(',')
self.opt.fineSize = []
for str_size in str_sizes:
size_ = int(str_size)
if size_ >= 0:
self.opt.fineSize.append(size_)
# set gpu ids
if len(self.opt.gpu_ids) > 0:
torch.cuda.set_device(self.opt.gpu_ids[0])
args = vars(self.opt)
print('------------ Options -------------')
for k, v in sorted(args.items()):
print('%s: %s' % (str(k), str(v)))
print('-------------- End ----------------')
# save to the disk
expr_dir = os.path.join(self.opt.checkpoints_dir, self.opt.name)
util.mkdirs(expr_dir)
if save:
file_name = os.path.join(expr_dir, 'opt.txt')
with open(file_name, 'wt') as opt_file:
opt_file.write('------------ Options -------------\n')
for k, v in sorted(args.items()):
opt_file.write('%s: %s\n' % (str(k), str(v)))
opt_file.write('-------------- End ----------------\n')
return self.opt
示例6: parse
# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import mkdirs [as 别名]
def parse(self):
if not self.initialized:
self.initialize()
self.opt = self.parser.parse_args()
# str_ids = self.opt.gpu_ids.split(',')
# self.opt.gpu_ids = []
# for str_id in str_ids:
# id = int(str_id)
# if id >= 0:
# self.opt.gpu_ids.append(id)
args = vars(self.opt)
print('------------ Options -------------')
for k, v in sorted(args.items()):
print('%s: %s' % (str(k), str(v)))
print('-------------- End ----------------')
# save to the disk
if self.opt.exp_id == '':
print('Please set the experimental ID with option --exp_id')
exit()
exp_dir = os.path.join(self.opt.exp_dir, self.opt.exp_id)
util.mkdirs(exp_dir)
if self.opt.resume_prefix_pose != '':
trunc_index = self.opt.resume_prefix_pose.index('pth')
self.opt.resume_prefix_pose = self.opt.resume_prefix_pose[0:trunc_index - 1]
self.opt.resume_prefix_pose += '-'
# opt_name = self.opt.resume_prefix_pose + 'opt.txt'
# opt_name = os.path.join(exp_dir, opt_name)
# else:
# opt_name = os.path.join(exp_dir, 'opt.txt')
if self.opt.resume_prefix_asn != '':
trunc_index = self.opt.resume_prefix_asn.index('pth')
self.opt.resume_prefix_asn = self.opt.resume_prefix_asn[0:trunc_index - 1]
self.opt.resume_prefix_asn += '-'
# opt_name = self.opt.resume_prefix_asdn + 'opt.txt'
# opt_name = os.path.join(exp_dir, opt_name)
# else:
# opt_name = os.path.join(exp_dir, 'opt.txt')
if self.opt.resume_prefix_dropout != '':
trunc_index = self.opt.resume_prefix_dropout.index('pth')
self.opt.resume_prefix_dropout = self.opt.resume_prefix_dropout[0:trunc_index - 1]
self.opt.resume_prefix_dropout += '-'
if self.opt.resume_prefix_aug != '':
trunc_index = self.opt.resume_prefix_aug.index('pth')
self.opt.resume_prefix_aug = self.opt.resume_prefix_aug[0:trunc_index - 1]
self.opt.resume_prefix_aug += '-'
with open('opt.txt', 'wt') as opt_file:
opt_file.write('------------ Options -------------\n')
for k, v in sorted(args.items()):
opt_file.write('%s: %s\n' % (str(k), str(v)))
opt_file.write('-------------- End ----------------\n')
return self.opt