danhtran2mind commited on
Commit
26d8676
·
verified ·
1 Parent(s): 3e0e9b6

Delete src/anime_super_resolution/old-train.py

Browse files
src/anime_super_resolution/old-train.py DELETED
@@ -1,71 +0,0 @@
1
- import sys
2
- import os
3
- import subprocess
4
- import argparse
5
- import yaml
6
- import shutil
7
-
8
- # Get the absolute path to the Real-ESRGAN directory
9
- real_esrgan_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'third_party', 'Real-ESRGAN'))
10
-
11
- def train(args):
12
- # Ensure the config file exists
13
- if not os.path.exists(args.config):
14
- raise FileNotFoundError(f"Configuration file {args.config} not found")
15
-
16
- # Read the YAML config file to get the experiment name
17
- with open(args.config, 'r') as f:
18
- config_data = yaml.safe_load(f)
19
- experiment_name = config_data.get('name', 'default_experiment')
20
-
21
- # Set up environment for subprocess
22
- env = os.environ.copy()
23
- env['PYTHONPATH'] = f"{real_esrgan_dir}{os.pathsep}{env.get('PYTHONPATH', '')}"
24
-
25
- # Execute the Real-ESRGAN training command
26
- try:
27
- command = [
28
- sys.executable, # Use the current Python executable
29
- os.path.join(real_esrgan_dir, 'realesrgan', 'train.py'),
30
- '-opt', args.config
31
- ]
32
- if args.auto_resume:
33
- command.append('--auto_resume')
34
-
35
- subprocess.run(command, env=env, check=True) # Pass the modified environment
36
-
37
- # Move the entire experiment directory to output_model_dir
38
- if args.output_model_dir:
39
- source_dir = os.path.join(real_esrgan_dir, 'experiments', experiment_name)
40
- target_dir = os.path.abspath(args.output_model_dir)
41
-
42
- # Create target directory if it doesn't exist
43
- os.makedirs(target_dir, exist_ok=True)
44
-
45
- # Move the entire source directory to target
46
- if os.path.exists(source_dir):
47
-
48
- shutil.move(source_dir, target_dir)
49
- print(f"Moved experiment directory from {source_dir} to {args.output_model_dir}")
50
- else:
51
- print(f"Warning: Source directory {source_dir} does not exist")
52
-
53
- except subprocess.CalledProcessError as e:
54
- print(f"Training failed with error: {e}")
55
- sys.exit(1)
56
- except Exception as e:
57
- print(f"Error moving directory: {e}")
58
- sys.exit(1)
59
-
60
- if __name__ == "__main__":
61
- # Parse command-line arguments
62
- parser = argparse.ArgumentParser(description='Run Real-ESRGAN training with specified config')
63
- parser.add_argument('--config', type=str, default='configs/Real-ESRGAN-Anime-finetuning.yml',
64
- help='Path to the configuration YAML file')
65
- parser.add_argument('--auto_resume', action='store_true',
66
- help='Automatically resume training from the latest checkpoint')
67
- parser.add_argument('--output_model_dir', type=str, default='ckpts',
68
- help='Path to move experiment directory after training')
69
- args = parser.parse_args()
70
-
71
- train(args)