Commit 39221da7 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

Upload New File

parent ee9ad2f9
{
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"source": [
"import keras\n",
"import numpy as np\n",
"import cv2\n",
"import sys"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"cap = cv2.VideoCapture('./video/none_256_5_mix.mp4')\n",
"if (cap.isOpened()== False): \n",
" print(\"Error opening video stream or file\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"NO_OF_FRAMES=10\n",
"'''NO_OF_FRAMES=int(sys.argv[1])\n",
"'''\n",
"FRAME_HEIGHT=1080\n",
"FRAME_WIDTH=1920\n",
"COLOR_CHANNELS=3\n",
"\n",
"EPOCHS=10\n",
"BATCH_SIZE=4\n",
"CUDA1=0\n",
"CUDA2=1\n",
"\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"{},{}\".format(CUDA1,CUDA2)\n",
"\n",
"\n",
"'''EPOCHS=int(sys.argv[2])\n",
"BATCH_SIZE=int(sys.argv[3])\n",
"CUDA1=int(sys.argv[4])\n",
"CUDA2=int(sys.argv[5])'''\n"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"cap.release()\n",
"cv2.destroyAllWindows()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"while(cap.isOpened()):\n",
" ret, frame = cap.read()\n",
" if ret == True:\n",
" cv2.imshow('Frame',frame)\n",
" if cv2.waitKey(25) & 0xFF == ord('q'):\n",
" break\n",
" else: \n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"def makeX(cap):\n",
" ret,frame=cap.read()\n",
" '''if (len(sys.argv)>1):\n",
" NO_OF_FRAMES=int(sys.argv[1])'''\n",
"\n",
" X=np.zeros((NO_OF_FRAMES,FRAME_HEIGHT,FRAME_WIDTH,COLOR_CHANNELS))\n",
" \n",
" for f in range(NO_OF_FRAMES):\n",
" X[f,:,:,:]=frame\n",
" ret,frame=cap.read()\n",
"\n",
" '''if f%1 == 0:\n",
" print(len(X[f,:,4,1]))'''\n",
" \n",
" return X\n",
"#maxeX(cap)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"def makeY():\n",
" import pandas as pd\n",
" df=pd.read_csv('./video/none_256_5_mix.csv', sep=',',header=None)\n",
" df=np.array(df)\n",
" df=df[:,1]\n",
" return df\n",
" \n",
"#makeY()"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"X=makeX(cap)\n",
"Y=makeY()"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X shape (10, 1080, 1920, 1), Y shape (12016,).\n"
]
}
],
"source": [
"'''Preparing the input and output vectors'''\n",
"X=np.mean(X,axis=3)\n",
"X=np.reshape(X,(X.shape[0],X.shape[1],X.shape[2],1))\n",
"\n",
"\n",
"print(\"X shape {}, Y shape {}.\".format(X.shape,Y.shape))"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"def cnn(inptuDim,outputDim):\n",
" model=Sequential()\n",
" model.add(Conv2D(5, kernel_size=(5,5), activation='relu',strides=(2,2)))\n",
" model.add(Conv2D(5, kernel_size=(5,5), activation='relu',strides=(2,2)))\n",
" model.add(Conv2D(5, kernel_size=(2,2), activation='relu',strides=(2,2)))\n",
" model.add(Conv2D(5, kernel_size=(2,2), activation='relu',strides=(2,2)))\n",
" model.add(Flatten())\n",
" model.add(Dense(10000,activation='relu'))\n",
" model.add(Dense(2000,activation='relu'))\n",
" model.add(Dense(500,activation='relu'))\n",
" model.add(Dense(50,activation='relu'))\n",
" model.add(Dense((1),activation='linear'))\n",
"\n",
" return model\n"
]
},
{
"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.5.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment