示例#1
0
print(f'dataset size: {len(dataset)}')

model = model_fn(dataset)

if use_half:
    model = model.half()

for partial_path in args.partial:
    model.load_state_dict(torch.load(partial_path), strict=False)

optimiser = optim.Adam(model.parameters(),
                       lr=args.lr,
                       weight_decay=args.weight_decay)

paths = env.Paths(model_name, data_path)

if args.scratch or args.load == None and not os.path.exists(
        paths.model_path()):
    # Start from scratch
    step = 0
    epoch = 0
else:
    if args.load:
        #remove .pyt extension and step number
        prev_model_name = re.sub(
            r'_[0-9]+$', '', re.sub(r'\.pyt$', '',
                                    os.path.basename(args.load)))
        prev_model_basename = prev_model_name.split('_')[0]
        model_basename = model_name.split('_')[0]
        if prev_model_basename != model_basename and not args.force:
示例#2
0
else:
    raise RuntimeError('bad dataset type')

print(f'dataset size: {len(dataset)}')

model = model_fn(dataset)

if use_half:
    model = model.half()

for partial_path in args.partial:
    model.load_state_dict(torch.load(partial_path), strict=False)

optimiser = optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.weight_decay)

paths = env.Paths(model_name, data_path, args.results_dir, args.exp_name)

if args.scratch or args.load == None and not os.path.exists(paths.model_path()):
    # Start from scratch
    step = 0
    epoch = 0
    print("Start from Scratch.")
else:
    if args.load:
        prev_model_name = re.sub(r'_[0-9]+$', '', re.sub(r'\.pyt$', '', os.path.basename(args.load)))
        prev_model_basename = prev_model_name.split('_')[0]
        model_basename = model_name.split('_')[0]
        if prev_model_basename != model_basename and not args.force:
            sys.exit(f'refusing to load {args.load} because its basename ({prev_model_basename}) is not {model_basename}')
        if args.generate:
            paths = env.Paths(prev_model_name, data_path, args.results_dir, args.exp_name)