-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathpipeline_i3d.py
More file actions
80 lines (66 loc) · 2.49 KB
/
Copy pathpipeline_i3d.py
File metadata and controls
80 lines (66 loc) · 2.49 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
https://github.com/FrederikSchorr/sign-language
Assume videos are stored:
... sVideoDir / train / class001 / gesture0027.mp4
... sVideoDir / val / class249 / gesture1069.avi
This pipeline
* extracts frames=images from videos (training + validation)
* calculates optical flow
* trains an I3D neural network
"""
import os
import glob
import sys
import warnings
import numpy as np
import pandas as pd
from frame import videosDir2framesDir
from opticalflow import framesDir2flowsDir
from datagenerator import VideoClasses
from model_i3d import Inception_Inflated3d, Inception_Inflated3d_Top
from feature import features_3D_predict_generator
from train_i3d import train_I3D_oflow_end2end
# Image and/or Optical flow pipeline
bImage = False
bOflow = True
# dataset
"""diVideoSet = {"sName" : "ledasila",
"nClasses" : 21, # number of classes
"nFramesNorm" : 40, # number of frames per video
"nMinDim" : 240, # smaller dimension of saved video-frames
"tuShape" : (288, 352), # height, width
"nFpsAvg" : 25,
"nFramesAvg" : 75,
"fDurationAvg" : 3.0} # seconds
"""
diVideoSet = {"sName" : "chalearn",
"nClasses" : 249, # number of classes
"nFramesNorm" : 40, # number of frames per video
"nMinDim" : 240, # smaller dimension of saved video-frames
"tuShape" : (240, 320), # height, width
"nFpsAvg" : 10,
"nFramesAvg" : 50,
"fDurationAvg" : 5.0} # seconds
# directories
sFolder = "%03d-%d"%(diVideoSet["nClasses"], diVideoSet["nFramesNorm"])
sClassFile = "data-set/%s/%03d/class.csv"%(diVideoSet["sName"], diVideoSet["nClasses"])
sVideoDir = "data-set/%s/%03d"%(diVideoSet["sName"], diVideoSet["nClasses"])
sImageDir = "data-temp/%s/%s/image"%(diVideoSet["sName"], sFolder)
sImageFeatureDir = "data-temp/%s/%s/image-i3d"%(diVideoSet["sName"], sFolder)
sOflowDir = "data-temp/%s/%s/oflow"%(diVideoSet["sName"], sFolder)
sOflowFeatureDir = "data-temp/%s/%s/oflow-i3d"%(diVideoSet["sName"], sFolder)
print("Starting I3D pipeline ...")
print(os.getcwd())
# extract frames from videos
if bImage or bOflow:
videosDir2framesDir(sVideoDir, sImageDir, nFramesNorm = diVideoSet["nFramesNorm"],
nResizeMinDim = diVideoSet["nMinDim"], tuCropShape = None)
# calculate optical flow
if bOflow:
framesDir2flowsDir(sImageDir, sOflowDir, nFramesNorm = diVideoSet["nFramesNorm"])
# train I3D network(s)
if bOflow:
train_I3D_oflow_end2end(diVideoSet)
elif bImage:
raise ValueError("I3D training with only image data not implemented")
# the end