0%

shell(实例完成自动化dl模型测试)

2019年11月1日 下午5:39

目标:

实现自动化测试深度学习训练出来的模型

实现方式:

  1. 这其中涉及到expect的安装和使用:用来自动化交互过程
    1. shell脚本传参实现scp命令无需输入密码和别的参数
    2. Linux expect 介绍和用法 - 梦徒 - 博客园
    3. expect实现scp/ssh-copy-id非交互 - 骏马金龙 - 博客园
  2. 其中的代码主要是使用shell语言写
    1. scp 文件 : /目录: Permission denied 要记得给.sh文件777的权限
      1. chmod 777 *.sh
    2. Shell中for循环的几个常用写法 - 虚生 - 博客园 for循环
    3. 判断文件是否存在的shell脚本代码! - 孤舟点点 - 博客园 if 文件判断
auto_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash

# 定义
port=22778
user_ip="zhiheng_chen@210.76.196.61"
dataset="OTB100"
src_path="/data/zhiheng_chen/"

# 无限循环
while ((1 > 0))
do
# 循环1~20 的checkpoint
for i in $(seq 1 20)
do
checkpoint_file="checkpoint_e"$i".pth"
snapshot_checkpoint_file="./snapshot/"$checkpoint_file
src_file=$src_path$checkpoint_file
# 如果本地没有这个模型,才执行scp.sh
if [ ! -f $snapshot_checkpoint_file ]; then
# 执行下载和模型检测
./scp.sh $port $user_ip $src_file $snapshot_checkpoint_file $dataset
fi
done
sleep 3
done
scp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/home/chenzhiheng18/installed/bin/expect

set port [lindex $argv 0]
set user_ip [lindex $argv 1]
set src_file [lindex $argv 2]
set snapshot [lindex $argv 3]
set dataset [lindex $argv 4]

set timeout -1
# 打印信息
spawn echo "src_file: $src_file"
spawn echo "snapshot: $snapshot"
spawn echo "dataset: $dataset"

# 执行scp
spawn scp -P $port -r $user_ip:$src_file ./snapshot/
expect {
"(yes/no)?" {
send "yes\n"
expect "*assword:" {
send "chen_gpu\n"
# 如果不存在,则直接结束当前bash
expect "No such file or directory" {
exit
}
# 执行测试
spawn python -u ../../tools/test.py --snapshot $snapshot --dataset $dataset --config config.yaml
}
}
"*assword:" {
send "chen_gpu\n"
# 如果不存在,则直接结束当前bash
expect "No such file or directory" {
exit
}
# 执行测试
spawn python -u ../../tools/test.py --snapshot $snapshot --dataset $dataset --config config.yaml

}
}

expect eof