{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"#Published on December 05, 2022, (21:00 GMT) by Marília Prata, mpwolke","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport cv2\nimport random\n\n#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-12-05T23:42:37.790335Z","iopub.execute_input":"2022-12-05T23:42:37.790902Z","iopub.status.idle":"2022-12-05T23:42:38.270956Z","shell.execute_reply.started":"2022-12-05T23:42:37.790780Z","shell.execute_reply":"2022-12-05T23:42:38.270015Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#codes from Rodrigo Lima  @rodrigolima82\nfrom IPython.display import Image\nImage(url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAagAAAB3CAMAAABhcyS8AAABEVB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9Fw/PloATDc99iC51RPJhgQHF7oChcDEonWy7Uald90eH5S+t/Ql++RiVBMQeMHgeKBgRQB2TomjxSLQTFPXPUD0DRv+x3eFDNREpXWwtqlBue4WWavlB+dOkj+yjGhDSY2X8UqcUGoCAtzo/uZiagiFVCmQE1U/lWXgtq1ExRCYyyWE8BRdqzRCPFFTQdYMKEq183TbJljfSRBBTd39MQg8r8GPQL6S+hLweKDp+zANVj7s+IeZNIuMMW8MDAwIzhElCQ2P6PDkosFlSfTrfnNH1g6ub7GQAVv293ASjSbCXG55V4CzpdJrRjolrsTc5ZOiQFMPMF7x+y6RNr1CwQ+fHM1gn9kJqx1aeHvJt8aQywl8V9jQKSaU0NX4EfgH3sEBxOdzT8QiRPC20ye/geBOhO7MRxo7pVgHv4UaQjNsLXvpVTSkpKSkpKSkpKSkpKSkpKSkpKSkpKSkpKSkpKSkpKSkpKSkpKSkpKSkpKSkpqhfV/vpD3zWmhkyMAAAAASUVORK5CYII=',width=400,height=400)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-06T00:20:40.411464Z","iopub.execute_input":"2022-12-06T00:20:40.411920Z","iopub.status.idle":"2022-12-06T00:20:40.423626Z","shell.execute_reply.started":"2022-12-06T00:20:40.411884Z","shell.execute_reply":"2022-12-06T00:20:40.422365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#NFL Health and Safety Fact Sheet\n\n\"The National Football League is committed to advancing progress in the diagnosis, prevention and treatment of sports-related injuries, enhancing medical protocols, improving how the game is taught and played, and protecting players' overall health, safety and wellbeing.\"\n\n\"The NFL continues to make changes on and off the field to protect the health and safety of every player.\"\n\n\"In collaboration with the NFLPA, the NFL fosters a positive culture around mental health by providing players and the NFL family with resources and tools to succeed, on and off the field, over the course of their lives.\"\n\nhttps://www.nfl.com/playerhealthandsafety/resources/fact-sheets/nfl-health-and-safety-fact-sheet","metadata":{}},{"cell_type":"code","source":"#By Rob Mulla https://www.kaggle.com/robikscube/kaggle-deepfake-detection-introduction  \n\nimport cv2 as cv\nimport os\nimport matplotlib.pylab as plt\ntrain_dir = '/kaggle/input/nfl-player-contact-detection/test'\nfig, ax = plt.subplots(1,1, figsize=(15, 15))\ntrain_video_files = [train_dir + x for x in os.listdir(train_dir)]\n# video_file = train_video_files[30]\nvideo_file = '../input/nfl-player-contact-detection/test/58172_003247_All29.mp4'\ncap = cv.VideoCapture(video_file)\nsuccess, image = cap.read()\nimage = cv.cvtColor(image, cv.COLOR_BGR2RGB)\ncap.release()   \nax.imshow(image)\nax.xaxis.set_visible(False)\nax.yaxis.set_visible(False)\nax.title.set_text(f\"FRAME 0: {video_file.split('/')[-1]}\")\nplt.grid(False)","metadata":{"execution":{"iopub.status.busy":"2022-12-05T22:10:03.120974Z","iopub.execute_input":"2022-12-05T22:10:03.121344Z","iopub.status.idle":"2022-12-05T22:10:04.278558Z","shell.execute_reply.started":"2022-12-05T22:10:03.121315Z","shell.execute_reply":"2022-12-05T22:10:04.276308Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"helmets = pd.read_csv('../input/nfl-player-contact-detection/train_baseline_helmets.csv', encoding='utf8')\nhelmets.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-05T22:12:36.875708Z","iopub.execute_input":"2022-12-05T22:12:36.876186Z","iopub.status.idle":"2022-12-05T22:12:45.481907Z","shell.execute_reply.started":"2022-12-05T22:12:36.876153Z","shell.execute_reply":"2022-12-05T22:12:45.480703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = pd.read_csv('../input/nfl-player-contact-detection/train_labels.csv', encoding='utf8')\nlabels.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-05T22:14:17.306814Z","iopub.execute_input":"2022-12-05T22:14:17.307280Z","iopub.status.idle":"2022-12-05T22:14:29.503232Z","shell.execute_reply.started":"2022-12-05T22:14:17.307231Z","shell.execute_reply":"2022-12-05T22:14:29.501611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track = pd.read_csv('../input/nfl-player-contact-detection/train_player_tracking.csv', encoding='utf8')\ntrack.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-05T22:15:31.846759Z","iopub.execute_input":"2022-12-05T22:15:31.847260Z","iopub.status.idle":"2022-12-05T22:15:36.608827Z","shell.execute_reply.started":"2022-12-05T22:15:31.847219Z","shell.execute_reply":"2022-12-05T22:15:36.607920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"meta = pd.read_csv('../input/nfl-player-contact-detection/train_video_metadata.csv', encoding='utf8')\nmeta.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-05T22:16:21.601303Z","iopub.execute_input":"2022-12-05T22:16:21.601823Z","iopub.status.idle":"2022-12-05T22:16:21.625498Z","shell.execute_reply.started":"2022-12-05T22:16:21.601782Z","shell.execute_reply":"2022-12-05T22:16:21.623966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.read_csv('../input/nfl-player-contact-detection/sample_submission.csv', encoding='utf8')\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-05T22:17:13.055689Z","iopub.execute_input":"2022-12-05T22:17:13.056137Z","iopub.status.idle":"2022-12-05T22:17:13.125851Z","shell.execute_reply.started":"2022-12-05T22:17:13.056101Z","shell.execute_reply":"2022-12-05T22:17:13.124173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Jeff Herman https://www.kaggle.com/jth359/video-to-frames-and-face-detection-using-opencv/data\n\nvidObj = cv2.VideoCapture('/kaggle/input/nfl-player-contact-detection/train/58168_003392_Endzone.mp4')\n\ncount = 0\n\nwhile True: \n      \n    success, image = vidObj.read() \n    \n    if success:\n        cv2.imwrite(f\"frame{count}.jpg\", image) \n    else: \n        break\n        \n    count += 1","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:09:36.751453Z","iopub.execute_input":"2022-12-05T23:09:36.751915Z","iopub.status.idle":"2022-12-05T23:09:50.924412Z","shell.execute_reply.started":"2022-12-05T23:09:36.751881Z","shell.execute_reply":"2022-12-05T23:09:50.923015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#https://stackoverflow.com/questions/25359288/how-to-know-total-number-of-frame-in-a-file-with-cv2-in-python\n\ncap = cv2.VideoCapture(\"/kaggle/input/nfl-player-contact-detection/train/019d5b34_1.mp4\")\nlength = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))\nprint( length )","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:11:04.780843Z","iopub.execute_input":"2022-12-05T23:11:04.781311Z","iopub.status.idle":"2022-12-05T23:11:04.793212Z","shell.execute_reply.started":"2022-12-05T23:11:04.781275Z","shell.execute_reply":"2022-12-05T23:11:04.792128Z"},"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Jeff Herman https://www.kaggle.com/jth359/video-to-frames-and-face-detection-using-opencv/data\n\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\n\nfor i in range(0, 700, 100):  ## the original was 0,1300,100 The length is 702 above \n    img = mpimg.imread(f'./frame{i}.jpg')\n    imgplot = plt.imshow(img)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:11:26.569415Z","iopub.execute_input":"2022-12-05T23:11:26.569838Z","iopub.status.idle":"2022-12-05T23:11:29.293091Z","shell.execute_reply.started":"2022-12-05T23:11:26.569803Z","shell.execute_reply":"2022-12-05T23:11:29.292155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\n#PATH PROCESS\nimport os\nimport os.path\nfrom pathlib import Path\nimport glob\n#IMAGE PROCESS\nfrom PIL import Image\nfrom keras.preprocessing import image\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nimport cv2\nfrom keras.applications.vgg16 import preprocess_input, decode_predictions\nimport imageio\nfrom IPython.display import Image\nimport matplotlib.image as mpimg\nfrom skimage.transform import resize\nfrom mpl_toolkits.mplot3d import Axes3D\nfrom matplotlib import cm\nimport zipfile\nfrom io import BytesIO\nfrom nibabel import FileHolder\nfrom nibabel.analyze import AnalyzeImage\nimport PIL\nfrom IPython import display","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:42:54.666596Z","iopub.execute_input":"2022-12-05T23:42:54.667000Z","iopub.status.idle":"2022-12-05T23:43:02.028599Z","shell.execute_reply.started":"2022-12-05T23:42:54.666968Z","shell.execute_reply":"2022-12-05T23:43:02.027190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\n#SCALER & TRANSFORMATION\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.preprocessing import MinMaxScaler\nfrom keras.utils.np_utils import to_categorical\nfrom sklearn.model_selection import train_test_split\nfrom keras import regularizers\nfrom sklearn.preprocessing import LabelEncoder\n#ACCURACY CONTROL\nfrom sklearn.metrics import confusion_matrix, accuracy_score, classification_report, roc_auc_score, roc_curve\nfrom sklearn.model_selection import GridSearchCV, cross_val_score\nfrom sklearn.metrics import mean_squared_error, r2_score","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:43:04.142393Z","iopub.execute_input":"2022-12-05T23:43:04.143088Z","iopub.status.idle":"2022-12-05T23:43:04.270245Z","shell.execute_reply.started":"2022-12-05T23:43:04.143051Z","shell.execute_reply":"2022-12-05T23:43:04.269129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\n#OPTIMIZER\nfrom tensorflow.keras.optimizers import RMSprop,Adam,Optimizer,Optimizer, SGD\n#MODEL LAYERS\nfrom tensorflow.keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D, BatchNormalization,MaxPooling2D,BatchNormalization,\\\n                        Permute, TimeDistributed, Bidirectional,GRU, SimpleRNN,\\\nLSTM, GlobalAveragePooling2D, SeparableConv2D, ZeroPadding2D, Convolution2D, ZeroPadding2D,Reshape, Conv2DTranspose, LeakyReLU\nfrom tensorflow.keras import models\nfrom keras import layers\nimport tensorflow as tf\nfrom tensorflow.keras.applications import VGG16,VGG19,inception_v3\nfrom keras import backend as K\nfrom tensorflow.keras.utils import plot_model\nfrom keras.datasets import mnist\nimport keras","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:43:09.017299Z","iopub.execute_input":"2022-12-05T23:43:09.017720Z","iopub.status.idle":"2022-12-05T23:43:09.027904Z","shell.execute_reply.started":"2022-12-05T23:43:09.017686Z","shell.execute_reply":"2022-12-05T23:43:09.026688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\n#SKLEARN CLASSIFIER\nfrom xgboost import XGBClassifier, XGBRegressor\nfrom lightgbm import LGBMClassifier, LGBMRegressor\nfrom catboost import CatBoostClassifier, CatBoostRegressor\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.ensemble import RandomForestClassifier, RandomForestRegressor\nfrom sklearn.ensemble import GradientBoostingClassifier, GradientBoostingRegressor\nfrom sklearn.ensemble import BaggingRegressor\nfrom sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor\nfrom sklearn.neural_network import MLPClassifier, MLPRegressor\nfrom sklearn.neighbors import KNeighborsClassifier, KNeighborsRegressor\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.cross_decomposition import PLSRegression\nfrom sklearn.linear_model import Ridge\nfrom sklearn.linear_model import RidgeCV\nfrom sklearn.linear_model import Lasso\nfrom sklearn.linear_model import LassoCV\nfrom sklearn.linear_model import ElasticNet\nfrom sklearn.linear_model import ElasticNetCV\n#IGNORING WARNINGS\nfrom warnings import filterwarnings\nfilterwarnings(\"ignore\",category=DeprecationWarning)\nfilterwarnings(\"ignore\", category=FutureWarning) \nfilterwarnings(\"ignore\", category=UserWarning)","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:43:13.455780Z","iopub.execute_input":"2022-12-05T23:43:13.456188Z","iopub.status.idle":"2022-12-05T23:43:14.975256Z","shell.execute_reply.started":"2022-12-05T23:43:13.456155Z","shell.execute_reply":"2022-12-05T23:43:14.974232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Video_Path = \"../input/nfl-player-contact-detection/train/58173_003606_Endzone.mp4\"","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:18:38.038240Z","iopub.execute_input":"2022-12-05T23:18:38.038684Z","iopub.status.idle":"2022-12-05T23:18:38.044377Z","shell.execute_reply.started":"2022-12-05T23:18:38.038647Z","shell.execute_reply":"2022-12-05T23:18:38.043114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\nVideo_IMG_List = []\n\nVideo_Cap = cv2.VideoCapture(Video_Path)\n\n\nwhile Video_Cap.isOpened():\n\n    \n    ret,frame = Video_Cap.read()\n    \n    if ret != True:\n        break\n        \n    if Video_Cap.isOpened():\n        Transformation_IMG = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)\n        Resize_IMG = cv2.resize(Transformation_IMG,(180,180))\n        Video_IMG_List.append(Resize_IMG)\n        \n        \nVideo_Cap.release()","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:19:00.579797Z","iopub.execute_input":"2022-12-05T23:19:00.580207Z","iopub.status.idle":"2022-12-05T23:19:06.107477Z","shell.execute_reply.started":"2022-12-05T23:19:00.580172Z","shell.execute_reply":"2022-12-05T23:19:06.106177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(np.shape(np.asarray(Video_IMG_List)))","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:19:22.420587Z","iopub.execute_input":"2022-12-05T23:19:22.421156Z","iopub.status.idle":"2022-12-05T23:19:22.513453Z","shell.execute_reply.started":"2022-12-05T23:19:22.421115Z","shell.execute_reply":"2022-12-05T23:19:22.512251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\nfigure = plt.figure(figsize=(8,8))\n\nPick_IMG = Video_IMG_List[1]\nplt.xlabel(Pick_IMG.shape)\nplt.ylabel(Pick_IMG.size)\nplt.imshow(Pick_IMG);","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:19:39.907085Z","iopub.execute_input":"2022-12-05T23:19:39.907563Z","iopub.status.idle":"2022-12-05T23:19:40.352477Z","shell.execute_reply.started":"2022-12-05T23:19:39.907526Z","shell.execute_reply":"2022-12-05T23:19:40.351458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\nfigure = plt.figure(figsize=(8,8))\n\nPick_IMG = Video_IMG_List[700]#Original is 1000, but we have 750, 180, 180, 3 \nplt.xlabel(Pick_IMG.shape)\nplt.ylabel(Pick_IMG.size)\nplt.imshow(Pick_IMG);","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:20:00.953972Z","iopub.execute_input":"2022-12-05T23:20:00.954380Z","iopub.status.idle":"2022-12-05T23:20:01.412104Z","shell.execute_reply.started":"2022-12-05T23:20:00.954346Z","shell.execute_reply":"2022-12-05T23:20:01.410457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\nfigure = plt.figure(figsize=(8,8))\n\nPick_IMG = Video_IMG_List[610]#Original 3410\nplt.xlabel(Pick_IMG.shape)\nplt.ylabel(Pick_IMG.size)\nplt.imshow(Pick_IMG);","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:20:20.171977Z","iopub.execute_input":"2022-12-05T23:20:20.173674Z","iopub.status.idle":"2022-12-05T23:20:20.609972Z","shell.execute_reply.started":"2022-12-05T23:20:20.173607Z","shell.execute_reply":"2022-12-05T23:20:20.609002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"figure,axis = plt.subplots(4,4,figsize=(10,10))\n\nfor i,ax in enumerate(axis.flat):\n    \n    IMG_From_List = Video_IMG_List[i]\n    ax.set_xlabel(IMG_From_List.shape)\n    ax.imshow(IMG_From_List)\n    \nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:20:39.377415Z","iopub.execute_input":"2022-12-05T23:20:39.377939Z","iopub.status.idle":"2022-12-05T23:20:41.291866Z","shell.execute_reply.started":"2022-12-05T23:20:39.377792Z","shell.execute_reply":"2022-12-05T23:20:41.290908Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_Train = np.asarray(Video_IMG_List)","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:21:02.432901Z","iopub.execute_input":"2022-12-05T23:21:02.433326Z","iopub.status.idle":"2022-12-05T23:21:02.514921Z","shell.execute_reply.started":"2022-12-05T23:21:02.433290Z","shell.execute_reply":"2022-12-05T23:21:02.513290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_Train.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:21:16.595984Z","iopub.execute_input":"2022-12-05T23:21:16.596426Z","iopub.status.idle":"2022-12-05T23:21:16.603548Z","shell.execute_reply.started":"2022-12-05T23:21:16.596385Z","shell.execute_reply":"2022-12-05T23:21:16.602019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\nfigure = plt.figure(figsize=(8,8))\n\nPick_IMG = X_Train[410]\nplt.xlabel(Pick_IMG.shape)\nplt.ylabel(Pick_IMG.size)\nplt.imshow(Pick_IMG);","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:21:34.628418Z","iopub.execute_input":"2022-12-05T23:21:34.628925Z","iopub.status.idle":"2022-12-05T23:21:35.102226Z","shell.execute_reply.started":"2022-12-05T23:21:34.628885Z","shell.execute_reply":"2022-12-05T23:21:35.100662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Baris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\nfigure = plt.figure(figsize=(8,8))\n\nPick_IMG = X_Train[534]#Original 3534\nplt.xlabel(Pick_IMG.shape)\nplt.ylabel(Pick_IMG.size)\nplt.imshow(Pick_IMG);","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:22:09.590604Z","iopub.execute_input":"2022-12-05T23:22:09.592337Z","iopub.status.idle":"2022-12-05T23:22:10.060401Z","shell.execute_reply.started":"2022-12-05T23:22:09.592250Z","shell.execute_reply":"2022-12-05T23:22:10.058919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Ducky https://www.kaggle.com/code/illgamhoduck/nfl-starter-eda\n\nENV_DIR = '../input'\nDATA_DIR = f'{ENV_DIR}/nfl-player-contact-detection'","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:43:27.752076Z","iopub.execute_input":"2022-12-05T23:43:27.752520Z","iopub.status.idle":"2022-12-05T23:43:27.758680Z","shell.execute_reply.started":"2022-12-05T23:43:27.752487Z","shell.execute_reply":"2022-12-05T23:43:27.757309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir(DATA_DIR)","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:43:32.370553Z","iopub.execute_input":"2022-12-05T23:43:32.370971Z","iopub.status.idle":"2022-12-05T23:43:32.381199Z","shell.execute_reply.started":"2022-12-05T23:43:32.370936Z","shell.execute_reply":"2022-12-05T23:43:32.380158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Ducky https://www.kaggle.com/code/illgamhoduck/nfl-starter-eda\n\n# Training data\n# -----------------------------------------------------------------------\n# Player information is included\n\n# Bounding Box\ntrain_df = pd.read_csv(f'{DATA_DIR}/train_labels.csv')\n\n# Tracking Information using Sensor\ntrain_tracking_df = pd.read_csv(f'{DATA_DIR}/train_player_tracking.csv')\ntest_tracking_df = pd.read_csv(f'{DATA_DIR}/test_player_tracking.csv')\n\n# images/\n# -----------------------------------------------------------------------\n# Trained images using images_labels.csv and predict the train, test\n# The prediction result is [train/test]_baseline_helmets.csv\n# No player information is included\n\n# information of images without player information\nimage_df = pd.read_csv(f'{DATA_DIR}/train_baseline_helmets.csv')\n\n# Baseline Prediction - Trained by images inside folder images/\ntrain_predict_df = pd.read_csv(f'{DATA_DIR}/train_baseline_helmets.csv')\n\ntest_predict_df = pd.read_csv(f'{DATA_DIR}/test_baseline_helmets.csv')","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:43:39.505884Z","iopub.execute_input":"2022-12-05T23:43:39.506543Z","iopub.status.idle":"2022-12-05T23:44:06.592403Z","shell.execute_reply.started":"2022-12-05T23:43:39.506493Z","shell.execute_reply":"2022-12-05T23:44:06.591221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# reference : https://www.kaggle.com/coldfir3/eda-helmet-keypoint-tracking-data-comparison\ndef get_frame_from_video(video_path, frame):\n    video_path = f\"{DATA_DIR}/train/{video_path}\"\n    frame = frame - 1\n    \n    !ffmpeg \\\n        -hide_banner \\\n        -loglevel fatal \\\n        -nostats \\\n        -i $video_path -vf \"select=eq(n\\,$frame)\" -vframes 1 frame.png\n    \n    img = PIL.Image.open('frame.png')#StackOverflow https://stackoverflow.com/questions/10748822/img-image-openfp-attributeerror-class-image-has-no-attribute-open\n    os.remove('frame.png')\n    return img","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:44:10.184281Z","iopub.execute_input":"2022-12-05T23:44:10.184729Z","iopub.status.idle":"2022-12-05T23:44:10.191991Z","shell.execute_reply.started":"2022-12-05T23:44:10.184684Z","shell.execute_reply":"2022-12-05T23:44:10.190752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_frame_from_video('58176_002844_Sideline.mp4', 1)","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:44:17.256022Z","iopub.execute_input":"2022-12-05T23:44:17.256635Z","iopub.status.idle":"2022-12-05T23:44:19.607910Z","shell.execute_reply.started":"2022-12-05T23:44:17.256601Z","shell.execute_reply":"2022-12-05T23:44:19.606811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def draw_rect(image, bbox_df):\n    new_image = image.copy()\n    draw = ImageDraw.Draw(new_image)\n    for _, (left, width, top, height) in bbox_df[['left', 'width', 'top', 'height']].iterrows():\n        draw.rectangle(((left, top), (left + width, top + height)), outline=(255, 0, 0), width=2)\n    \n    return new_image","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:44:46.618628Z","iopub.execute_input":"2022-12-05T23:44:46.619040Z","iopub.status.idle":"2022-12-05T23:44:46.626968Z","shell.execute_reply.started":"2022-12-05T23:44:46.619004Z","shell.execute_reply":"2022-12-05T23:44:46.625901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def frame_bbox(df, video_frame):\n    video_name = '_'.join(video_frame.split('_')[:3]) + '.mp4'\n    frame = int(video_frame.split('_')[-1])\n    \n    image = get_frame_from_video(video_name, frame)\n    bbox_df = df.query('video_frame == @video_frame')\n    \n    bbox_image = draw_rect(image, bbox_df)\n    \n    return bbox_image","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:45:02.575064Z","iopub.execute_input":"2022-12-05T23:45:02.575496Z","iopub.status.idle":"2022-12-05T23:45:02.583278Z","shell.execute_reply.started":"2022-12-05T23:45:02.575461Z","shell.execute_reply":"2022-12-05T23:45:02.581563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#frame_bbox(train_df, '58172_003247_All29')","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-12-06T00:11:17.716447Z","iopub.execute_input":"2022-12-06T00:11:17.717010Z","iopub.status.idle":"2022-12-06T00:11:17.721764Z","shell.execute_reply.started":"2022-12-06T00:11:17.716960Z","shell.execute_reply":"2022-12-06T00:11:17.720880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Above ValueError: invalid literal for int() with base 10: 'All29'\n\nI don't know how to fix it with mp4 files","metadata":{}},{"cell_type":"markdown","source":"#Display a Video","metadata":{}},{"cell_type":"code","source":"from IPython.display import Video, display\n\ndef video(video_path, ratio=0.7):\n    nfl_video = Video(f\"{DATA_DIR}/train/{video_path}\",\n                      embed=True,\n                      height=int(720 * ratio),\n                      width=int(1280 * ratio))\n    return nfl_video\n    \nvideo('58173_003606_Endzone.mp4')","metadata":{"execution":{"iopub.status.busy":"2022-12-05T23:57:23.705098Z","iopub.execute_input":"2022-12-05T23:57:23.705541Z","iopub.status.idle":"2022-12-05T23:57:24.304123Z","shell.execute_reply.started":"2022-12-05T23:57:23.705506Z","shell.execute_reply":"2022-12-05T23:57:24.302453Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Video 2 Patriots field - End Racism","metadata":{}},{"cell_type":"code","source":"def video2(video_path2, ratio=0.7):\n    nfl_video2 = Video(f\"{DATA_DIR}/train/{video_path2}\",\n                      embed=True,\n                      height=int(720 * ratio),\n                      width=int(1280 * ratio))\n    return nfl_video2\n    \nvideo2('58176_002844_Sideline.mp4')","metadata":{"execution":{"iopub.status.busy":"2022-12-06T00:07:04.269097Z","iopub.execute_input":"2022-12-06T00:07:04.269575Z","iopub.status.idle":"2022-12-06T00:07:04.410129Z","shell.execute_reply.started":"2022-12-06T00:07:04.269536Z","shell.execute_reply":"2022-12-06T00:07:04.407573Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Safety First - I still couldn't make the Bounding Boxes.","metadata":{}},{"cell_type":"markdown","source":"![](https://thumbs.gfycat.com/AnotherBadKite-size_restricted.gif)Gfycat","metadata":{}},{"cell_type":"markdown","source":"#Acknowledgements:\n\nBaris Dincer https://www.kaggle.com/brsdincer/human-evolution-process-dcgan/notebook\n\nRob Mulla https://www.kaggle.com/robikscube/kaggle-deepfake-detection-introduction\n\nJeff Herman https://www.kaggle.com/jth359/video-to-frames-and-face-detection-using-opencv/data\n\nDucky https://www.kaggle.com/code/illgamhoduck/nfl-starter-eda\n\nAdriano Passos https://www.kaggle.com/coldfir3/eda-helmet-keypoint-tracking-data-comparison","metadata":{}}]}