1 Star 0 Fork 0

michaelowenliu/ritm_interactive_segmentation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
train.py 3.03 KB
一键复制 编辑 原始数据 按行查看 历史
Konstantin Sofiiuk 提交于 2021-02-13 04:23 +08:00 . Init commit
import os
import argparse
import importlib.util
import torch
from isegm.utils.exp import init_experiment
def main():
args = parse_args()
if args.temp_model_path:
model_script = load_module(args.temp_model_path)
else:
model_script = load_module(args.model_path)
model_base_name = getattr(model_script, 'MODEL_NAME', None)
args.distributed = 'WORLD_SIZE' in os.environ
cfg = init_experiment(args, model_base_name)
torch.backends.cudnn.benchmark = True
torch.multiprocessing.set_sharing_strategy('file_system')
model_script.main(cfg)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('model_path', type=str,
help='Path to the model script.')
parser.add_argument('--exp-name', type=str, default='',
help='Here you can specify the name of the experiment. '
'It will be added as a suffix to the experiment folder.')
parser.add_argument('--workers', type=int, default=4,
metavar='N', help='Dataloader threads.')
parser.add_argument('--batch-size', type=int, default=-1,
help='You can override model batch size by specify positive number.')
parser.add_argument('--ngpus', type=int, default=1,
help='Number of GPUs. '
'If you only specify "--gpus" argument, the ngpus value will be calculated automatically. '
'You should use either this argument or "--gpus".')
parser.add_argument('--gpus', type=str, default='', required=False,
help='Ids of used GPUs. You should use either this argument or "--ngpus".')
parser.add_argument('--resume-exp', type=str, default=None,
help='The prefix of the name of the experiment to be continued. '
'If you use this field, you must specify the "--resume-prefix" argument.')
parser.add_argument('--resume-prefix', type=str, default='latest',
help='The prefix of the name of the checkpoint to be loaded.')
parser.add_argument('--start-epoch', type=int, default=0,
help='The number of the starting epoch from which training will continue. '
'(it is important for correct logging and learning rate)')
parser.add_argument('--weights', type=str, default=None,
help='Model weights will be loaded from the specified path if you use this argument.')
parser.add_argument('--temp-model-path', type=str, default='',
help='Do not use this argument (for internal purposes).')
parser.add_argument("--local_rank", type=int, default=0)
return parser.parse_args()
def load_module(script_path):
spec = importlib.util.spec_from_file_location("model_script", script_path)
model_script = importlib.util.module_from_spec(spec)
spec.loader.exec_module(model_script)
return model_script
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/michaelowenliu/ritm_interactive_segmentation.git
git@gitee.com:michaelowenliu/ritm_interactive_segmentation.git
michaelowenliu
ritm_interactive_segmentation
ritm_interactive_segmentation
master

搜索帮助