Skip to content
This repository was archived by the owner on Sep 28, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added __init__.py
Empty file.
28 changes: 28 additions & 0 deletions architectures/RNN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import torch
import torch.nn as nn

# Defining LSTM RNN
class RNN(nn.Module):
def __init__(self, input_size, hidden_size, num_layers, num_classes):
super(RNN, self).__init__() # inheriting from existing RNN class
self.num_layers = num_layers # number of input layers
self.hidden_size = hidden_size # number of hidden players

self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True) # creating LSTM layer
self.fc = nn.Linear(hidden_size, num_classes) # creating linear output layer

self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# x -> (batch_size, seq_size, input_size)

def forward(self, x):
h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(self.device)
c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(self.device)

out, _ = self.lstm(x, (h0, c0))
# out -> (batch_size, seq_size, input_size) = (N, 50, 512)
out = out[:, -1, :]
# out -> (N, 512)
out = self.fc(out)


return torch.sigmoid(out) # returning one forward step of the NN
Empty file added architectures/__init__.py
Empty file.
1 change: 0 additions & 1 deletion auto_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

import cv2
import numpy as np
import sys
import os
import datetime
Expand Down
7 changes: 0 additions & 7 deletions combine_cnn_output.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import os
import cv2
import sys


Expand Down
31 changes: 31 additions & 0 deletions data_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import torch

def load_data(path_to_data):
data = torch.load(path_to_data)
labels = torch.ones(data.shape[0]).unsqueeze(1)
return data, labels

# torch.load("./no_hacks_data_tensor/clips.pt")
hacks_data, hacks_labels = load_data("./hacks_data_tensor/full_data/hacks_data_tensor_file_100.pt")
no_hacks_data, no_hacks_labels = load_data("./hacks_data_tensor/full_data/hacks_data_tensor_file_100.pt")

# Seperating Training/Testing data into 90%/10% splits
def create_training_testing_sets(data, split=0.9):
training_data = data[:int(len(data) * split)]
testing_data = data[int(len(data) * split):]
return training_data, testing_data

hacks_data_train, hacks_data_test = create_training_testing_sets(hacks_data)
no_hacks_data_train, no_hacks_data_test = create_training_testing_sets(no_hacks_data)
hacks_labels_train, hacks_labels_test = create_training_testing_sets(hacks_labels)
no_hacks_labels_train, no_hacks_labels_test = create_training_testing_sets(no_hacks_labels)

def load_training_data():
train_data = torch.cat((hacks_data_train, no_hacks_data_train))
train_labels = torch.cat((hacks_labels_train, no_hacks_labels_train))
return train_data, train_labels

def load_testing_data():
test_data = torch.cat((hacks_data_test, no_hacks_data_test))
test_labels = torch.cat((hacks_labels_test, no_hacks_labels_test))
return test_data, test_labels
7 changes: 0 additions & 7 deletions old_test_rnn.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import os
import cv2



Expand Down
4 changes: 0 additions & 4 deletions save_cnn_output.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import os
import cv2
import sys
Expand Down
37 changes: 0 additions & 37 deletions test_rnn.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import sys
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import os
import cv2

assert len(sys.argv) >= 2, "File requires input path"

Expand All @@ -20,36 +13,6 @@
inDir = sys.argv[2]
assert os.path.isdir(inDir), "not a valid directory"



# Defining LSTM RNN
class RNN(nn.Module):
def __init__(self, input_size, hidden_size, num_layers, num_classes):
super(RNN, self).__init__() # inheriting from existing RNN class
self.num_layers = num_layers # number of input layers
self.hidden_size = hidden_size # number of hidden players

self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True) # creating LSTM layer
self.fc = nn.Linear(hidden_size, num_classes) # creating linear output layer

self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')


# x -> (batch_size, seq_size, input_size)

def forward(self, x):
h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(self.device)
c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(self.device)

out, _ = self.lstm(x, (h0, c0))
# out -> (batch_size, seq_size, input_size) = (N, 50, 512)
out = out[:, -1, :]
# out -> (N, 512)
out = self.fc(out)


return torch.sigmoid(out) # returning one forward step of the NN

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

model = torch.load("./models/model.pt")
Expand Down
67 changes: 3 additions & 64 deletions train_rnn.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,7 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import os
import cv2


# Defining LSTM RNN
class RNN(nn.Module):
def __init__(self, input_size, hidden_size, num_layers, num_classes):
super(RNN, self).__init__() # inheriting from existing RNN class
self.num_layers = num_layers # number of input layers
self.hidden_size = hidden_size # number of hidden players

self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True) # creating LSTM layer
self.fc = nn.Linear(hidden_size, num_classes) # creating linear output layer

self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')


