while [ 1 ];do
read -p "输入正确数据集类型training、test: " dstype
read -p "输入正确业务类型defect、device、element、tower、environment、defect2、device2、element2、defect3: " etype
read -p "输入正确批次: " batchnum
picnum=0
no_picnum=0
current_path=$(pwd)
if [ "$dstype" = "training" ]; then
cd "$current_path"
# cd "/datasets/train_project/ka3ffd2b8f1eea49a0a3a91a0ba60001b5"
# for i in $(find . -type d -name "${dstype}-data-*-${etype}")
for i in $(ls |grep -w "${dstype}-data-.\{2,30\}-${etype}")
do
# echo "$i/defect/$batchnum/"
target_path="$current_path/$i/defect/$batchnum/images"
if [ -d "$target_path" ]; then
echo "目录存在$i/defect/$batchnum/"
cd "$target_path" || exit
num=$(find . -type f -iname "*.jpg" | wc -l)
picnum=$((picnum + num))
else
echo "目录不存在$target_path"
fi
no_target_path="$current_path/$i/no_defect/$batchnum/images"
if [ -d "$no_target_path" ]; then
echo "目录存在$i/no_defect/$batchnum/"
cd "$no_target_path" || exit
no_num=$(find . -type f -name "*.jpg" | wc -l)
no_picnum=$((no_picnum + no_num))
else
echo "目录不存在$no_target_path"
fi
done
total_picnum=$((no_picnum+picnum))
echo "训练批次$batchnum 图片数: $total_picnum"
elif [ "$dstype" = "test" ]; then
# for i in $(find . -type d -name "${dstype}-data-*-${etype}")
cd "$current_path"
for i in $(ls |grep -w "${dstype}-data-.\{2,30\}-${etype}")
do
# echo "$i"
target_path="$current_path/$i/images"
if [ -d "$target_path" ]; then
echo "目录存在$i"
cd "$target_path" || exit
num=$(find . -type f -iname "*.jpg" | wc -l)
picnum=$((picnum + num))
else
echo "目录不存在$target_path"
fi
done
echo "测试图片数: $picnum"
else
echo "输入错误数据集类型"
fi
done
shell脚本的小实例
于 2024-06-19 09:45:24 首次发布