新增测试脚本和日志记录功能

- 添加 test_shell.py脚本,实现自动测试和日志记录功能
- 新增 deployment.xml 和 iml 文件,配置项目部署和模块信息
- 添加 log_20241008_success.log 和 status.md 文件,记录测试结果和状态
- 更新 test_IVF.py,修改测试模型和输出路径
This commit is contained in:
whaifree 2024-10-09 11:52:46 +08:00
parent 5e3fc11c37
commit f95b13b8aa
5 changed files with 131 additions and 4 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea/

View File

@ -0,0 +1,38 @@
/home/star/anaconda3/envs/pfcfuse/bin/python /home/star/whaiDir/PFCFuse/test_IVF.py
================================================================================
The test result of TNO :
19.png
05.png
21.png
18.png
15.png
22.png
14.png
13.png
08.png
01.png
02.png
03.png
25.png
17.png
11.png
16.png
06.png
07.png
09.png
10.png
12.png
23.png
24.png
20.png
04.png
EN SD SF MI SCD VIF Qabf SSIM
PFCFuse 7.01 40.4 15.51 1.55 1.75 0.66 0.54 0.96
================================================================================
Process finished with exit code 0

45
logs/status.md Normal file
View File

@ -0,0 +1,45 @@
PFCFuse
20241008
```
/home/star/anaconda3/envs/pfcfuse/bin/python /home/star/whaiDir/PFCFuse/test_IVF.py
================================================================================
The test result of TNO :
19.png
05.png
21.png
18.png
15.png
22.png
14.png
13.png
08.png
01.png
02.png
03.png
25.png
17.png
11.png
16.png
06.png
07.png
09.png
10.png
12.png
23.png
24.png
20.png
04.png
EN SD SF MI SCD VIF Qabf SSIM
PFCFuse 7.01 40.4 15.51 1.55 1.75 0.66 0.54 0.96
================================================================================
Process finished with exit code 0
```

View File

@ -13,13 +13,14 @@ logging.basicConfig(level=logging.CRITICAL)
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
ckpt_path= r"models/PFCFuse.pth"
ckpt_path= r"PFCFuse_IVF.pth"
for dataset_name in ["TNO","RoadScene"]:
for dataset_name in ["MSRS","TNO","RoadScene"]:
print("\n"*2+"="*80)
model_name="PFCFuse "
print("The test result of "+dataset_name+' :')
test_folder=os.path.join('test_img',dataset_name)
test_folder=os.path.join('test_img',dataset_name)
test_out_folder=os.path.join('test_result',dataset_name)
device = 'cuda' if torch.cuda.is_available() else 'cpu'
@ -39,6 +40,7 @@ for dataset_name in ["MSRS","TNO","RoadScene"]:
with torch.no_grad():
for img_name in os.listdir(os.path.join(test_folder,"ir")):
print(img_name)
data_IR=image_read_cv2(os.path.join(test_folder,"ir",img_name),mode='GRAY')[np.newaxis,np.newaxis, ...]/255.0
data_VIS = cv2.split(image_read_cv2(os.path.join(test_folder, "vi", img_name), mode='YCrCb'))[0][np.newaxis, np.newaxis, ...] / 255.0
@ -60,7 +62,7 @@ for dataset_name in ["MSRS","TNO","RoadScene"]:
rgb_fi = cv2.cvtColor(ycrcb_fi, cv2.COLOR_YCrCb2RGB)
img_save(rgb_fi, img_name.split(sep='.')[0], test_out_folder)
eval_folder=test_out_folder
eval_folder=test_out_folder
ori_img_folder=test_folder
metric_result = np.zeros((8))

41
test_shell.py Normal file
View File

@ -0,0 +1,41 @@
import os
import subprocess
import datetime
import sys
# 定义命令
command = "/home/star/anaconda3/envs/pfcfuse/bin/python /home/star/whaiDir/PFCFuse/test_IVF.py"
# 获取当前时间并格式化为文件名
current_time = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
output_file = f"/home/star/whaiDir/PFCFuse/logs/ans_log_{current_time}.log"
try:
# 打开文件用于写入
with open(output_file, 'w') as log_file:
# 运行命令
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True)
# 循环读取输出
for line in process.stdout:
# 同时打印到控制台和写入文件
print(line.strip())
log_file.write(line)
log_file.flush() # 确保立即写入文件
# 等待命令完成
process.wait()
# 检查返回码
if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, command)
# 如果命令成功执行,则打印确认信息
print(f"Command executed successfully. Output has been written to {output_file}")
except subprocess.CalledProcessError as e:
# 如果命令执行失败,则删除文件并打印错误信息
if os.path.exists(output_file):
os.remove(output_file)
print(f"Command failed with return code {e.returncode}. No log file was created.")