Commit f37a47f5 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

visualizer

parent a44dbcfe
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: '../butterfly-code-20x20.csv'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-fd27115351d9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[0mvideo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mVideoCapture\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'{}-code-{}x{}.mp4'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 22\u001b[0;31m \u001b[0mpattern\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'{}-code-{}x{}.csv'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 23\u001b[0m \u001b[0mnpzFile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'{}-ideal-{}x{}.npz'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '../butterfly-code-20x20.csv'"
]
}
],
"source": [
"FILE_NAME='../butterfly'\n",
"GRID_X=20\n",
"GRID_Y=20\n",
"\n",
"\n",
"CELLS_PER_FRAME=GRID_X*GRID_Y\n",
"\n",
"import cv2\n",
"import numpy as np\n",
"\n",
"def binArray(x):\n",
" ans=np.zeros((CELLS_PER_FRAME),dtype=np.uint8)\n",
" \n",
" for i in range(CELLS_PER_FRAME):\n",
" ans[i]=x&1\n",
" x=x>>1\n",
" return ans\n",
"\n",
"\n",
"\n",
"video = cv2.VideoCapture('{}-code-{}x{}.mp4'.format(FILE_NAME,GRID_X,GRID_Y))\n",
"pattern = open('{}-code-{}x{}.csv'.format(FILE_NAME,GRID_X,GRID_Y))\n",
"npzFile = '{}-ideal-{}x{}.npz'.format(FILE_NAME,GRID_X,GRID_Y)\n",
"\n",
"XX=[]\n",
"YY=[]\n",
"\n",
"while video.isOpened():\n",
" ret, frame = video.read()\n",
" pat = pattern.readline()\n",
" if ret:\n",
" YY.append(binArray(int(pat)))\n",
" frame=cv2.resize(frame,(299,299),interpolation = cv2.INTER_LINEAR)\n",
" XX.append(frame)\n",
" else:\n",
" break\n",
"video.release()\n",
"pattern.close()\n",
"\n",
"XX=np.array(XX)\n",
"YY=np.array(YY)\n",
"np.savez(npzFile, X=XX, Y=YY)\n",
"print(\"X shape\",XX.shape,\"Y shape\",YY.shape)"
]
},
{
"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
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X shape (20000, 400) Y shape (20000, 299, 299, 3)\n"
]
},
{
"ename": "IndexError",
"evalue": "tuple index out of range",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-4-bdade1271f1e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[0;31m#print(i,Y[i],'\\r')\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 51\u001b[0;31m \u001b[0ml\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mgenImage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mY\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 52\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Image\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-4-bdade1271f1e>\u001b[0m in \u001b[0;36mgenImage\u001b[0;34m(label)\u001b[0m\n\u001b[1;32m 32\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mgenImage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 34\u001b[0;31m \u001b[0mframe\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint8\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 35\u001b[0m \u001b[0mnoCellsSqrt\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 36\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcellHeight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnoCellsSqrt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mIndexError\u001b[0m: tuple index out of range"
]
}
],
"source": [
"'''\n",
"This script is used to verify the dataset created\n",
"All you have to do is to change the FILE_NAME variable and run the program\n",
"\n",
"'''\n",
"\n",
"import numpy as np\n",
"import cv2\n",
"import sys\n",
"import random\n",
"import math\n",
"random.seed(625742)\n",
"FILE_NAME='../../../video/videos-ideal-20x20-shuffled.npz'\n",
"NO_FRAMES_TO_CHECK=100\n",
"SHELL=False\n",
"\n",
"\n",
"if SHELL:\n",
" if len(sys.argv)>=2:\n",
" FILE_NAME=sys.argv[1]\n",
" if len(sys.argv)==3:\n",
" NO_FRAMES_TO_CHECK=int(sys.argv[2])\n",
" \n",
" \n",
"\n",
"data=np.load(FILE_NAME)\n",
"X=data['X']\n",
"Y=data['Y']\n",
"\n",
"print(\"X shape\",X.shape,\"Y shape\",Y.shape)\n",
"\n",
"\n",
"def genImage(label):\n",
" frame=np.zeros((X.shape[1],X.shape[2],3),dtype=np.uint8)\n",
" noCellsSqrt=int(math.sqrt(len(label)))\n",
" h=cellHeight=int(frame.shape[0]/noCellsSqrt)\n",
" w=cellWidth=int(frame.shape[1]/noCellsSqrt)\n",
" for y in range(noCellsSqrt):\n",
" for x in range(noCellsSqrt):\n",
"# print(x,y,noCellsSqrt,h,w)\n",
" frame[y*h:(y+1)*h,x*w:(x+1)*w,:]=label[y*noCellsSqrt+x]*255\n",
" \n",
"# print(label[y*noCellsSqrt+x])\n",
" frame=cv2.flip(frame,-1)\n",
" return frame\n",
" \n",
"\n",
"for f in range(NO_FRAMES_TO_CHECK):\n",
" i=random.randint(0,X.shape[0]-1)\n",
" #print(i,Y[i],'\\r')\n",
" l=genImage(Y[i])\n",
"\n",
" cv2.imshow(\"Image\",X[i])\n",
" cv2.imshow(\"Label\",l)\n",
" cv2.waitKey(0)\n",
" \n",
"cv2.destroyAllWindows()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"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
}
......@@ -19,7 +19,7 @@ DELTA = 5
NUMPAT33 = 384
READ_FILE = "../butterfly"
READ_FILE = "../drone"
EXTENSION = ".mp4"
OUT_FILE = "{}-code-{}x{}".format(READ_FILE,GRID_Y,GRID_X)
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X shape (10000, 360, 480, 3) Y shape (10000, 25)\n"
]
}
],
"source": [
"'''\n",
"This script is used to verify the dataset created\n",
"All you have to do is to change the FILE_NAME variable and run the program\n",
"\n",
"'''\n",
"\n",
"import numpy as np\n",
"import cv2\n",
"import sys\n",
"import random\n",
"import math\n",
"random.seed(625742)\n",
"FILE_NAME='../../video/nature-5x5.npz'\n",
"NO_FRAMES_TO_CHECK=100\n",
"SHELL=False\n",
"\n",
"\n",
"if SHELL:\n",
" if len(sys.argv)>=2:\n",
" FILE_NAME=sys.argv[1]\n",
" if len(sys.argv)==3:\n",
" NO_FRAMES_TO_CHECK=int(sys.argv[2])\n",
" \n",
" \n",
"\n",
"data=np.load(FILE_NAME)\n",
"X=data['X']\n",
"Y=data['Y']\n",
"\n",
"print(\"X shape\",X.shape,\"Y shape\",Y.shape)\n",
"\n",
"\n",
"def genImage(label):\n",
" frame=np.zeros((X.shape[1],X.shape[2],3),dtype=np.uint8)\n",
" noCellsSqrt=int(math.sqrt(len(label)))\n",
" h=cellHeight=int(frame.shape[0]/noCellsSqrt)\n",
" w=cellWidth=int(frame.shape[1]/noCellsSqrt)\n",
" for y in range(noCellsSqrt):\n",
" for x in range(noCellsSqrt):\n",
"# print(x,y,noCellsSqrt,h,w)\n",
" frame[y*h:(y+1)*h,x*w:(x+1)*w,:]=label[y*noCellsSqrt+x]*255\n",
" \n",
"# print(label[y*noCellsSqrt+x])\n",
" frame=cv2.flip(frame,-1)\n",
" return frame\n",
" \n",
"\n",
"for f in range(NO_FRAMES_TO_CHECK):\n",
" i=random.randint(0,X.shape[0]-1)\n",
" #print(i,Y[i],'\\r')\n",
" l=genImage(Y[i])\n",
"\n",
" cv2.imshow(\"Image\",X[i])\n",
" cv2.imshow(\"Label\",l)\n",
" cv2.waitKey(0)\n",
" \n",
"cv2.destroyAllWindows()\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
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: '../../video/butterfly-code-20x20.csv'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-8-5f03600d6eff>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[0mvideo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mVideoCapture\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'{}-code-{}x{}.mp4'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 22\u001b[0;31m \u001b[0mpattern\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'{}-code-{}x{}.csv'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 23\u001b[0m \u001b[0mnpzFile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'{}-ideal-{}x{}.npz'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFILE_NAME\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_X\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mGRID_Y\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '../../video/butterfly-code-20x20.csv'"
]
}
],
"source": [
"FILE_NAME='../../video/butterfly'\n",
"GRID_X=20\n",
"GRID_Y=20\n",
"\n",
"\n",
"CELLS_PER_FRAME=GRID_X*GRID_Y\n",
"\n",
"import cv2\n",
"import numpy as np\n",
"\n",
"def binArray(x):\n",
" ans=np.zeros((CELLS_PER_FRAME),dtype=np.uint8)\n",
" \n",
" for i in range(CELLS_PER_FRAME):\n",
" ans[i]=x&1\n",
" x=x>>1\n",
" return ans\n",
"\n",
"\n",
"\n",
"video = cv2.VideoCapture('{}-code-{}x{}.mp4'.format(FILE_NAME,GRID_X,GRID_Y))\n",
"pattern = open('{}-code-{}x{}.csv'.format(FILE_NAME,GRID_X,GRID_Y))\n",
"npzFile = '{}-ideal-{}x{}.npz'.format(FILE_NAME,GRID_X,GRID_Y)\n",
"\n",
"XX=[]\n",
"YY=[]\n",
"\n",
"while video.isOpened():\n",
" ret, frame = video.read()\n",
" pat = pattern.readline()\n",
" if ret:\n",
" YY.append(binArray(int(pat)))\n",
" frame=cv2.resize(frame,(299,299),interpolation = cv2.INTER_LINEAR)\n",
" XX.append(frame)\n",
" else:\n",
" break\n",
"video.release()\n",
"pattern.close()\n",
"\n",
"XX=np.array(XX)\n",
"YY=np.array(YY)\n",
"np.savez(npzFile, X=XX, Y=YY)\n",
"print(\"X shape\",XX.shape,\"Y shape\",YY.shape)"
]
},
{
"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
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Up to file 0. X=(5000, 400) Y=(5000, 299, 299, 3).\n",
"Up to file 1. X=(10000, 400) Y=(10000, 299, 299, 3).\n",
"Up to file 2. X=(15000, 400) Y=(15000, 299, 299, 3).\n",
"Up to file 3. X=(20000, 400) Y=(20000, 299, 299, 3).\n",
"Shuffled\n",
"Finish saving file\n"
]
}
],
"source": [
"PREFIX='../../video/'\n",
"FILES=['butterfly-ideal-20x20','travel-ideal-20x20','mario-ideal-20x20','drone-ideal-20x20']\n",
"OUTPUT_FILE='videos-ideal-20x20'\n",
"EXTENSION='.npz'\n",
"\n",
"SHUFFLE=True\n",
"\n",
"\n",
"import numpy as np\n",
"\n",
"\n",
"\n",
"fileNames=[]\n",
"\n",
"for f in range(len(FILES)):\n",
" fileNames.append(PREFIX+FILES[f]+EXTENSION)\n",
"\n",
"data=np.load(fileNames[0])\n",
"X=data['X'][:5000]\n",
"Y=data['Y'][:5000]\n",
"\n",
"print(\"Up to file {}. X={} Y={}.\".format(0,X.shape,Y.shape))\n",
"\n",
"for f in range(1,len(fileNames)):\n",
" data=np.load(fileNames[f])\n",
" X=np.concatenate((X,data['X'][:5000]))\n",
" Y=np.concatenate((Y,data['Y'][:5000]))\n",
" \n",
" print(\"Up to file {}. X={} Y={}.\".format(f,X.shape,Y.shape))\n",
"\n",
"if SHUFFLE:\n",
" p = np.random.permutation(len(X))\n",
" X=X[p]\n",
" Y=Y[p]\n",
" print(\"Shuffled\")\n",
" np.savez(\"{}{}-shuffled.npz\".format(PREFIX,OUTPUT_FILE),X=X,Y=Y)\n",
"else:\n",
" np.savez(\"{}{}.npz\".format(PREFIX,OUTPUT_FILE),X=X,Y=Y)\n",
"\n",
"print(\"Finish saving file\")\n",
"\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
}
......@@ -2,14 +2,26 @@
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X shape (10000, 360, 480, 3) Y shape (10000, 25)\n"
"X shape (20000, 400) Y shape (20000, 299, 299, 3)\n"
]
},
{
"ename": "IndexError",
"evalue": "tuple index out of range",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-bdade1271f1e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[0;31m#print(i,Y[i],'\\r')\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 51\u001b[0;31m \u001b[0ml\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mgenImage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mY\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 52\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Image\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-5-bdade1271f1e>\u001b[0m in \u001b[0;36mgenImage\u001b[0;34m(label)\u001b[0m\n\u001b[1;32m 32\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mgenImage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 34\u001b[0;31m \u001b[0mframe\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint8\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 35\u001b[0m \u001b[0mnoCellsSqrt\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 36\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcellHeight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnoCellsSqrt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mIndexError\u001b[0m: tuple index out of range"
]
}
],
......@@ -26,7 +38,7 @@
"import random\n",
"import math\n",
"random.seed(625742)\n",
"FILE_NAME='../../video/nature-5x5.npz'\n",
"FILE_NAME='../../../video/videos-ideal-20x20-shuffled.npz'\n",
"NO_FRAMES_TO_CHECK=100\n",
"SHELL=False\n",
"\n",
......@@ -73,6 +85,13 @@
"cv2.destroyAllWindows()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
......
This diff is collapsed.
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