wangjing
commited on
Commit
·
0a53e34
1
Parent(s):
53d4ed1
add dataset
Browse files- .gitattributes +12 -0
- mixkit.00.tar +3 -0
- pexels.00.tar +3 -0
- pexels.01.tar +3 -0
- pexels.02.tar +3 -0
- pixabay.00.tar +3 -0
- pixabay.01.tar +3 -0
- pixabay.02.tar +3 -0
- pixabay.03.tar +3 -0
- pixabay.04.tar +3 -0
- pixabay.05.tar +3 -0
- pixabay.06.tar +3 -0
- pixabay.07.tar +3 -0
- pixabay.08.tar +3 -0
- pixabay.09.tar +3 -0
- pixabay.10.tar +3 -0
- pixabay.11.tar +3 -0
- run.sh +34 -0
- sample.py +70 -0
.gitattributes
CHANGED
@@ -59,3 +59,15 @@ mixkit.00.tar filter=lfs diff=lfs merge=lfs -text
|
|
59 |
pexels.00.tar filter=lfs diff=lfs merge=lfs -text
|
60 |
pexels.01.tar filter=lfs diff=lfs merge=lfs -text
|
61 |
pexels.02.tar filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
pexels.00.tar filter=lfs diff=lfs merge=lfs -text
|
60 |
pexels.01.tar filter=lfs diff=lfs merge=lfs -text
|
61 |
pexels.02.tar filter=lfs diff=lfs merge=lfs -text
|
62 |
+
pixabay.01.tar filter=lfs diff=lfs merge=lfs -text
|
63 |
+
pixabay.03.tar filter=lfs diff=lfs merge=lfs -text
|
64 |
+
pixabay.07.tar filter=lfs diff=lfs merge=lfs -text
|
65 |
+
pixabay.08.tar filter=lfs diff=lfs merge=lfs -text
|
66 |
+
pixabay.11.tar filter=lfs diff=lfs merge=lfs -text
|
67 |
+
pixabay.09.tar filter=lfs diff=lfs merge=lfs -text
|
68 |
+
pixabay.10.tar filter=lfs diff=lfs merge=lfs -text
|
69 |
+
pixabay.00.tar filter=lfs diff=lfs merge=lfs -text
|
70 |
+
pixabay.02.tar filter=lfs diff=lfs merge=lfs -text
|
71 |
+
pixabay.04.tar filter=lfs diff=lfs merge=lfs -text
|
72 |
+
pixabay.05.tar filter=lfs diff=lfs merge=lfs -text
|
73 |
+
pixabay.06.tar filter=lfs diff=lfs merge=lfs -text
|
mixkit.00.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:43273d48d9a2c7d47726318e32a61acd8fbbbc75855ca8080e3fad6f1b1b6e05
|
3 |
+
size 803870720
|
pexels.00.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:91028024dd214584f182ef0ef2164e4670cd593f8434f3c9a281ee1cb77ccfec
|
3 |
+
size 3054643200
|
pexels.01.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c1d96cfa7c85a67d07a3ab50bbf4a8a3afa9242ef0df48a97421b360054a367d
|
3 |
+
size 3054684160
|
pexels.02.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d9f9d164bccaffcf1417fbfae665c7bc6294a59a9a5a532913ce4666a12a6851
|
3 |
+
size 1350881280
|
pixabay.00.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0649c4ec78c3fc1c05d027c5c26bcab56089f25c471c809f767fad52ae31d5a4
|
3 |
+
size 3057971200
|
pixabay.01.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c6da266c18ae8cc2f79561dda254ff55ea89bafffb03e9d18e434d41b431abe
|
3 |
+
size 3053998080
|
pixabay.02.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d3dbe15983a893a69b0d672270da0623ee31d294af8b1d0c4b46f42db89d829a
|
3 |
+
size 3055452160
|
pixabay.03.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fd9a26844bc0c1a563a24392b26524de5bae7f44adc104ceaebb995cbb8b2f63
|
3 |
+
size 3055431680
|
pixabay.04.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5493e87d9badab0f26758a392a4ff8502f332acd71f8b378a22390c4223baf13
|
3 |
+
size 3054643200
|
pixabay.05.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ca8a07b3a59ec0297441f8bbc33d6656e2ca20107f927bdeccdd146c462cb771
|
3 |
+
size 3052533760
|
pixabay.06.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:09564c3253829a287fbd4425b190bf854738c13b907ae95ddb8b7b0754f424ba
|
3 |
+
size 3052984320
|
pixabay.07.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:adfa63148ffbed018e8efec0e122a8411a5d59d09bf0926148a20e3a4a9eabc6
|
3 |
+
size 3052769280
|
pixabay.08.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d13c9ea32c82e904bcf74726ebb154d49ae0bf604f02119b1eddf9859bcbd26a
|
3 |
+
size 3053219840
|
pixabay.09.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ddad46f28e19cb9e33ec8e17a082958950f57fe8aa0e3dbdbc7af854a7d00ae1
|
3 |
+
size 3056230400
|
pixabay.10.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:43c37d37b457820d76e8781ec8f336ae6864c6ab59c61b61d1e80c3b58bb76c2
|
3 |
+
size 3054008320
|
pixabay.11.tar
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e49d160a33355ac058ec3bba753c0802fae3eeb76170b9cba599e61c8e3f2876
|
3 |
+
size 1696389120
|
run.sh
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
set -ex
|
2 |
+
|
3 |
+
MODE=$1
|
4 |
+
DATASET=${2:-mixkit}
|
5 |
+
echo "Running in mode: $MODE"
|
6 |
+
|
7 |
+
if [ "$MODE" == "sample_all" ]; then
|
8 |
+
conda run --no-capture-output -n torch python sample.py --root_dir mixkit --size 512
|
9 |
+
rm -rf mixkit
|
10 |
+
conda run --no-capture-output -n torch python sample.py --root_dir pexels --size 512
|
11 |
+
rm -rf pexels
|
12 |
+
conda run --no-capture-output -n torch python sample.py --root_dir pixabay --size 512
|
13 |
+
rm -rf pixabay
|
14 |
+
elif [ "$MODE" == "sample" ]; then
|
15 |
+
if [ "$DATASET" == "mixkit" ]; then
|
16 |
+
unpigz -c mixkit.tar.gz | tar -xvf -
|
17 |
+
elif [ "$DATASET" == "pexels" ]; then
|
18 |
+
cat pexels.tar.gz.0* | unpigz -c - | tar -xvf -
|
19 |
+
elif [ "$DATASET" == "pixabay" ]; then
|
20 |
+
cat pixabay.tar.gz.{00..24} | unpigz -c - | tar -xvf -
|
21 |
+
fi
|
22 |
+
rm -rf $DATASET.tar.gz*
|
23 |
+
conda run --no-capture-output -n torch python sample.py --root_dir $DATASET --size 512
|
24 |
+
rm -rf $DATASET
|
25 |
+
elif [ "$MODE" == "sample_files"]; then
|
26 |
+
conda run --no-capture-output -n torch python sample.py --root_dir mixkit --size 512 --output_format files
|
27 |
+
rm -rf mixkit
|
28 |
+
conda run --no-capture-output -n torch python sample.py --root_dir pexels --size 512 --output_format files
|
29 |
+
rm -rf pexels
|
30 |
+
conda run --no-capture-output -n torch python sample.py --root_dir pixabay --size 512 --output_format files
|
31 |
+
rm -rf pixabay
|
32 |
+
else
|
33 |
+
echo "Invalid mode"
|
34 |
+
fi
|
sample.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from torch.utils.data import Dataset, DataLoader
|
3 |
+
from glob import glob
|
4 |
+
import os, os.path as osp
|
5 |
+
from tqdm import tqdm
|
6 |
+
import webdataset as wds
|
7 |
+
|
8 |
+
from kn_util.data.video import read_frames_decord, get_frame_indices, fill_temporal_param, save_video_imageio, array_to_video_bytes
|
9 |
+
from kn_util.data.transforms.video import Compose, Resize, ToStackedArray, CenterCrop
|
10 |
+
from kn_util.data.transforms.video.functional import split_array
|
11 |
+
|
12 |
+
|
13 |
+
class VideoDataset(Dataset):
|
14 |
+
def __init__(self, root_dir, fps=8, size=256):
|
15 |
+
self.transform = Compose(
|
16 |
+
[
|
17 |
+
Resize(size),
|
18 |
+
ToStackedArray(),
|
19 |
+
]
|
20 |
+
)
|
21 |
+
self.video_files = glob(osp.join(root_dir, "**/*.mp4"))
|
22 |
+
self.fps = fps
|
23 |
+
|
24 |
+
def __getitem__(self, idx):
|
25 |
+
video_file = self.video_files[idx]
|
26 |
+
|
27 |
+
frames = read_frames_decord(video_file, fps=self.fps, output_format="thwc")
|
28 |
+
frames = split_array(frames)
|
29 |
+
frames = self.transform(frames)
|
30 |
+
return video_file, frames
|
31 |
+
|
32 |
+
def __len__(self):
|
33 |
+
return len(self.video_files)
|
34 |
+
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
parser = argparse.ArgumentParser()
|
38 |
+
parser.add_argument("--root_dir", type=str)
|
39 |
+
parser.add_argument("--output_dir", type=str, default="outputs")
|
40 |
+
parser.add_argument("--fps", type=int, default=8)
|
41 |
+
parser.add_argument("--size", type=int, default=256)
|
42 |
+
parser.add_argument("--output_format", type=str, default="tar")
|
43 |
+
args = parser.parse_args()
|
44 |
+
|
45 |
+
dataset = VideoDataset(root_dir=args.root_dir, fps=args.fps, size=args.size)
|
46 |
+
dataloader = DataLoader(
|
47 |
+
dataset,
|
48 |
+
batch_size=1,
|
49 |
+
shuffle=False,
|
50 |
+
collate_fn=lambda x: x[0],
|
51 |
+
num_workers=32,
|
52 |
+
pin_memory=True,
|
53 |
+
)
|
54 |
+
|
55 |
+
dataset_name = args.root_dir.strip("/")
|
56 |
+
tar_path = osp.join(args.output_dir, f"{dataset_name}.%02d.tar")
|
57 |
+
os.makedirs(args.output_dir, exist_ok=True)
|
58 |
+
|
59 |
+
if args.output_format == "files":
|
60 |
+
for video_path, frames in tqdm(dataloader):
|
61 |
+
output_path = osp.join(args.output_dir, video_path)
|
62 |
+
os.makedirs(osp.dirname(output_path), exist_ok=True)
|
63 |
+
save_video_imageio(frames, output_path, fps=args.fps, input_format="thwc")
|
64 |
+
|
65 |
+
if args.output_format == "tar":
|
66 |
+
writer = wds.ShardWriter(tar_path, maxcount=4000000000)
|
67 |
+
for video_path, frames in tqdm(dataloader):
|
68 |
+
video_filename = osp.basename(video_path).split(".")[0]
|
69 |
+
writer.write({"mp4": array_to_video_bytes(frames), "__key__": video_filename})
|
70 |
+
writer.close()
|