Skip to content

XD-Violence

import sys
sys.path.append('..')

from pysauron.datasets import XDViolence
from pysauron.transforms import RandomAnomalyInject, ChangeDirection, FrameDrop

import matplotlib.pyplot as plt
from IPython.display import clear_output
train_dataset = XDViolence(root='../data/XD-Violence/', test_mode=False, _debug=True)
test_dataset = XDViolence(root='../data/XD-Violence/', test_mode=True, _debug=True)
100.0%
100.0%

print('# Train samples: ', len(train_dataset))
print('# Test samples:  ', len(test_dataset))
# Train samples:  15658
# Test samples:   4899

Frame drop augmentationยค

sample = test_dataset[243]

video, label, temporal_l = FrameDrop(k=5, always_apply=True)(video=sample[0], label=sample[1], temporal_label=sample[2])

for i in range(video.shape[0]):
    plt.imshow(video[i])
    plt.title(f'Label: {temporal_l[i]}')
    clear_output(True)
    plt.show()

print('Sample temporal labels after transform: ', temporal_l)
Sample temporal labels after transform:  [1. 0. 1. 1. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 1. 0.]

Direction change augmentationยค

sample = test_dataset[243]

video, label, temporal_l = ChangeDirection(always_apply=True)(video=sample[0], label=sample[1], temporal_label=sample[2])

for i in range(video.shape[0]):
    plt.imshow(video[i])
    plt.title(f'Label: {temporal_l[i]}')
    clear_output(True)
    plt.show()

print('Sample temporal labels after transform: ', temporal_l)
Sample temporal labels after transform:  [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

Randomg injection augmentationยค

sample = test_dataset[243]

video, label, temporal_l = RandomAnomalyInject(
        anomaly_folder='/Users/bogdanivanyuk/Desktop/PySauron/pysauron/transforms/assets/anomalies/animals',
        always_apply=True)(video=sample[0], label=sample[1], temporal_label=sample[2])

for i in range(video.shape[0]):
    plt.imshow(video[i])
    plt.title(f'Label: {temporal_l[i]}')
    clear_output(True)
    plt.show()

print('Sample temporal labels after transform: ', temporal_l)
Sample temporal labels after transform:  [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]