Initialize the output dir.
(args: argparse)
| 153 | |
| 154 | |
| 155 | def get_output_dir(args: argparse): |
| 156 | """ |
| 157 | Initialize the output dir. |
| 158 | """ |
| 159 | |
| 160 | if args.checkpoint_dir is None: |
| 161 | checkpoint_dir = os.path.join(args.root_path, 'checkpoints', args.dataset.lower(), args.backbone.lower(), args.method.lower()) |
| 162 | |
| 163 | name_str = f'-n_way={args.train_way}' \ |
| 164 | f'-n_shot={args.num_shot}' \ |
| 165 | f'-lr={args.lr}' \ |
| 166 | f'-scheduler={args.scheduler}' \ |
| 167 | f'-dropout={args.dropout}' |
| 168 | |
| 169 | checkpoint_dir = os.path.join(checkpoint_dir, name_str) |
| 170 | else: |
| 171 | checkpoint_dir = args.checkpoint_dir |
| 172 | |
| 173 | if args.eval: |
| 174 | return checkpoint_dir |
| 175 | |
| 176 | while os.path.exists(checkpoint_dir): |
| 177 | checkpoint_dir += f'-{np.random.randint(100)}' |
| 178 | |
| 179 | os.makedirs(checkpoint_dir, exist_ok=True) |
| 180 | |
| 181 | # write args to a file |
| 182 | with open(os.path.join(checkpoint_dir, "args.txt"), 'w') as f: |
| 183 | for key, value in vars(args).items(): |
| 184 | f.write('%s:%s\n' % (key, value)) |
| 185 | |
| 186 | print("=> Checkpoints will be saved at:\n", checkpoint_dir) |
| 187 | |
| 188 | return checkpoint_dir |
| 189 | |
| 190 | |
| 191 | def load_weights(model: torch.nn.Module, pretrained_path: str): |
nothing calls this directly
no outgoing calls
no test coverage detected