Skip to content

Commit d997469

Browse files
committed
Add dump_data_set.sh
1 parent ecf11f1 commit d997469

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

data/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This folder contains the following scripts:
44

55
- [`add_frame_numbering.sh*`](add_frame_numbering.sh): draws a huge number on each frame on a specific video;
6+
- [`dump_data_set.sh*`](dump_data_set.sh): get images from videos for ["traditional training"](https://github.com/pytorch/examples/tree/master/imagenet);
67
- [`resize_and_split.sh*`](resize_and_split.sh): see [below](#matchnet-mode);
78
- [`resize_and_sample.sh*`](resize_and_sample.sh): see [below](#temponet-mode);
89
- [`VideoFolder.py`](VideoFolder.py): *PyTorch* `data.Dataset`'s sub-class for video data loading.

data/dump_data_set.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
################################################################################
2+
# Dump data set
3+
################################################################################
4+
# Alfredo Canziani, Apr 17
5+
################################################################################
6+
# Run as:
7+
# ./dump_data_set.sh src_path/ dst_path/
8+
################################################################################
9+
10+
# some colours
11+
r='\033[0;31m' # red
12+
g='\033[0;32m' # green
13+
b='\033[0;34m' # blue
14+
n='\033[0m' # none
15+
16+
# title
17+
echo "Dumping video data set into separate frames"
18+
19+
# assert existence of source directory
20+
src_dir=${1%/*} # remove trailing /, if present
21+
if [ ! -d $src_dir ] || [ -z $src_dir ]; then
22+
echo -e "${r}Source directory/link \"$src_dir\" is missing. Exiting.${n}"
23+
exit 1
24+
fi
25+
echo -e " - Source directory/link set to \"$b$src_dir$n\""
26+
27+
# assert existence of destination directory
28+
dst_dir="${2%/*}" # remove trailing /, if present
29+
if [ -d $dst_dir ]; then
30+
echo -e "${r}Destination directory \"$dst_dir\" already existent." \
31+
"Exiting.${n}"
32+
exit 1
33+
fi
34+
echo -e " - Destination directory set to \"$b$dst_dir$n\""
35+
36+
# check if all is good
37+
printf "Does it look fine? (${g}y${g}${n}/${r}n${n}) "
38+
read ans
39+
if [ $ans == 'n' ]; then
40+
echo -e "${r}Exiting.${n}"
41+
exit 0
42+
fi
43+
44+
# for every class
45+
for set_ in $(ls $src_dir); do
46+
47+
printf "\nProcessing $set_ set\n"
48+
49+
for class in $(ls $src_dir/$set_); do
50+
51+
printf " > Processing class \"$class\":"
52+
53+
# define src and dst
54+
src_class_dir="$src_dir/$set_/$class"
55+
dst_class_dir="$dst_dir/$set_/$class"
56+
mkdir -p $dst_class_dir
57+
58+
# for each video in the class
59+
for video in $(ls $src_class_dir); do
60+
61+
printf " \"$video\""
62+
63+
# define src and dst video paths
64+
src_video_path="$src_class_dir/$video"
65+
dst_video_path="$dst_class_dir/${video%.*}%03d.png"
66+
67+
ffmpeg \
68+
-loglevel error \
69+
-i $src_video_path \
70+
$dst_video_path
71+
72+
done
73+
echo ""
74+
done
75+
done
76+
77+
echo -e "${r}Done. Exiting.${n}"
78+
exit 0

0 commit comments

Comments
 (0)