# x -> (batch_size, seq_size, input_size)

def forward(self, x):
h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(self.device)
c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(self.device)

out, _ = self.lstm(x, (h0, c0))
# out -> (batch_size, seq_size, input_size) = (N, 50, 512)
out = out[:, -1, :]
# out -> (N, 512)
out = self.fc(out)


return torch.sigmoid(out) # returning one forward step of the NN
from architectures.RNN import RNN
from data_loader import load_training_data

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

Expand All @@ -56,34 +22,7 @@ def forward(self, x):
criterion = nn.BCELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)

# Loading the model
hacks_data = torch.load("./hacks_data_tensor/clips.pt")
hacks_labels = torch.ones(hacks_data.shape[0]).unsqueeze(1)

no_hacks_data = torch.load("./no_hacks_data_tensor/clips.pt")
no_hacks_labels = torch.zeros(no_hacks_data.shape[0]).unsqueeze(1)


# Seperating Training/Testing data into 90%/10% splits
hacks_data_train = hacks_data[:int(len(hacks_data) * 0.9)]
hacks_data_test = hacks_data[int(len(hacks_data) * 0.9):]

no_hacks_data_train = no_hacks_data[:int(len(no_hacks_data) * 0.9)]
no_hacks_data_test = no_hacks_data[int(len(no_hacks_data) * 0.9):]

hacks_labels_train = hacks_labels[:int(len(hacks_labels) * 0.9)]
hacks_labels_test = hacks_labels[int(len(hacks_labels) * 0.9):]

no_hacks_labels_train = no_hacks_labels[:int(len(no_hacks_labels) * 0.9)]
no_hacks_labels_test = no_hacks_labels[int(len(no_hacks_labels) * 0.9):]


train_data = torch.cat((hacks_data_train, no_hacks_data_train))
train_labels = torch.cat((hacks_labels_train, no_hacks_labels_train))


test_data = torch.cat((hacks_data_test, no_hacks_data_test))
test_labels = torch.cat((hacks_labels_test, no_hacks_labels_test))
train_data, train_labels = load_training_data()

model.train() # set model to training mode
for epoch in range(num_epochs):
Expand Down
66 changes: 3 additions & 63 deletions validate_rnn.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import os
import cv2



# Defining LSTM RNN
class RNN(nn.Module):
def __init__(self, input_size, hidden_size, num_layers, num_classes):
super(RNN, self).__init__() # inheriting from existing RNN class
self.num_layers = num_layers # number of input layers
self.hidden_size = hidden_size # number of hidden players

self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True) # creating LSTM layer
self.fc = nn.Linear(hidden_size, num_classes) # creating linear output layer

self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')


# x -> (batch_size, seq_size, input_size)

def forward(self, x):
h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(self.device)
c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(self.device)

out, _ = self.lstm(x, (h0, c0))
# out -> (batch_size, seq_size, input_size) = (N, 50, 512)
out = out[:, -1, :]
# out -> (N, 512)
out = self.fc(out)


return torch.sigmoid(out) # returning one forward step of the NN

from data_loader import load_testing_data
from architectures.RNN import RNN
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

num_classes = 1
Expand All @@ -55,30 +18,7 @@ def forward(self, x):
model = torch.load("./models/model.pt")

# Loading the model
hacks_data = torch.load("./hacks_data_tensor/clips.pt")
hacks_labels = torch.ones(hacks_data.shape[0]).unsqueeze(1)

no_hacks_data = torch.load("./no_hacks_data_tensor/clips.pt")
no_hacks_labels = torch.zeros(no_hacks_data.shape[0]).unsqueeze(1)

hacks_data_train = hacks_data[:int(len(hacks_data) * 0.9)]
hacks_data_test = hacks_data[int(len(hacks_data) * 0.9):]

no_hacks_data_train = no_hacks_data[:int(len(no_hacks_data) * 0.9)]
no_hacks_data_test = no_hacks_data[int(len(no_hacks_data) * 0.9):]

hacks_labels_train = hacks_labels[:int(len(hacks_labels) * 0.9)]
hacks_labels_test = hacks_labels[int(len(hacks_labels) * 0.9):]

no_hacks_labels_train = no_hacks_labels[:int(len(no_hacks_labels) * 0.9)]
no_hacks_labels_test = no_hacks_labels[int(len(no_hacks_labels) * 0.9):]


# train_data = torch.cat((hacks_data_train, no_hacks_data_train))
# train_labels = torch.cat((hacks_labels_train, no_hacks_labels_train))

test_data = torch.cat((hacks_data_test, no_hacks_data_test))
test_labels = torch.cat((hacks_labels_test, no_hacks_labels_test))
test_data, test_labels = load_testing_data()

print(test_data.shape)

Expand Down