|
|
import argparse
|
|
|
import os
|
|
|
import sys
|
|
|
import shutil
|
|
|
import subprocess
|
|
|
|
|
|
def run_inference(input_path, output_path):
|
|
|
|
|
|
cwd = os.path.dirname(os.path.abspath(__file__))
|
|
|
python_exe = sys.executable
|
|
|
inference_script = os.path.join(cwd, "inference_codeformer.py")
|
|
|
|
|
|
print(f"🚀 [CodeFormer] 启动中...")
|
|
|
|
|
|
|
|
|
|
|
|
temp_in = os.path.join(cwd, "temp_worker_input")
|
|
|
if os.path.exists(temp_in): shutil.rmtree(temp_in)
|
|
|
os.makedirs(temp_in, exist_ok=True)
|
|
|
|
|
|
|
|
|
img_name = os.path.basename(input_path)
|
|
|
shutil.copy(input_path, os.path.join(temp_in, img_name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd = [
|
|
|
python_exe,
|
|
|
inference_script,
|
|
|
"-w", "0.5",
|
|
|
"--input_path", temp_in,
|
|
|
"--face_upsample"
|
|
|
]
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
subprocess.run(cmd, cwd=cwd, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
res_dir = os.path.join(cwd, "results", "temp_worker_input_0.5", "final_results")
|
|
|
res_file = os.path.join(res_dir, img_name)
|
|
|
|
|
|
if os.path.exists(res_file):
|
|
|
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
|
|
shutil.copy(res_file, output_path)
|
|
|
print(f"✅ CodeFormer 处理完成: {output_path}")
|
|
|
else:
|
|
|
print(f"❌ 未找到结果文件: {res_file}")
|
|
|
print(" (可能是因为图片里没有人脸,或者模型下载失败)")
|
|
|
|
|
|
except Exception as e:
|
|
|
print(f"❌ 执行出错: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
parser = argparse.ArgumentParser()
|
|
|
parser.add_argument('-i', '--input', required=True)
|
|
|
parser.add_argument('-o', '--output', required=True)
|
|
|
parser.add_argument('-m', '--model', help="Ignored")
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
run_inference(args.input, args.output) |