-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathVideoHFlip.lua
36 lines (32 loc) · 921 Bytes
/
VideoHFlip.lua
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
-- takes a video (table of frames) and horizontally flips each frame
require 'image'
require 'dpnn'
function VideoHFlip(x)
if torch.uniform()>0.5 and #x>0 then
for t = 1,#x do
x[t] = image.hflip(x[t])
end
end
return x
end
--[[
-- make it 5D by padding singleton dim
x = nn.Module:toBatch(x,4) -- gross abuse of OOP by I need this function...
-- flippity flip flip
for b = 1,x:size(1) do
-- flip with only 0.5 probability
if torch.uniform()>0.5 then
-- swap time and channel since image.hflip will do <= 3 channels only
frames = nn.Convert('cbhw','bchw'):forward(x[b]) -- now time x channel x h x w
for f = 1,frames:size(1) do
frames[f] = image.hflip(frames[f])
end
-- swap back time and channel
frames = nn.Convert('bchw','cbhw'):forward(frames)
-- and assign back to x
x[b] = frames
end
end
return x
end
--]]