-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cdc1b2
commit 40a76de
Showing
6 changed files
with
169 additions
and
410,732 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Imports" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np, os, json, pandas as pd, matplotlib.pyplot as plt, seaborn as sns\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"import cv2\n", | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Creating Synthetic Data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from synthetic import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Running the Classifier" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 33, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<video width=\"320\" height=\"240\" controls>\n", | ||
" <source src=\"../data/videos/00376.mp4\" type=\"video/mp4\">\n", | ||
"</video>" | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.HTML object>" | ||
] | ||
}, | ||
"execution_count": 33, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import IPython.display as ipd\n", | ||
"class Vid:\n", | ||
" \n", | ||
" def __init__(self, video_path):\n", | ||
" self.video_path = video_path\n", | ||
" self.frames = self.read(video_path)\n", | ||
" \n", | ||
" def __len__(self):\n", | ||
" return len(self.frames)\n", | ||
" \n", | ||
" def __getitem__(self, idx):\n", | ||
" return self.frames[idx]\n", | ||
" \n", | ||
" def __iter__(self):\n", | ||
" for frame in self.frames:\n", | ||
" yield frame\n", | ||
" \n", | ||
" @staticmethod\n", | ||
" def read(video_path):\n", | ||
" cap = cv2.VideoCapture(video_path)\n", | ||
" frames = []\n", | ||
" while True:\n", | ||
" ret, frame = cap.read()\n", | ||
" if not ret:\n", | ||
" break\n", | ||
" frames.append(frame)\n", | ||
" cap.release()\n", | ||
" return np.array(frames)\n", | ||
"\n", | ||
" def show(self):\n", | ||
" return VideoPlayer(self.video_path)\n", | ||
" \n", | ||
"from IPython.display import HTML\n", | ||
"\n", | ||
"HTML(\"\"\"<video width=\"320\" height=\"240\" controls>\n", | ||
" <source src=\"../data/videos/00376.mp4\" type=\"video/mp4\">\n", | ||
"</video>\"\"\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import pandas as pd | ||
import numpy as np | ||
import cv2 | ||
# Define the paths | ||
videos_dir = '../data/videos' | ||
labels_file = '../data/labels.csv' | ||
|
||
def read_video(video_path): | ||
cap = cv2.VideoCapture(video_path) | ||
frames = [] | ||
while True: | ||
ret, frame = cap.read() | ||
if not ret: | ||
break | ||
frames.append(frame) | ||
cap.release() | ||
return np.array(frames) | ||
|
||
|
||
|
||
# Load the labels from the CSV file | ||
labels_df = pd.read_csv(labels_file) | ||
|
||
videos_fns = os.listdir(videos_dir) | ||
videos = [] | ||
labels = [] | ||
|
||
for video_fn in videos_fns: | ||
video_id = int(video_fn.split('.')[0]) | ||
label = labels_df[labels_df['video_id'] == video_id]['label'].values[0] | ||
full_fn = os.path.join(videos_dir, video_fn) | ||
video = cv2.VideoCapture(full_fn) | ||
labels.append(label) |
File renamed without changes.
Oops, something went wrong.