Skip to content

Instantly share code, notes, and snippets.

@Multihuntr
Created June 11, 2018 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Multihuntr/02a935a165a291f59d13ce215f41b088 to your computer and use it in GitHub Desktop.
Save Multihuntr/02a935a165a291f59d13ce215f41b088 to your computer and use it in GitHub Desktop.
Minimal examples of using NVIDIA/nvvl
# Simplest case (note: VideoDataset.__get__ puts frames on CPU)
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3)
fr = d[0]
print(type(fr))
print(fr.shape)
# Custom processing (note: VideoDataset.__get__ puts frames on CPU)
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3, processing={'a': nvvl.ProcessDesc()})
fr = d[0]
print(type(fr))
print(fr['a'].shape)
# Custom labels associated with frames (note: VideoDataset.__get__ puts frames on CPU)
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3, get_label=lambda x,y: (x,y))
fr = d[0]
print(type(fr))
print(fr['default'].shape)
print(fr['labels'])
for x in [50, 121, 31, 50]:
print(d[x]['labels'])
# Both custom processing and custom labels (note: VideoDataset.__get__ puts frames on CPU)
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3, processing={'a': nvvl.ProcessDesc()}, get_label=lambda x,y: (x,y))
fr = d[0]
print(type(fr))
print(fr['a'].shape)
print(fr['labels'])
for x in [50, 121, 31, 50]:
print(d[x]['labels'])
# Simplest Dataloader use
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3)
lo = nvvl.VideoLoader(d, batch_size=3)
it = lo.__iter__()
fr = next(it)
print(type(fr))
print(fr['default'].shape)
# Sequential Dataloader with custom processing
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3, processing={'a': nvvl.ProcessDesc()})
lo = nvvl.VideoLoader(d, batch_size=3)
it = lo.__iter__()
fr = next(it)
print(type(fr))
print(fr['a'].shape)
# Sequential Dataloader with default processing and custom labels
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3, get_label=lambda x,y: (x,y))
lo = nvvl.VideoLoader(d, batch_size=3)
it = lo.__iter__()
fr = next(it)
print(type(fr))
print(fr['default'].shape)
# Sequential Dataloader with custom processing and custom labels
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3, processing={'a': nvvl.ProcessDesc()}, get_label=lambda x,y: (x,y))
lo = nvvl.VideoLoader(d, batch_size=3)
it = lo.__iter__()
fr = next(it)
print(type(fr))
print(fr['a'].shape)
print(fr['labels'])
# Shuffled Dataloader with custom processing and custom labels
import nvvl
d = nvvl.VideoDataset(['prepared.mp4'], 3, processing={'a': nvvl.ProcessDesc()}, get_label=lambda x,y: (x,y))
lo = nvvl.VideoLoader(d, batch_size=3, shuffle=True)
it = lo.__iter__()
fr = next(it)
print(type(fr))
print(fr['a'].shape)
print(fr['labels'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment