#!/bin/bash
# convert the images folder to the test.list and train.list file according to
# the distribution, command will clear the train.list and test.list files first
#将图片文件夹转为test.list和train.list文件
# Args:
# path: the path to the video folder 路径:视频文件夹的路径
# factor: denominator that split the train and test data. if the number
# is 4, then 1/4 of the data will be written to test.list and the
# rest of the data will be written to train.list
因素: 区分训练和测试文件数据的分母,如果是4,那么训练集:测试集 = 3:1
# Usage:
# ./convert_images_to_list.sh path/to/video 4
# Example Usage:
# ./convert_images_to_list.sh ~/document/videofile 4
# Example Output(train.list and test.list):
# /Volumes/passport/datasets/action_kth/origin_images/boxing/person01_boxing_d1_uncomp 0
# /Volumes/passport/datasets/action_kth/origin_images/boxing/person01_boxing_d2_uncomp 0
# ...
# /Volumes/passport/datasets/action_kth/origin_images/handclapping/person01_handclapping_d1_uncomp 1
# /Volumes/passport/datasets/action_kth/origin_images/handclapping/person01_handclapping_d2_uncomp 1
# ...
> train.list
> test.list
COUNT=-1
for folder in $1/* #将文件夹名循环出来
do
COUNT=$[$COUNT + 1]
for imagesFolder in "$folder"/*
do
if (( $(jot -r 1 1 $2) > 1 )); then
echo "$imagesFolder" $COUNT >> train.list
else
echo "$imagesFolder" $COUNT >> test.list
fi
done
done