<jupyter_start><jupyter_text>Collect Data<jupyter_code>!wget -q --no-check-certificate https://www.crcv.ucf.edu/data/UCF101/UCF101.rar
!wget -q --no-check-certificate https://www.crcv.ucf.edu/data/UCF101/UCF101TrainTestSplits-RecognitionTask.zip
%%capture
!unrar e UCF101.rar data/
!unzip -qq UCF101TrainTestSplits-RecognitionTask.zip<jupyter_output><empty_output><jupyter_text>Imports<jupyter_code>from imutils import paths
from tqdm import tqdm
import pandas as pd 
import numpy as np
import shutil
import cv2
import os<jupyter_output><empty_output><jupyter_text>Metadata Loading<jupyter_code># Open the .txt file which have names of training videos
f = open("ucfTrainTestlist/trainlist01.txt", "r")
temp = f.read()
videos = temp.split('\n')

# Create a dataframe having video names
train = pd.DataFrame()
train['video_name'] = videos
train = train[:-1]
train.head()
# Open the .txt file which have names of test videos
with open("ucfTrainTestlist/testlist01.txt", "r") as f:
    temp = f.read()
videos = temp.split("\n")

# Create a dataframe having video names
test = pd.DataFrame()
test["video_name"] = videos
test = test[:-1]
test.head()<jupyter_output><empty_output><jupyter_text>Utility Functions<jupyter_code>def extract_tag(video_path):
    return video_path.split("/")[0]

def separate_video_name(video_name):
    return video_name.split("/")[1]

def rectify_video_name(video_name):
    return video_name.split(" ")[0]

def move_videos(df, output_dir):
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    for i in tqdm(range(df.shape[0])):
        videoFile = df['video_name'][i].split("/")[-1]
        videoPath = os.path.join("data", videoFile)
        shutil.copy2(videoPath, output_dir)
    print()
    print(f"Total videos: {len(os.listdir(output_dir))}")<jupyter_output><empty_output><jupyter_text>DataFrame Preparation<jupyter_code>train["tag"] = train["video_name"].apply(extract_tag)
train["video_name"] = train["video_name"].apply(separate_video_name)
train.head()
train["video_name"] = train["video_name"].apply(rectify_video_name)
train.head()
test["tag"] = test["video_name"].apply(extract_tag)
test["video_name"] = test["video_name"].apply(separate_video_name)
test.head()<jupyter_output><empty_output><jupyter_text>Filtering Top-n Actions<jupyter_code>n = 10
topNActs = train["tag"].value_counts().nlargest(n).reset_index()["index"].tolist()
train_new = train[train["tag"].isin(topNActs)]
test_new = test[test["tag"].isin(topNActs)]
train_new.shape, test_new.shape
train_new = train_new.reset_index(drop=True)
test_new = test_new.reset_index(drop=True)<jupyter_output><empty_output><jupyter_text>Move Top-n Action Videos<jupyter_code>move_videos(train_new, "train")
move_videos(test_new, "test")
train_new.to_csv("train.csv", index=False)
test_new.to_csv("test.csv", index=False)<jupyter_output><empty_output><jupyter_text>Serialization<jupyter_code>!tar cf ucf101_top10.tar.gz train test train.csv test.csv
from google.colab import drive
drive.mount('/content/drive')
!cp ucf101_top10.tar.gz /content/drive/MyDrive<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14720155289550307, 'fraction_numerical': 0.013911355548366224, 'mean_word_length': 6.9282051282051285, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '490102', 'license': 'Apache-2.0', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1143, 'n_words': 188, 'path': 'Data_Preparation_UCF101.ipynb', 'repo_name': 'sayakpaul/Action-Recognition-in-TensorFlow', 'size': '3091'}