代码拉取完成,页面将自动刷新
#!/bin/bash
# Copyright xmuspeech (Author:Snowdar 2019-03-16)
objects="diagnostic valid train" # default all.
outputname="output"
. subtools/parse_options.sh
if [[ $# != 2 ]];then
echo "[exit] Num of parameters is not equal to 2"
echo "usage:$0 <model-logdir> <outdir>"
exit 1
fi
logdir=$1
outdir=$2
mkdir -p $outdir
for object in $objects;do
case $object in
diagnostic)
log=$(ls $logdir/compute_prob_train.*.log)
[ "$log" == "" ] && echo "[Warning] No $object logs in $logdir, so skip it."
> $outdir/$object.loss
max=0
for x in $log;do
iter=$(echo "$x" | sed 's/\./ /g' | awk '{print $(NF-1)}')
[ "$iter" != "final" ] && [ "$iter" -gt "$max" ] && max=$iter
value=$(awk -v name=$outputname '{if($3=="Overall" && $4=="log-likelihood" && $6=="'\''"name"'\''") {value=$8;}}END{print value}' $x)
[ "$value" != "" ] && echo "$iter $value" >> $outdir/$object.loss
done
max=`expr $max + 2`
sed -i 's/final/'"$max"'/g' $outdir/$object.loss
sort -n -k 1 $outdir/$object.loss -o $outdir/$object.loss
;;
valid)
log=$(ls $logdir/compute_prob_valid.*.log)
[ "$log" == "" ] && echo "[Warning] No $object logs in $logdir, so skip it."
> $outdir/$object.loss
max=0
for x in $log;do
iter=$(echo "$x" | sed 's/\./ /g' | awk '{print $(NF-1)}')
[ "$iter" != "final" ] && [ "$iter" -gt "$max" ] && max=$iter
value=$(awk -v name=$outputname '{if($3=="Overall" && $4=="log-likelihood" && $6=="'\''"name"'\''") {value=$8;}}END{print value}' $x)
[ "$value" != "" ] && echo "$iter $value" >> $outdir/$object.loss
done
max=`expr $max + 2`
sed -i 's/final/'"$max"'/g' $outdir/$object.loss
sort -n -k 1 $outdir/$object.loss -o $outdir/$object.loss
;;
train)
log=$(ls $logdir/train.*.*.log)
[ "$log" == "" ] && echo "[Warning] No $object logs in $logdir, so skip it."
> $outdir/$object.parallel.loss
for x in $log;do
iter=$(echo "$x" | sed 's/\./ /g' | awk '{print $(NF-2),$(NF-1)}')
iter=$(echo $iter | awk '{$1=$1+1;print $0}')
value=$(awk -v name=$outputname '{if($3=="Overall" && $5=="objective" && $8=="'\''"name"'\''") {value=$10;}}END{print value}' $x)
[ "$value" != "" ] && echo "$iter $value" >> $outdir/$object.parallel.loss
done
sort -n -k 1 -n -k 2 $outdir/$object.parallel.loss -o $outdir/$object.parallel.loss
awk 'BEGIN{current=-1;}{a[$1]=a[$1]+$3;b[$1]=b[$1]+1;if($1!=current){if(current!=-1){print current,a[current]/b[current];}current=$1;}}
END{print current,a[current]/b[current];}' \
$outdir/$object.parallel.loss > $outdir/$object.loss
;;
*) echo "[exit] Invalid object $object" && exit 1 ;;
esac
echo "Grabing loss of $object ..."
done
echo "All done."
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。