-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanimal_person_other_sort.sh
65 lines (49 loc) · 2.31 KB
/
animal_person_other_sort.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
##########USERS VAR ###############
path_main_folder="/content/animals_and_person" #NEED CHANGE TO YOU FOLDER
percent_files="20" #NEED CHANGE TO YOUR %
##########USERS VAR ###############
#################################SORT DATA TO FOLDERS######################################################
echo "create folders val"
mkdir $path_main_folder/val
folder_val="$path_main_folder/val"
ls $path_main_folder | grep -v val| while read -r NAME; do
echo " START ###### ${NAME} #####"
count_files_in_folder=$(ls "$path_main_folder"/"${NAME}" | wc -l)
echo " count files in folder ${NAME} $count_files_in_folder"
echo "count percentage $percent_files folder "${NAME}" need move to another folder"
count_files_need_move=$(echo $(( $count_files_in_folder*$percent_files/100 )))
echo $count_files_need_move
echo "create folder ${NAME}"
mkdir $folder_val/"${NAME}"
chmod -R 777 $path_main_folder
echo "count files which need move to another direcory"
echo $count_files_need_move
cd "$path_main_folder"/"${NAME}" && ls | head -"$count_files_need_move" | xargs -I{} sudo mv {} $folder_val/"${NAME}"/
echo "count files in val direcory for ${NAME} "
ls $folder_val/"${NAME}"/ | wc -l
echo "count files in train direcory for ${NAME} "
ls "$path_main_folder"/"${NAME}"/ | wc -l
echo " FINISH ###### ${NAME} #####
"
done
#################################SORT DATA TO FOLDERS######################################################
#################################MOVE LEFT DATA TO TRAIN FOLDER######################################################
echo "create folder train and move all left except folder val to this folder - it's just rename"
mkdir $path_main_folder/train
ls $path_main_folder | grep -v val | grep -v train | while read -r NAME; do
mv "$path_main_folder"/"${NAME}" $path_main_folder/train/
done
echo "
check again count files per classes in folder train"
ls $path_main_folder/train/ | while read -r NAME; do
echo "folder $path_main_folder/train/"${NAME}" "
ls $path_main_folder/train/"${NAME}"/ | wc -l
done
echo "
check again count files per classes in folder val"
ls $path_main_folder/train/ | while read -r NAME; do
echo "folder $path_main_folder/val/"${NAME}" "
ls $path_main_folder/val/"${NAME}"/ | wc -l
done
#################################MOVE LEFT DATA TO TRAIN FOLDER######################################################