diff --git a/CIFAR10_extract_download.ipynb b/CIFAR10_extract_download.ipynb new file mode 100644 index 0000000..e9b3782 --- /dev/null +++ b/CIFAR10_extract_download.ipynb @@ -0,0 +1,119 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from __future__ import absolute_import\n", + "from __future__ import division\n", + "from __future__ import print_function\n", + "\n", + "import argparse\n", + "import os\n", + "import sys\n", + "import tarfile\n", + "\n", + "from six.moves import urllib\n", + "import tensorflow as tf" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ">> Downloading cifar-10-binary.tar.gz 100.0%\n", + "Successfully downloaded cifar-10-binary.tar.gz 170052171 bytes.\n" + ] + }, + { + "ename": "SystemExit", + "evalue": "", + "output_type": "error", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[0;31mSystemExit\u001b[0m\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/ysqyang/anaconda3/envs/tensorflow/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2918: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n", + " warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n" + ] + } + ], + "source": [ + "DATA_URL = 'https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz'\n", + "\n", + "parser = argparse.ArgumentParser()\n", + "\n", + "parser.add_argument(\n", + " '--data_dir', type=str, default='/tmp/cifar10_data',\n", + " help='Directory to download data and extract the tarball')\n", + "\n", + "\n", + "def main(_):\n", + " \"\"\"Download and extract the tarball from Alex's website.\"\"\"\n", + " if not os.path.exists(FLAGS.data_dir):\n", + " os.makedirs(FLAGS.data_dir)\n", + " \n", + " filename = DATA_URL.split('/')[-1]\n", + " filepath = os.path.join(FLAGS.data_dir, filename)\n", + "\n", + " if not os.path.exists(filepath):\n", + " def _progress(count, block_size, total_size):\n", + " sys.stdout.write('\\r>> Downloading %s %.1f%%' % (\n", + " filename, 100.0 * count * block_size / total_size))\n", + " sys.stdout.flush()\n", + "\n", + " filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress)\n", + " print()\n", + " statinfo = os.stat(filepath)\n", + " print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')\n", + "\n", + " tarfile.open(filepath, 'r:gz').extractall(FLAGS.data_dir)\n", + "\n", + "\n", + "if __name__ == '__main__':\n", + " FLAGS, unparsed = parser.parse_known_args()\n", + " tf.app.run(argv=[sys.argv[0]] + unparsed)" + ] + }, + { + "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.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Model2.ipynb b/Model2.ipynb deleted file mode 100644 index 6b7eeb3..0000000 --- a/Model2.ipynb +++ /dev/null @@ -1,405 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "from __future__ import absolute_import\n", - "from __future__ import print_function\n", - "import os\n", - "import glob\n", - "import random\n", - "import numpy as np\n", - "from keras import optimizers\n", - "from keras.layers import LSTM\n", - "from keras.models import Sequential, Model\n", - "from keras.applications.vgg16 import VGG16\n", - "from keras.layers.wrappers import TimeDistributed\n", - "from keras.applications.mobilenet import MobileNet\n", - "from keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense, GlobalAveragePooling2D\n", - "from keras.layers import Input, InputLayer\n", - "from keras.layers.core import Activation, Flatten, Reshape\n", - "from keras.layers.convolutional import Convolution2D, MaxPooling2D, UpSampling2D\n", - "from keras.layers.normalization import BatchNormalization\n", - "from keras.utils import np_utils\n", - "from keras.applications import imagenet_utils" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "videoFiles = glob.glob('../dataset/first-set/numpys/*.npy')\n", - "mosFiles = [i for i in videoFiles if 'mos' in i]\n", - "videoFiles = [i for i in videoFiles if 'mos' not in i]" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "def myGenerator():\n", - " while True:\n", - " index_list = random.sample(range(1, 80), 5)\n", - " alldata_x = []\n", - " alldata_y = []\n", - " for i in index_list:\n", - " f = videoFiles[i]\n", - " s = f[:-4]+'_mos.npy'\n", - " a = np.load(f)\n", - " b = np.load(s)\n", - " alldata_x.append(a)\n", - " alldata_y.append(b)\n", - " alldata_x = np.array(alldata_x)\n", - " #alldata_x = np.rollaxis(alldata_x, 1, 5) \n", - " #alldata_x = alldata_x.reshape((32, 30, height, width, 3))\n", - " #alldata_x = np.swapaxes(alldata_x, 1, 4)\n", - " alldata_y = np.array(alldata_y)\n", - " yield alldata_x, alldata_y\n", - "# x = myGenerator()\n", - "# xtrain, ytrain = next(x)\n", - "# print('xtrain shape:',xtrain.shape)\n", - "# print('ytrain shape:',ytrain.shape)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "height = 68\n", - "width = 120\n", - "input_shape=(200, height, width, 3)" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "ename": "ValueError", - "evalue": "number of input channels does not match corresponding dimension of filter, 120 != 3", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msummary\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 18\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 19\u001b[0;31m \u001b[0mmySegNet\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_shape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m\u001b[0m in \u001b[0;36mmySegNet\u001b[0;34m(input_shape)\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;31m#model.add(TimeDistributed(cnn_model, input_shape=input_shape))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;31m#model.add(TimeDistributed(Flatten()))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcnn_model\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 12\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mFlatten\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 13\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/models.py\u001b[0m in \u001b[0;36madd\u001b[0;34m(self, layer)\u001b[0m\n\u001b[1;32m 490\u001b[0m output_shapes=[self.outputs[0]._keras_shape])\n\u001b[1;32m 491\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 492\u001b[0;31m \u001b[0moutput_tensor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlayer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\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 493\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput_tensor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 494\u001b[0m raise TypeError('All layers in a Sequential model '\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, **kwargs)\u001b[0m\n\u001b[1;32m 615\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 616\u001b[0m \u001b[0;31m# Actually call the layer, collecting output(s), mask(s), and shape(s).\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 617\u001b[0;31m \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 618\u001b[0m \u001b[0moutput_mask\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompute_mask\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprevious_mask\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 619\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py\u001b[0m in \u001b[0;36mcall\u001b[0;34m(self, inputs, mask)\u001b[0m\n\u001b[1;32m 2076\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_output_tensor_cache\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcache_key\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2077\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2078\u001b[0;31m \u001b[0moutput_tensors\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_internal_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmasks\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2079\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0moutput_tensors\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2080\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py\u001b[0m in \u001b[0;36mrun_internal_graph\u001b[0;34m(self, inputs, masks)\u001b[0m\n\u001b[1;32m 2227\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'mask'\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2228\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'mask'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcomputed_mask\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2229\u001b[0;31m \u001b[0moutput_tensors\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_to_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlayer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcomputed_tensor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 2230\u001b[0m output_masks = _to_list(layer.compute_mask(computed_tensor,\n\u001b[1;32m 2231\u001b[0m computed_mask))\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/layers/convolutional.py\u001b[0m in \u001b[0;36mcall\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0mpadding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpadding\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 167\u001b[0m \u001b[0mdata_format\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata_format\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 168\u001b[0;31m dilation_rate=self.dilation_rate)\n\u001b[0m\u001b[1;32m 169\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrank\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 170\u001b[0m outputs = K.conv3d(\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py\u001b[0m in \u001b[0;36mconv2d\u001b[0;34m(x, kernel, strides, padding, data_format, dilation_rate)\u001b[0m\n\u001b[1;32m 3330\u001b[0m \u001b[0mstrides\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstrides\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3331\u001b[0m \u001b[0mpadding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpadding\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3332\u001b[0;31m data_format=tf_data_format)\n\u001b[0m\u001b[1;32m 3333\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3334\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdata_format\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'channels_first'\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mtf_data_format\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'NHWC'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/nn_ops.py\u001b[0m in \u001b[0;36mconvolution\u001b[0;34m(input, filter, padding, strides, dilation_rate, name, data_format)\u001b[0m\n\u001b[1;32m 779\u001b[0m \u001b[0mdilation_rate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdilation_rate\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 780\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 781\u001b[0;31m data_format=data_format)\n\u001b[0m\u001b[1;32m 782\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfilter\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 783\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/nn_ops.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, input_shape, filter_shape, padding, strides, dilation_rate, name, data_format)\u001b[0m\n\u001b[1;32m 839\u001b[0m \u001b[0;34m\"number of input channels does not match corresponding dimension of \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 840\u001b[0m \"filter, {} != {}\".format(input_channels_dim,\n\u001b[0;32m--> 841\u001b[0;31m filter_shape[num_spatial_dims]))\n\u001b[0m\u001b[1;32m 842\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 843\u001b[0m strides, dilation_rate = _get_strides_and_dilation_rate(\n", - "\u001b[0;31mValueError\u001b[0m: number of input channels does not match corresponding dimension of filter, 120 != 3" - ] - } - ], - "source": [ - "def mySegNet(input_shape):\n", - " base_model = MobileNet(input_shape=(224,224,3), include_top=False)\n", - " x = base_model.output\n", - " x = GlobalAveragePooling2D()(x)\n", - " cnn_model = Model(inputs=base_model.input, outputs=x)\n", - " \n", - " model = Sequential();\n", - " model.add(InputLayer(input_shape=input_shape))\n", - " #model.add(TimeDistributed(cnn_model, input_shape=input_shape))\n", - " #model.add(TimeDistributed(Flatten()))\n", - " model.add(cnn_model)\n", - " model.add(Flatten())\n", - " \n", - " model.add(LSTM(5, return_sequences=True))\n", - " model.add(Dense(5, activation='softmax', input_shape=input_shape))\n", - " model.compile(optimizer='adam', loss='mean_squared_error')\n", - " print(model.summary())\n", - " return model \n", - "mySegNet(input_shape)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "_________________________________________________________________\n", - "Layer (type) Output Shape Param # \n", - "=================================================================\n", - "time_distributed_3 (TimeDist (None, 200, 1024) 3228864 \n", - "_________________________________________________________________\n", - "time_distributed_4 (TimeDist (None, 200, 1024) 0 \n", - "_________________________________________________________________\n", - "lstm_2 (LSTM) (None, 200, 5) 20600 \n", - "_________________________________________________________________\n", - "dense_2 (Dense) (None, 200, 5) 30 \n", - "=================================================================\n", - "Total params: 3,249,494\n", - "Trainable params: 3,227,606\n", - "Non-trainable params: 21,888\n", - "_________________________________________________________________\n", - "None\n", - "Epoch 1/10\n" - ] - }, - { - "ename": "ValueError", - "evalue": "Error when checking target: expected dense_2 to have shape (200, 5) but got array with shape (80, 5)", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m model.fit_generator(generator=myGenerator(),\n\u001b[1;32m 4\u001b[0m \u001b[0muse_multiprocessing\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m steps_per_epoch=3, epochs=10)\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msave\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'model1.h5'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msave_weights\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'model_weights1.h5'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 89\u001b[0m warnings.warn('Update your `' + object_name +\n\u001b[1;32m 90\u001b[0m '` call to the Keras 2 API: ' + signature, stacklevel=2)\n\u001b[0;32m---> 91\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 92\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_original_function\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 93\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/models.py\u001b[0m in \u001b[0;36mfit_generator\u001b[0;34m(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)\u001b[0m\n\u001b[1;32m 1254\u001b[0m \u001b[0muse_multiprocessing\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0muse_multiprocessing\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1255\u001b[0m \u001b[0mshuffle\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mshuffle\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1256\u001b[0;31m initial_epoch=initial_epoch)\n\u001b[0m\u001b[1;32m 1257\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1258\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0minterfaces\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlegacy_generator_methods_support\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 89\u001b[0m warnings.warn('Update your `' + object_name +\n\u001b[1;32m 90\u001b[0m '` call to the Keras 2 API: ' + signature, stacklevel=2)\n\u001b[0;32m---> 91\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 92\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_original_function\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 93\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mfit_generator\u001b[0;34m(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)\u001b[0m\n\u001b[1;32m 2175\u001b[0m outs = self.train_on_batch(x, y,\n\u001b[1;32m 2176\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2177\u001b[0;31m class_weight=class_weight)\n\u001b[0m\u001b[1;32m 2178\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2179\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mouts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mtrain_on_batch\u001b[0;34m(self, x, y, sample_weight, class_weight)\u001b[0m\n\u001b[1;32m 1841\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1842\u001b[0m \u001b[0mclass_weight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mclass_weight\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1843\u001b[0;31m check_batch_axis=True)\n\u001b[0m\u001b[1;32m 1844\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muses_learning_phase\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mK\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlearning_phase\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1845\u001b[0m \u001b[0mins\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0msample_weights\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[0;32m/usr/local/lib/python3.5/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36m_standardize_user_data\u001b[0;34m(self, x, y, sample_weight, class_weight, check_batch_axis, batch_size)\u001b[0m\n\u001b[1;32m 1428\u001b[0m \u001b[0moutput_shapes\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1429\u001b[0m \u001b[0mcheck_batch_axis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1430\u001b[0;31m exception_prefix='target')\n\u001b[0m\u001b[1;32m 1431\u001b[0m sample_weights = _standardize_sample_weights(sample_weight,\n\u001b[1;32m 1432\u001b[0m self._feed_output_names)\n", - "\u001b[0;32m/usr/local/lib/python3.5/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36m_standardize_input_data\u001b[0;34m(data, names, shapes, check_batch_axis, exception_prefix)\u001b[0m\n\u001b[1;32m 118\u001b[0m \u001b[0;34m': expected '\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mnames\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m' to have shape '\u001b[0m \u001b[0;34m+\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 119\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m' but got array with shape '\u001b[0m \u001b[0;34m+\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 120\u001b[0;31m str(data_shape))\n\u001b[0m\u001b[1;32m 121\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 122\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mValueError\u001b[0m: Error when checking target: expected dense_2 to have shape (200, 5) but got array with shape (80, 5)" - ] - } - ], - "source": [ - "model = mySegNet(input_shape)\n", - "\n", - "model.fit_generator(generator=myGenerator(),\n", - " use_multiprocessing=True,\n", - " steps_per_epoch=3, epochs=10)\n", - "model.save('model1.h5')\n", - "model.save_weights('model_weights1.h5')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "predictions shape: (6000, 30, 200)\n" - ] - } - ], - "source": [ - "input_shape=(30, height, width, 3)\n", - "model = mySegNet(input_shape)\n", - "model.load_weights('model_weights2.h5')\n", - "totalTestSamples = len(allfiles)\n", - "predictions = []\n", - "ytrue = []\n", - "for i in range(0, totalTestSamples, batchSize):\n", - " x = myTestDataGenerator()\n", - " xtest, ytest = next(x)\n", - " ytrue.append(ytest)\n", - " pred = model.predict(xtest, batch_size=batchSize)\n", - " for p in pred:\n", - " predictions.append(p)\n", - "print('predictions shape: ', np.array(predictions).shape)" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(90,)\n" - ] - } - ], - "source": [ - "tileFrames = []\n", - "for sample in ytrue[:1]:\n", - " for frames in sample:\n", - " t = []\n", - " for frame in frames:\n", - " f = []\n", - " for i, j in enumerate(frame):\n", - " if j!=0:\n", - " f.append(i+1)\n", - " tileFrames.append(f)\n", - "print(np.array(tileFrames).shape)" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(90,)\n" - ] - } - ], - "source": [ - "pTileFrames = []\n", - "for sample in predictions[:3]:\n", - " for frames in sample:\n", - " f = []\n", - " for i, j in enumerate(frames):\n", - " if j!=0:\n", - " f.append(i+1)\n", - " pTileFrames.append(f)\n", - "print(np.array(pTileFrames).shape)" - ] - }, - { - "cell_type": "code", - "execution_count": 82, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[67, 68, 69, 70, 86, 87, 88, 89, 90, 91, 106, 107, 108, 109, 110, 111, 126, 127, 128, 129, 130, 131, 146, 147, 148, 149, 150, 151, 167, 168, 169, 170]\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAADKCAYAAABDsfw/AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdH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6nX8FuDRJ5nkNQzVPv3MZ+2dtPpMaAquBF/pu72f+N/AoFfC1JI8l2dpqp1fVwTb9feD0Nj0Jr2OxvU1Cz9e1zebt07tX5ulr5P223Q+/RO8/wIlfvzP6hQlcv0lWJNkNHKb3x/AZ4G+q6tVZnvf1ntr8l4B3jKrX2fqtqul1e1Nbt59LctLMfmf0NQmftYkNgUn2nqq6ALgcuDbJ+/pnVm87byLPu53k3vrcCrwTWA8cBG4ebzs/KcnbgK8Cn6qql/vnTeL6naXfiVy/VfVaVa0H1tD77/0fjbmlec3sN8m7gBvo9f2P6e3i+XdjbHHBJjUEDgBn9d1e02pjV1UH2vVh4B56b9hD07t52vXhtvgkvI7F9jbWnqvqUPuA/Rj4Am9szo+93yQn0PuD+qWq+uNWntj1O1u/k7x+W39/A3wD+Cf0dptM/75Z//O+3lOb//eBF0fd64x+N7VdcFVVR4H/zoSt27lMagg8CqxrZwecSO/gz44x90SStyZ5+/Q0cBmwl15v00f2rwHubdM7gKvb2QGXAC/17ToYlcX2dj9wWZKVbVfBZa02EjOOmXyQ3vqd7ndLOzNkLbAOeIQRvVfaPucvAt+pqs/2zZrI9TtXv5O4fpOcluSUNv2zwAfoHcP4BvChttjMdTu9zj8E/HnbCpvrNQzVHP1+t++fgdA7ftG/bifus/a6UR6FXsyF3hH1p+jtG/z0uPtpPZ1D7+yDbwNPTPdFb3/kA8DTwNeBVfXGWQS/317D48CGZe7vTnqb+K/Q27/4saX0BnyU3kG1KeAjI+73f7R+9tD78JzRt/ynW7/7gMtH+V4B3kNvV88eYHe7XDGp63eefidu/QLvBr7VetoL/Ie+z9sjbT39EXBSq7+l3Z5q88851msYUb9/3tbtXuB/8sYZRGP/rM138WcjJKnDJnV3kCRpBAwBSeowQ0CSOswQkKQOMwQkqcMMAUnqMENAkjrs/wOXKG3g3VqEvgAAAABJRU5ErkJggg==\n", - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "from PIL import Image\n", - "import numpy as np\n", - "from matplotlib import pyplot as plt\n", - "\n", - "breadth = 3840\n", - "width = 1920\n", - "tileSize = 192\n", - "tilesInColumn = width / tileSize\n", - "for i, tiles in enumerate(tileFrames):\n", - " frame = np.zeros(width*breadth)\n", - " print(tiles)\n", - " for tileNo in tiles:\n", - " tileRowNumber = int((tileNo - 1) / tilesInColumn)\n", - " tileColumnNumber = (tileNo - 1) % tilesInColumn\n", - " firstPixel = tileRowNumber * width * tileSize + tileColumnNumber * tileSize\n", - " for rowPixel in range(0, tileSize):\n", - " for columnPixel in range(0, tileSize):\n", - " frame[int(firstPixel + rowPixel * breadth + columnPixel)] = 255\n", - " frame = frame.reshape((width, breadth))\n", - " plt.imshow(frame, interpolation='nearest')\n", - " plt.show()\n", - " break" - ] - }, - { - "cell_type": "code", - "execution_count": 83, - "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAADKCAYAAABDsfw/AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAErtJREFUeJzt3X2sXPWd3/H3p14eNk/lsQhsUkxqdgUo8YJLqJqN0tJgg1ZrUkWpXWkh2WidNCBtpFYtNKuGbovUbpdEjbpL5DQu0GZ52LAsVsXWcdio9I/yYIhjDInh8hBhx7FTyEK62TqBfPvH/C5MzL3X996ZOzPmvF/S0Zz5nt/MfOenmfu953fOmV+qCklSN/21cScgSRofi4AkdZhFQJI6zCIgSR1mEZCkDrMISFKHjbwIJFmXZE+SqSTXjvr1JUmvyyivE0iyDHgS+CCwF3gY2FhVT4wsCUnSa0a9J3ARMFVVz1TVT4DbgfUjzkGS1PzCiF9vOfB83/29wHsPb5RkE7AJ4K1vyYW//LeOHehFn9z1loEeL0lHk//HX/KTOpT5tB11EZiXqtoMbAZY857j66FtZw70f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Al3h9d37s+SY5ht4f1K9U1Z+08MT270z5TnL/tvz+AvgG8HfoDZtM/75Z/+u+llPb/teBF0ad62H5rmtDcFVVh4D/woT17WwmtQg8DKxqZwccS+/gz9Yx50SStyZ5+/Q6cCmwm15u00f2rwLuaetbgSvb2QEXAy/1DR2MykJz2wZcmuTENlRwaYuNxGHHTD5Er3+n893QzgxZCawCHmJEn5U25vxl4NtV9bm+TRPZv7PlO4n9m+TUJCe09V8EPkjvGMY3gA+3Zof37XSffxj487YXNtt7GKpZ8v1O3z8DoXf8or9vJ+679ppRHoVeyELviPqT9MYGPzPufFpOZ9M7++BbwOPTedEbj7wPeAr4OnBSvX4WwR+09/AYsGaJ87uN3i7+T+mNL358MbkBv0nvoNoU8LER5/tfWz676H15Tu9r/5mW7x7gslF+VoD30Rvq2QXsbMvlk9q/c+Q7cf0LvBv4ZstpN/Cv+r5vD7V++mPguBY/vt2fatvPPtJ7GFG+f976djfw33j9DKKxf9fmWvzZCEnqsEkdDpIkjYBFQJI6zCIgSR1mEZCkDrMISFKHWQQkqcMsApLUYf8fjxyXfqxia+oAAAAASUVORK5CYII=\n", - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "for i, tiles in enumerate(pTileFrames):\n", - " frame = np.zeros(width*breadth)\n", - " for tileNo in tiles:\n", - " tileRowNumber = int((tileNo - 1) / tilesInColumn)\n", - " tileColumnNumber = (tileNo - 1) % tilesInColumn\n", - " firstPixel = tileRowNumber * width * tileSize + tileColumnNumber * tileSize\n", - " for rowPixel in range(0, tileSize):\n", - " for columnPixel in range(0, tileSize):\n", - " frame[int(firstPixel + rowPixel * breadth + columnPixel)] = 255\n", - " frame = frame.reshape((width, breadth))\n", - " plt.imshow(frame, interpolation='nearest')\n", - " plt.show()\n", - " break" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "index = 28\n", - "thresh = 0.5\n", - "\n", - "temp = predictions[0][index] \n", - "temp[temp > thresh] = 1\n", - "temp[temp <= thresh] = 0\n", - "\n", - "for i, j in enumerate(ytest[0][index]):\n", - " if ytest[0][index][i] != temp[i]:\n", - " print('Index: ', i, 'Value: ', ytest[0][index][i], temp[i])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(ytest[0][index].shape)" - ] - } - ], - "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.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Model2.py b/Model2.py deleted file mode 100644 index bc8b883..0000000 --- a/Model2.py +++ /dev/null @@ -1,219 +0,0 @@ - -# coding: utf-8 - -# In[11]: - - -from __future__ import absolute_import -from __future__ import print_function -import os -import glob -import random -import numpy as np -from keras import optimizers -from keras.layers import LSTM -from keras.models import Sequential, Model -from keras.applications.vgg16 import VGG16 -from keras.layers.wrappers import TimeDistributed -from keras.applications.mobilenet import MobileNet -from keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense, GlobalAveragePooling2D -from keras.layers import Input, InputLayer -from keras.layers.core import Activation, Flatten, Reshape -from keras.layers.convolutional import Convolution2D, MaxPooling2D, UpSampling2D -from keras.layers.normalization import BatchNormalization -from keras.utils import np_utils -from keras.applications import imagenet_utils - - -# In[3]: - - -videoFiles = glob.glob('../dataset/first-set/numpys/*.npy') -mosFiles = [i for i in videoFiles if 'mos' in i] -videoFiles = [i for i in videoFiles if 'mos' not in i] - - -# In[4]: - - -def myGenerator(): - while True: - index_list = random.sample(range(1, 80), 2) - alldata_x = [] - alldata_y = [] - for i in index_list: - f = videoFiles[i] - s = f[:-4]+'_mos.npy' - a = np.load(f) - b = np.load(s) - alldata_x.append(a) - alldata_y.append(b[0]) - alldata_x = np.array(alldata_x) - #alldata_x = np.rollaxis(alldata_x, 1, 5) - #alldata_x = alldata_x.reshape((32, 30, height, width, 3)) - #alldata_x = np.swapaxes(alldata_x, 1, 4) - alldata_y = np.array(alldata_y) - yield alldata_x, alldata_y -#x = myGenerator() -#xtrain, ytrain = next(x) -#print('xtrain shape:',xtrain.shape) -#print('ytrain shape:',ytrain.shape) - -# In[5]: - - -height = 68 -width = 120 -input_shape=(200, height, width, 3) - - -# In[12]: - - -def mySegNet(input_shape): - base_model = MobileNet(input_shape=(224,224,3), include_top=False) - x = base_model.output - x = GlobalAveragePooling2D()(x) - cnn_model = Model(inputs=base_model.input, outputs=x) - - model = Sequential(); - #model.add(InputLayer(input_shape=input_shape)) - model.add(TimeDistributed(cnn_model, input_shape=input_shape)) - model.add(TimeDistributed(Flatten())) - #model.add(cnn_model) - #model.add(Flatten()) - - model.add(LSTM(50, return_sequences=False)) - model.add(Dense(5, activation='softmax')) - model.compile(optimizer='adam', loss='mean_squared_error') - print(model.summary()) - return model -#mySegNet(input_shape) - - -# In[9]: - - -model = mySegNet(input_shape) - -model.fit_generator(generator=myGenerator(), - use_multiprocessing=True, - steps_per_epoch=3, epochs=10) -model.save('model1.h5') -model.save_weights('model_weights1.h5') - - -# In[11]: - - -input_shape=(30, height, width, 3) -model = mySegNet(input_shape) -model.load_weights('model_weights2.h5') -totalTestSamples = len(allfiles) -predictions = [] -ytrue = [] -for i in range(0, totalTestSamples, batchSize): - x = myTestDataGenerator() - xtest, ytest = next(x) - ytrue.append(ytest) - pred = model.predict(xtest, batch_size=batchSize) - for p in pred: - predictions.append(p) -print('predictions shape: ', np.array(predictions).shape) - - -# In[60]: - - -tileFrames = [] -for sample in ytrue[:1]: - for frames in sample: - t = [] - for frame in frames: - f = [] - for i, j in enumerate(frame): - if j!=0: - f.append(i+1) - tileFrames.append(f) -print(np.array(tileFrames).shape) - - -# In[59]: - - -pTileFrames = [] -for sample in predictions[:3]: - for frames in sample: - f = [] - for i, j in enumerate(frames): - if j!=0: - f.append(i+1) - pTileFrames.append(f) -print(np.array(pTileFrames).shape) - - -# In[82]: - - -from PIL import Image -import numpy as np -from matplotlib import pyplot as plt - -breadth = 3840 -width = 1920 -tileSize = 192 -tilesInColumn = width / tileSize -for i, tiles in enumerate(tileFrames): - frame = np.zeros(width*breadth) - print(tiles) - for tileNo in tiles: - tileRowNumber = int((tileNo - 1) / tilesInColumn) - tileColumnNumber = (tileNo - 1) % tilesInColumn - firstPixel = tileRowNumber * width * tileSize + tileColumnNumber * tileSize - for rowPixel in range(0, tileSize): - for columnPixel in range(0, tileSize): - frame[int(firstPixel + rowPixel * breadth + columnPixel)] = 255 - frame = frame.reshape((width, breadth)) - plt.imshow(frame, interpolation='nearest') - plt.show() - break - - -# In[83]: - - -for i, tiles in enumerate(pTileFrames): - frame = np.zeros(width*breadth) - for tileNo in tiles: - tileRowNumber = int((tileNo - 1) / tilesInColumn) - tileColumnNumber = (tileNo - 1) % tilesInColumn - firstPixel = tileRowNumber * width * tileSize + tileColumnNumber * tileSize - for rowPixel in range(0, tileSize): - for columnPixel in range(0, tileSize): - frame[int(firstPixel + rowPixel * breadth + columnPixel)] = 255 - frame = frame.reshape((width, breadth)) - plt.imshow(frame, interpolation='nearest') - plt.show() - break - - -# In[ ]: - - -index = 28 -thresh = 0.5 - -temp = predictions[0][index] -temp[temp > thresh] = 1 -temp[temp <= thresh] = 0 - -for i, j in enumerate(ytest[0][index]): - if ytest[0][index][i] != temp[i]: - print('Index: ', i, 'Value: ', ytest[0][index][i], temp[i]) - - -# In[ ]: - - -print(ytest[0][index].shape) - diff --git a/README.md b/README.md deleted file mode 100644 index 4c3d2fe..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# VQA-Deep-Learning -Video Quality Assessment using Deep Learning (CNN + LSTM) diff --git a/ResNet_model.ipynb b/ResNet_model.ipynb new file mode 100644 index 0000000..e729c6f --- /dev/null +++ b/ResNet_model.ipynb @@ -0,0 +1,274 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import tensorflow as tf" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "_BATCH_NORM_DECAY = 0.997\n", + "_BATCH_NORM_EPSILON = 1e-5\n", + "DEFAULT_VERSION = 2\n", + "DEFAULT_DTYPE = tf.float32\n", + "CASTABLE_TYPES = (tf.float16,)\n", + "ALLOWED_TYPES = (DEFAULT_DTYPE,) + CASTABLE_TYPES" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def batch_normalize(inputs, is_training, dFormat):\n", + " return tf.layers.batch_normalization(inputs, axis=1 if dFormat=='channels_first' else 3,\n", + " momentum=_BATCH_NORM_DECAY, epsilon=_BATCH_NORM_EPSILON,\n", + " training=is_training, fused=True)\n", + "\n", + "def fixed_pad(inputs, ksize, dFormat):\n", + " pad_total = ksize - 1\n", + " pad_left = pad_total//2\n", + " pad_right = pad_total - pad_left\n", + "\n", + " if dFormat == 'channels_first':\n", + " return tf.pad(inputs, [[0,0],[0,0],[pad_left,pad_right],[pad_left,pad_right]])\n", + " else:\n", + " return tf.pad(inputs, [[0,0],[pad_left,pad_right],[pad_left,pad_right],[0,0]])\n", + "\n", + "def conv_fixed_pad(inputs, n_filters, k_size, strides, dFormat): \n", + " if strides > 1:\n", + " inputs = fixed_pad(inputs, ksize, dFormat)\n", + " \n", + " return tf.layers.conv2d(inputs=inputs, filters=n_filters, kernel_size=k_size, \n", + " strides=[strides]*2, padding='SAME' if strides==1 else 'VALID',\n", + " data_format=dFormat)\n", + "\n", + "def conv_bn(inputs, n_filters, k_size, strides, is_training, dFormat, activation):\n", + " inputs = conv_fixed_pad(inputs, n_filters, k_size, strides, dFormat)\n", + " inputs = batch_normalize(inputs, is_training, dFormat)\n", + " return tf.nn.relu(inputs) if activation == 'RELU' else inputs\n", + "\n", + "conv_bn = tf.contrib.framework.add_arg_scope(conv_bn)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def _res_block_v1(inputs, n_filters, strides, is_training, projection_shortcut, dFormat):\n", + " shortcut = inputs\n", + " \n", + " if projection_shortcut is not None:\n", + " shortcut = projection_shortcut(shortcut)\n", + " shortcut = batch_normalize(inputs=shortcut, is_training=is_training, dFormat=dFormat)\n", + " \n", + " with tf.contrib.framework.arg_scope([conv_bn], n_filters=n_filters, k_size=3, \n", + " is_training=is_training, dFormat=dFormat):\n", + " inputs = conv_bn(inputs=inputs, strides=strides, activation='RELU')\n", + " inputs = conv_bn(inputs=inputs, strides=1, activation=None)\n", + " \n", + " return tf.nn.relu(inputs + shortcut)\n", + "\n", + "def _res_block_v2(inputs, n_filters, strides, is_training, projection_shortcut, dFormat):\n", + " shortcut = inputs\n", + " inputs = batch_normalize(inputs=inputs, is_training=is_training, dFormat=dFormat)\n", + " inputs = tf.nn.relu(inputs)\n", + " \n", + " if projection_shortcut is not None:\n", + " shortcut = projection_shortcut(inputs)\n", + "\n", + " inputs = conv_bn(inputs=inputs, n_filters=n_filters, k_size=3, strides=strides, \n", + " is_training=is_training, dFormat=dFormat, activation='RELU')\n", + " inputs = conv_fixed_pad(inputs=inputs, n_filters=n_filters, k_size=3, strides=1, dFormat=dFormat)\n", + " \n", + " return inputs + shortcut\n", + "\n", + "def _bottleneck_res_block_v1(inputs, n_filters, strides, is_training, projection_shortcut, dFormat):\n", + " shortcut = inputs\n", + " \n", + " if projection_shortcut is not None:\n", + " shortcut = projection_shortcut(shortcut)\n", + " shortcut = batch_normalize(inputs=shortcut, is_training=is_training, dFormat=dFormat)\n", + " \n", + " with tf.contrib.framework.arg_scope([conv_bn], n_filters=n_filters, is_training=is_training, \n", + " dFormat=dFormat, activation='RELU'):\n", + " inputs = conv_bn(inputs=inputs, k_size=1, strides=1)\n", + " inputs = conv_bn(inputs=inputs, k_size=3, strides=strides)\n", + " \n", + " inputs = conv_bn(inputs=inputs, n_filters=4*n_filters, k_size=1, strides=1, \n", + " is_training=is_training, dFormat=dFormat, activation=None)\n", + " \n", + " return tf.nn.relu(inputs + shortcut)\n", + "\n", + "def _bottleneck_res_block_v2(inputs, n_filters, strides, is_training, projection_shortcut, dFormat):\n", + " shortcut = inputs\n", + " inputs = batch_normalize(inputs=inputs, is_training=is_training, dFormat=dFormat)\n", + " inputs = tf.nn.relu(inputs)\n", + " \n", + " if projection_shortcut is not None:\n", + " shortcut = projection_shortcut(inputs)\n", + " \n", + " with tf.contrib.framework.arg_scope([conv_bn], n_filters=n_filters, is_training=is_training, \n", + " dFormat=dFormat, activation='RELU'):\n", + " inputs = conv_bn(inputs=inputs, k_size=1, strides=1)\n", + " inputs = conv_bn(inputs=inputs, k_size=3, strides=strides)\n", + " \n", + " inputs = conv_fixed_pad(inputs=inputs, n_filters=4*n_filters, k_size=1, strides=1, dFormat=dFormat)\n", + " \n", + " return inputs + shortcut" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def block_layer(inputs, n_blocks, block_func, bottleneck, \n", + " n_filters, strides, is_training, dFormat, output_name):\n", + " # each block chain has a fixed n_filters\n", + " \n", + " n_filters_out = 4*n_filters if bottleneck else n_filters\n", + " \n", + " def projection_shortcut(inputs):\n", + " return conv_fixed_pad(inputs=inputs, n_filters=filters_out, k_size=1, strides=strides, dFormat=dFormat) \n", + " \n", + " # the input is projected to have depth=n_filters in the first block\n", + " inputs = block_func(inputs, n_filters, strides, is_training, projection_shortcut, dFormat)\n", + " \n", + " for _ in n_blocks:\n", + " inputs = block_func(inputs, n_filters, 1, is_training, None, dFormat)\n", + " \n", + " return tf.identity(inputs, output_name)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "class ResNet_Model():\n", + " def __init__(self, resnet_size, final_size, n_classes,\n", + " n_filters_initial, block_sizes, block_strides, bottleneck,\n", + " first_conv_size, first_conv_strides, first_pool_size, first_pool_strides,\n", + " version=DEFAULT_VERSION, data_format=None, dtype=DEFAULT_DTYPE):\n", + " \n", + " self.resnet_size = resnet_size\n", + " self.final_size = final_size\n", + " self.n_classes = n_classes\n", + " self.n_filters_initial = n_filters_initial\n", + " self.block_sizes = block_sizes\n", + " self.block_strides = block_strides\n", + " self.bottleneck = bottleneck \n", + " self.first_conv_size = first_conv_size\n", + " self.first_conv_strides = first_conv_strides\n", + " self.first_pool_size = first_pool_size\n", + " self.first_pool_strides = first_pool_strides\n", + " \n", + " if version not in {1, 2}:\n", + " raise ValueError('Resnet version should be 1 or 2.')\n", + " self.version = version\n", + " \n", + " if data_format not in {'channes_first', 'channels_last'}:\n", + " raise ValueError('Data format should be \"channel_first\" or \"channel_last\"')\n", + " self.data_format = data_format\n", + " \n", + " if dtype not in ALLOWED_TYPES:\n", + " raise ValueError('dtype must be one of: {}'.format(ALLOWED_TYPES))\n", + " self.dtype = dtype\n", + " \n", + " if bottleneck == True:\n", + " if version == 1:\n", + " self.block_func = _bottleneck_res_block_v1\n", + " else:\n", + " self.block_func = _bottleneck_res_block_v2\n", + " else:\n", + " if version == 1:\n", + " self.block_func = _res_block_v1\n", + " else:\n", + " self.block_func = _res_block_v2\n", + " \n", + " def _custom_dtype_getter(self, getter, name, shape=None, dtype=DEFAULT_DTYPE, *args, **kwargs):\n", + " if dtype in CASTABLE_TYPES:\n", + " var = getter(name, shape, tf.float32, *args, **kwargs)\n", + " return tf.cast(var, dtype=dtype, name=name + '_cast')\n", + " return getter(name, shape, dtype, *args, **kwargs)\n", + " \n", + " def _model_variable_scope(self):\n", + " return tf.variable_scope('resnet_model', custom_getter=self._custom_dtype_getter)\n", + " \n", + " def __call__(inputs, is_training):\n", + " with self._model_variabel_scope(): \n", + " if self.data_format == 'channels_first':\n", + " inputs = tf.transpose(inputs, [0,3,1,2])\n", + "\n", + " inputs = conv_fixed_pad(inputs=inputs, n_filters=self.n_filters_initial, k_size=self.first_conv_size, \n", + " strides=self.first_conv_strides, dFormat=self.data_format)\n", + "\n", + " if self.first_pool_size:\n", + " inputs = tf.layers.max_pooling2d(inputs=inputs, pool_size=self.first_pool_size,\n", + " strides=self.first_pool_strides, padding='SAME',\n", + " data_format=self.data_format)\n", + " inputs = tf.identity(inputs, 'initial_maxpool')\n", + "\n", + " for i, n_blocks in enumerate(self.block_sizes):\n", + " n_filters = self.n_filters * (2**i)\n", + " inputs = block_layer(inputs=inputs, n_blocks=n_blocks, block_func=self.block_func, \n", + " bottleneck=self.bottleneck, n_filters=n_filters, \n", + " strides=self.block_strides[i], is_training=is_training, \n", + " dFormat=self.data_format, output_name='block_layer_{}'.format(i))\n", + "\n", + " inputs = tf.nn.relu(batch_normalize(inputs, is_training, self.data_format))\n", + "\n", + " axes = [2, 3] if self.data_format == 'channels_first' else [1, 2]\n", + " inputs = tf.reduce_mean(inputs, axes, keepdims=True)\n", + " inputs = tf.identity(inputs, 'final_reduce_mean')\n", + "\n", + " inputs = tf.reshape(inputs, [-1, self.final_size])\n", + " inputs = tf.layers.dense(inputs=inputs, units=self.n_classes)\n", + " inputs = tf.identity(inputs, 'final_dense')\n", + " return inputs " + ] + }, + { + "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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/ResNet_run.ipynb b/ResNet_run.ipynb new file mode 100644 index 0000000..be5b83f --- /dev/null +++ b/ResNet_run.ipynb @@ -0,0 +1,352 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def process_record_dataset(dataset, is_training, batch_size, shuffle_buffer, parse_record_fn, num_epochs):\n", + " # make the dataset prefetchable for parallellism\n", + " dataset = dataset.prefetch(buffer_size=batch_size)\n", + " \n", + " # shuffle dataset\n", + " if is_training:\n", + " dataset = dataset.shuffle(buffer_size=shuffle_buffer)\n", + " \n", + " # repeat shuffled dataset for multi-epoch training\n", + " dataset = dataset.repeat(num_epochs)\n", + "\n", + " # Parse the raw records into images and labels and batch them\n", + " dataset = dataset.map(lambda x : parse_record_fn(x, is_training), num_parallel_calls=1) \n", + " dataset = dataset.batch(batch_size)\n", + " \n", + " # prefetch one batch at a time\n", + " dataset.prefetch(1)\n", + "\n", + " return dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def learning_schedule(batch_size, batch_denom, num_images, boundary_epochs, decay_rates):\n", + " initial_learning_rate = 0.1 * batch_size / batch_denom\n", + " batches_per_epoch = num_images / batch_size\n", + "\n", + " # Multiply the learning rate by 0.1 at 100, 150, and 200 epochs.\n", + " boundaries = [int(batches_per_epoch * epoch) for epoch in boundary_epochs]\n", + " vals = [initial_learning_rate * decay for decay in decay_rates]\n", + "\n", + " # a global step means running an optimization op on a batch\n", + " def learning_rate_fn(global_step):\n", + " global_step = tf.cast(global_step, tf.int32)\n", + " return tf.train.piecewise_constant(global_step, boundaries, vals)\n", + "\n", + " return learning_rate_fn" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def resnet_model_fn(features, labels, mode, model_class,\n", + " resnet_size, weight_decay, learning_rate_fn, momentum,\n", + " data_format, resnet_version, loss_scale,\n", + " loss_filter_fn=None, dtype=resnet_model.DEFAULT_DTYPE):\n", + " \"\"\"Shared functionality for different resnet model_fns.\n", + " Initializes the ResnetModel representing the model layers\n", + " and uses that model to build the necessary EstimatorSpecs for\n", + " the `mode` in question. For training, this means building losses,\n", + " the optimizer, and the train op that get passed into the EstimatorSpec.\n", + " For evaluation and prediction, the EstimatorSpec is returned without\n", + " a train op, but with the necessary parameters for the given mode.\n", + " Args:\n", + " features: tensor representing input images\n", + " labels: tensor representing class labels for all input images\n", + " mode: current estimator mode; should be one of\n", + " `tf.estimator.ModeKeys.TRAIN`, `EVALUATE`, `PREDICT`\n", + " model_class: a class representing a TensorFlow model that has a __call__\n", + " function. We assume here that this is a subclass of ResnetModel.\n", + " resnet_size: A single integer for the size of the ResNet model.\n", + " weight_decay: weight decay loss rate used to regularize learned variables.\n", + " learning_rate_fn: function that returns the current learning rate given\n", + " the current global_step\n", + " momentum: momentum term used for optimization\n", + " data_format: Input format ('channels_last', 'channels_first', or None).\n", + " If set to None, the format is dependent on whether a GPU is available.\n", + " resnet_version: Integer representing which version of the ResNet network to\n", + " use. See README for details. Valid values: [1, 2]\n", + " loss_scale: The factor to scale the loss for numerical stability. A detailed\n", + " summary is present in the arg parser help text.\n", + " loss_filter_fn: function that takes a string variable name and returns\n", + " True if the var should be included in loss calculation, and False\n", + " otherwise. If None, batch_normalization variables will be excluded\n", + " from the loss.\n", + " dtype: the TensorFlow dtype to use for calculations.\n", + " Returns:\n", + " EstimatorSpec parameterized according to the input params and the\n", + " current mode.\n", + " \"\"\"\n", + "\n", + " # Generate a summary node for the images\n", + " tf.summary.image('images', features, max_outputs=6)\n", + "\n", + " features = tf.cast(features, dtype)\n", + "\n", + " model = model_class(resnet_size, data_format, resnet_version=resnet_version, dtype=dtype)\n", + "\n", + " logits = model(features, mode == tf.estimator.ModeKeys.TRAIN)\n", + "\n", + " # This acts as a no-op if the logits are already in fp32 (provided logits are\n", + " # not a SparseTensor). If dtype is is low precision, logits must be cast to\n", + " # fp32 for numerical stability.\n", + " logits = tf.cast(logits, tf.float32)\n", + "\n", + " predictions = {\n", + " 'classes': tf.argmax(logits, axis=1),\n", + " 'probabilities': tf.nn.softmax(logits, name='softmax_tensor')\n", + " }\n", + "\n", + " if mode == tf.estimator.ModeKeys.PREDICT:\n", + " # Return the predictions and the specification for serving a SavedModel\n", + " return tf.estimator.EstimatorSpec(\n", + " mode=mode,\n", + " predictions=predictions,\n", + " export_outputs={\n", + " 'predict': tf.estimator.export.PredictOutput(predictions)\n", + " })\n", + "\n", + " # Calculate loss, which includes softmax cross entropy and L2 regularization.\n", + " # cross entropy part\n", + " cross_entropy = tf.losses.softmax_cross_entropy(logits=logits, onehot_labels=labels)\n", + "\n", + " # Create a tensor named cross_entropy for logging purposes.\n", + " tf.identity(cross_entropy, name='cross_entropy')\n", + " tf.summary.scalar('cross_entropy', cross_entropy)\n", + " \n", + " # L2 regularization part\n", + " def exclude_batch_norm(name):\n", + " return 'batch_normalization' not in name\n", + " \n", + " loss_filter_fn = loss_filter_fn or exclude_batch_norm\n", + "\n", + " # Add weight decay to the loss.\n", + " l2_loss = weight_decay * tf.add_n(\n", + " [tf.nn.l2_loss(tf.cast(v, tf.float32)) for v in tf.trainable_variables()\n", + " if loss_filter_fn(v.name)])\n", + " \n", + " tf.summary.scalar('l2_loss', l2_loss)\n", + " loss = cross_entropy + l2_loss\n", + "\n", + " if mode == tf.estimator.ModeKeys.TRAIN:\n", + " global_step = tf.train.get_or_create_global_step()\n", + "\n", + " learning_rate = learning_rate_fn(global_step)\n", + "\n", + " # Create a tensor named learning_rate for logging purposes\n", + " tf.identity(learning_rate, name='learning_rate')\n", + " tf.summary.scalar('learning_rate', learning_rate)\n", + "\n", + " optimizer = tf.train.MomentumOptimizer(learning_rate=learning_rate, momentum=momentum)\n", + "\n", + " if loss_scale != 1:\n", + " # When computing fp16 gradients, often intermediate tensor values are\n", + " # so small, they underflow to 0. To avoid this, we multiply the loss by\n", + " # loss_scale to make these tensor values loss_scale times bigger.\n", + " scaled_grad_vars = optimizer.compute_gradients(loss * loss_scale)\n", + "\n", + " # Once the gradient computation is complete we can scale the gradients\n", + " # back to the correct scale before passing them to the optimizer.\n", + " unscaled_grad_vars = [(grad / loss_scale, var) for grad, var in scaled_grad_vars]\n", + " minimize_op = optimizer.apply_gradients(unscaled_grad_vars, global_step)\n", + " else:\n", + " minimize_op = optimizer.minimize(loss, global_step)\n", + " \n", + " update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)\n", + " train_op = tf.group(minimize_op, update_ops)\n", + " else:\n", + " train_op = None\n", + "\n", + " \n", + " if not tf.contrib.distribute.has_distribution_strategy():\n", + " accuracy = tf.metrics.accuracy(tf.argmax(labels, axis=1), predictions['classes'])\n", + " else:\n", + " # Metrics are currently not compatible with distribution strategies during\n", + " # training. This does not affect the overall performance of the model.\n", + " accuracy = (tf.no_op(), tf.constant(0))\n", + "\n", + " metrics = {'accuracy': accuracy}\n", + "\n", + " # Create a tensor named train_accuracy for logging purposes\n", + " tf.identity(accuracy[1], name='train_accuracy')\n", + " tf.summary.scalar('train_accuracy', accuracy[1])\n", + "\n", + " return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions, loss=loss, \n", + " train_op=train_op, eval_metric_ops=metrics)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def resnet_main(flags_obj, model_function, input_function, dataset_name, shape=None):\n", + " \"\"\"Shared main loop for ResNet Models.\n", + " Args:\n", + " flags_obj: An object containing parsed flags. See define_resnet_flags()\n", + " for details.\n", + " model_function: the function that instantiates the Model and builds the\n", + " ops for train/eval. This will be passed directly into the estimator.\n", + " input_function: the function that processes the dataset and returns a\n", + " dataset that the estimator can train on. This will be wrapped with\n", + " all the relevant flags for running and passed to estimator.\n", + " dataset_name: the name of the dataset for training and evaluation. This is\n", + " used for logging purpose.\n", + " shape: list of ints representing the shape of the images used for training.\n", + " This is only used if flags_obj.export_dir is passed.\n", + " \"\"\"\n", + "\n", + " # Using the Winograd non-fused algorithms provides a small performance boost.\n", + " os.environ['TF_ENABLE_WINOGRAD_NONFUSED'] = '1'\n", + "\n", + " # Create session config based on values of inter_op_parallelism_threads and\n", + " # intra_op_parallelism_threads. Note that we default to having\n", + " # allow_soft_placement = True, which is required for multi-GPU and not\n", + " # harmful for other modes.\n", + " session_config = tf.ConfigProto(\n", + " inter_op_parallelism_threads=flags_obj.inter_op_parallelism_threads,\n", + " intra_op_parallelism_threads=flags_obj.intra_op_parallelism_threads,\n", + " allow_soft_placement=True)\n", + "\n", + " if flags_core.get_num_gpus(flags_obj) == 0:\n", + " distribution = tf.contrib.distribute.OneDeviceStrategy('device:CPU:0')\n", + " elif flags_core.get_num_gpus(flags_obj) == 1:\n", + " distribution = tf.contrib.distribute.OneDeviceStrategy('device:GPU:0')\n", + " else:\n", + " distribution = tf.contrib.distribute.MirroredStrategy(num_gpus=flags_core.get_num_gpus(flags_obj))\n", + "\n", + " run_config = tf.estimator.RunConfig(train_distribute=distribution, session_config=session_config)\n", + "\n", + " classifier = tf.estimator.Estimator(model_fn=model_function, model_dir=flags_obj.model_dir, \n", + " config=run_config,\n", + " params={\n", + " 'resnet_size': int(flags_obj.resnet_size),\n", + " 'data_format': flags_obj.data_format,\n", + " 'batch_size': flags_obj.batch_size,\n", + " 'resnet_version': int(flags_obj.resnet_version),\n", + " 'loss_scale': flags_core.get_loss_scale(flags_obj),\n", + " 'dtype': flags_core.get_tf_dtype(flags_obj)\n", + " })\n", + "\n", + " run_params = {\n", + " 'batch_size': flags_obj.batch_size,\n", + " 'dtype': flags_core.get_tf_dtype(flags_obj),\n", + " 'resnet_size': flags_obj.resnet_size,\n", + " 'resnet_version': flags_obj.resnet_version,\n", + " 'synthetic_data': flags_obj.use_synthetic_data,\n", + " 'train_epochs': flags_obj.train_epochs,\n", + " }\n", + " \n", + " benchmark_logger = logger.config_benchmark_logger(flags_obj.benchmark_log_dir)\n", + " benchmark_logger.log_run_info('resnet', dataset_name, run_params)\n", + "\n", + " train_hooks = hooks_helper.get_train_hooks(flags_obj.hooks,batch_size=flags_obj.batch_size,\n", + " benchmark_log_dir=flags_obj.benchmark_log_dir)\n", + "\n", + " def input_fn_train():\n", + " return input_function(is_training=True, data_dir=flags_obj.data_dir,\n", + " batch_size=per_device_batch_size(flags_obj.batch_size, \n", + " flags_core.get_num_gpus(flags_obj)),\n", + " num_epochs=flags_obj.epochs_between_evals)\n", + "\n", + " def input_fn_eval():\n", + " return input_function(is_training=False, data_dir=flags_obj.data_dir,\n", + " batch_size=per_device_batch_size(flags_obj.batch_size, \n", + " flags_core.get_num_gpus(flags_obj)),\n", + " num_epochs=1)\n", + "\n", + " total_training_cycle = (flags_obj.train_epochs // flags_obj.epochs_between_evals)\n", + " \n", + " for cycle_index in range(total_training_cycle):\n", + " tf.logging.info('Starting a training cycle: %d/%d', cycle_index, total_training_cycle)\n", + "\n", + " classifier.train(input_fn=input_fn_train, hooks=train_hooks,\n", + " max_steps=flags_obj.max_train_steps)\n", + "\n", + " tf.logging.info('Starting to evaluate.')\n", + "\n", + " # flags_obj.max_train_steps is generally associated with testing and\n", + " # profiling. As a result it is frequently called with synthetic data, which\n", + " # will iterate forever. Passing steps=flags_obj.max_train_steps allows the\n", + " # eval (which is generally unimportant in those circumstances) to terminate.\n", + " # Note that eval will run for max_train_steps each loop, regardless of the\n", + " # global_step count.\n", + " eval_results = classifier.evaluate(input_fn=input_fn_eval,\n", + " steps=flags_obj.max_train_steps)\n", + "\n", + " benchmark_logger.log_evaluation_result(eval_results)\n", + "\n", + " if model_helpers.past_stop_threshold(flags_obj.stop_threshold, eval_results['accuracy']):\n", + " break\n", + "\n", + " if flags_obj.export_dir is not None:\n", + " # Exports a saved model for the given classifier.\n", + " input_receiver_fn = export.build_tensor_serving_input_receiver_fn(shape, batch_size=flags_obj.batch_size)\n", + " classifier.export_savedmodel(flags_obj.export_dir, input_receiver_fn)\n", + "\n", + "\n", + "def define_resnet_flags(resnet_size_choices=None):\n", + " \"\"\"Add flags and validators for ResNet.\"\"\"\n", + " flags_core.define_base()\n", + " flags_core.define_performance(num_parallel_calls=False)\n", + " flags_core.define_image()\n", + " flags_core.define_benchmark()\n", + " flags.adopt_module_key_flags(flags_core)\n", + "\n", + " flags.DEFINE_enum(\n", + " name='resnet_version', short_name='rv', default='2',\n", + " enum_values=['1', '2'],\n", + " help=flags_core.help_wrap(\n", + " 'Version of ResNet. (1 or 2) See README.md for details.'))\n", + "\n", + "\n", + " choice_kwargs = dict(\n", + " name='resnet_size', short_name='rs', default='50',\n", + " help=flags_core.help_wrap('The size of the ResNet model to use.'))\n", + "\n", + " if resnet_size_choices is None:\n", + " flags.DEFINE_string(**choice_kwargs)\n", + " else:\n", + " flags.DEFINE_enum(enum_values=resnet_size_choices, **choice_kwargs)" + ] + } + ], + "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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/VQA.ipynb b/VQA.ipynb new file mode 100644 index 0000000..391bd23 --- /dev/null +++ b/VQA.ipynb @@ -0,0 +1,285 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import tensorflow as tf\n", + "import numpy as np\n", + "import cv2\n", + "import pickle\n", + "import matplotlib.pyplot as plt\n", + "from datetime import datetime" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "now = datetime.utcnow().strftime(\"%Y%m%d%H%M%S\")\n", + "root_logdir = \"tf_logs\"\n", + "logdir = \"{}/run-{}/\".format(root_logdir, now)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# a list that specifies convolution-pooling architecture\n", + "# list index indicate layer position in stack; \n", + "# a pooling layer is represented by a tuple: (pooling type, kernel_size, strides)\n", + "# a convolution layer is represented by a typle: (filter_height, filter_width, depth)\n", + "layers = [(5, 5, 6),\n", + " ('MAX', (1,2,2,1), (1,2,2,1)),\n", + " (5, 5, 16),\n", + " ('MAX', (1,2,2,1), (1,2,2,1)),\n", + " (5, 5, 60),\n", + " ('MAX', (1,2,2,1), (1,2,2,1))]\n", + "\n", + "ResNet_block_layers = [(1, 1, 128, 'relu'),\n", + " (3, 3, 128, 'relu'),\n", + " (1, 1, 512, None)]\n", + "\n", + "inception_depths = [64, (96, 128), (16, 32), 32]\n", + "\n", + "def conv_pool(x, layers):\n", + " out = x\n", + " n_conv, n_pool = 0, 0\n", + " prev_depth = int(x.shape[3])\n", + " for l in layers:\n", + " if type(l[0]) == int:\n", + " n_conv += 1\n", + " with tf.variable_scope('conv_{}'.format(n_conv), reuse = tf.AUTO_REUSE):\n", + " w = tf.get_variable('filter', initializer=tf.truncated_normal((l[0],l[1],prev_depth,l[2]),0,0.1))\n", + " b = tf.get_variable('bias', initializer=tf.zeros(l[2]))\n", + " out = tf.nn.relu(tf.nn.conv2d(out, w, strides=(1,1,1,1), padding='SAME') + b)\n", + " prev_depth = l[2]\n", + " else:\n", + " n_pool += 1\n", + " out = tf.nn.pool(out, pooling_type=l[0], window_shape=l[1], strides=l[2],\n", + " padding='SAME', name='pool_{}'.format(n_pool))\n", + " return out\n", + "\n", + "def ResNet_block(x, layers, name):\n", + " out = x\n", + " n = 0\n", + " if int(x.shape[3]) != layers[-1][2]:\n", + " print('Input to ResNet block must have the same shape as output of convolution layers')\n", + " return\n", + " prev_depth = int(x.shape[3])\n", + " with tf.variable_scope(name, reuse = tf.AUTO_REUSE):\n", + " for l in layers:\n", + " n += 1\n", + " with tf.variable_scope('conv_'.format(n), reuse = tf.AUTO_REUSE):\n", + " w = tf.get_variable('filter', initializer=tf.truncated_normal((l[0],l[1],prev_depth,l[2]),0,0.1))\n", + " b = tf.get_variable('bias', initializer=tf.zeros(l[2]))\n", + " out = tf.nn.conv2d(out, w, strides=(1,1,1,1), padding='SAME') + b\n", + " if l[3] == 'relu':\n", + " out = tf.nn.relu(out)\n", + " prev_depth = l[2]\n", + " return tf.nn.relu(out + x)\n", + "\n", + "def Inception_module(x, depths):\n", + " layers = [[(1, 1, depths[0])]\n", + " [(1, 1, depths[1][0]), (3, 3, depths[1][1])],\n", + " [(1, 1, depths[2][0]), (5, 5, depths[2][1])], \n", + " [('MAX', (1,3,3,1), (1,1,1,1)), (1, 1, depths[3])]]\n", + " out = []\n", + " for i in range(4):\n", + " with tf.variable_scope('component_{}'.format(i+1), reuse = tf.AUTO_REUSE):\n", + " out.append(conv_pool(x, layers[i])) \n", + " return tf.concat(out, axis=-1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# get all frames from video downscaled by a factor\\n\"\n", + "# return an ndarray of shape (n_frames, height, width, channels)\n", + "\n", + "def get_frames(path, n_frames, downscale_factor):\n", + " cap = cv2.VideoCapture(path)\n", + " seq = []\n", + " count = 0\n", + " while True:\n", + " success,frame = cap.read()\n", + " if count == n_frames or not success:\n", + " break\n", + " # downscale frame\n", + " width = int(frame.shape[1] / downscale_factor)\n", + " height = int(frame.shape[0] / downscale_factor)\n", + " resized = cv2.resize(frame, (width, height), interpolation = cv2.INTER_AREA)\n", + " if resized.shape[0] > resized.shape[1]:\n", + " resized = np.transpose(resized, (1,0,2))\n", + " seq.append(resized)\n", + " count += 1\n", + " return np.stack(seq)\n", + "\n", + "# mini-batch generator\n", + "def next_batch(path, labels, n_batches, batch_size, n_frames, downscale_factor):\n", + " perm = np.random.permutation(300)\n", + " for i in range(n_batches):\n", + " x_batch, y_batch = [], []\n", + " for j in range(0, batch_size):\n", + " all_frames = get_frames(path.format(perm[i*batch_size+j]+1), n_frames, downscale_factor)\n", + " #print(all_frames.shape)\n", + " x_batch.append(all_frames)\n", + " y_batch.append(labels[perm[i*batch_size+j]])\n", + " x_batch = np.stack(x_batch)\n", + " yield x_batch, y_batch\n", + " \n", + "# generate feature maps for each video in mini-batch\n", + "# x has shape (batch_size, n_frames, height, width, channels)\n", + "def get_feature_maps(x):\n", + " instances = []\n", + " for i in range(x.shape[0]):\n", + " instances.append(tf.contrib.layers.flatten(conv_pool(x[i, :, :, :, :], layers)))\n", + " return tf.stack(instances, axis=0)\n", + "\n", + "def score_to_label(scores, thresh_1, thresh_2):\n", + " for x in np.nditer(scores, op_flags=['readwrite']):\n", + " if x < thresh_1:\n", + " x[...] = 0\n", + " elif x < thresh_2:\n", + " x[...] = 1\n", + " else:\n", + " x[...] = 2\n", + " return scores" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "path = '/home/mallesh/video-qoe-labeling_1/VQA-Deep-Learning/data/set1-4/trace_{}.mp4'\n", + "height, width, n_channels = 1080, 1920, 3\n", + "downscale_factor = 8\n", + "n_frames = 100\n", + "n_classes = 3\n", + "n_batches, batch_size = 30, 10\n", + "n_hidden = 100 # number of hidden cells in LSTM\\n\"\n", + "X = tf.placeholder(tf.float32, shape=\n", + " (batch_size, n_frames, int(height/downscale_factor), int(width/downscale_factor), n_channels))\n", + "y = tf.placeholder(tf.int32, shape=(batch_size,))\n", + "labels = score_to_label(np.loadtxt('/home/mallesh/video-qoe-labeling_1/VQA-Deep-Learning/data/set1-4.txt'), 2, 3.8)\n", + "X_features = get_feature_maps(X)\n", + "print(X_features.shape)\n", + "cell = tf.contrib.rnn.BasicLSTMCell(n_hidden)\n", + "output, _ = tf.nn.dynamic_rnn(cell, X_features, initial_state = cell.zero_state(batch_size, dtype=tf.float32))\n", + "with tf.variable_scope('out', reuse = tf.AUTO_REUSE):\n", + " w = tf.get_variable('weight', shape=(n_hidden, n_classes))\n", + " b = tf.get_variable('bias', initializer=tf.zeros(n_classes))\n", + " pred = tf.matmul(output[:,-1,:], w) + b\n", + " loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=y))\n", + " optimizer = tf.train.AdamOptimizer()\n", + " training_op = optimizer.minimize(loss)\n", + " loss_summary = tf.summary.scalar('loss', loss)\n", + " file_writer = tf.summary.FileWriter(logdir, tf.get_default_graph())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "saver = tf.train.Saver()\n", + "with tf.Session() as sess:\n", + " sess.run(tf.global_variables_initializer())\n", + " batch_num = 0\n", + " for X_batch, y_batch in next_batch(path, labels, n_batches, batch_size, n_frames, downscale_factor):\n", + " print(X_batch.shape)\n", + " batch_num += 1\n", + " summary_str = loss_summary.eval(feed_dict={X: X_batch, y: y_batch})\n", + " file_writer.add_summary(summary_str, batch_num)\n", + " sess.run(training_op, feed_dict={X: X_batch, y: y_batch})\n", + " saver.save(sess, '/tmp/after_batch_{}.ckpt'.format(batch_num))\n", + " print(pred.eval(feed_dict={X: X_batch, y: y_batch}))\n", + " print(loss.eval(feed_dict={X: X_batch, y: y_batch}))\n", + " saver.save(sess, '/tmp/final.ckpt')\n", + " file_writer.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def unpickle(file): \n", + " with open(file, 'rb') as fo:\n", + " dic = pickle.load(fo, encoding='bytes')\n", + " return dic" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "unsupported operand type(s) for +: 'Tensor' and 'float'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mSession\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0msess\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlayers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbatch_normalization\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0meval\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[0;32m~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/layers/normalization.py\u001b[0m in \u001b[0;36mbatch_normalization\u001b[0;34m(inputs, axis, momentum, epsilon, center, scale, beta_initializer, gamma_initializer, moving_mean_initializer, moving_variance_initializer, beta_regularizer, gamma_regularizer, beta_constraint, gamma_constraint, training, trainable, name, reuse, renorm, renorm_clipping, renorm_momentum, fused, virtual_batch_size, adjustment)\u001b[0m\n\u001b[1;32m 778\u001b[0m \u001b[0m_reuse\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mreuse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 779\u001b[0m _scope=name)\n\u001b[0;32m--> 780\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mlayer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtraining\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtraining\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 781\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 782\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/layers/base.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self, inputs, *args, **kwargs)\u001b[0m\n\u001b[1;32m 826\u001b[0m \u001b[0mOutput\u001b[0m \u001b[0mtensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 827\u001b[0m \"\"\"\n\u001b[0;32m--> 828\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__call__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 829\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 830\u001b[0m def _add_inbound_node(self,\n", + "\u001b[0;32m~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/layers/base.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, *args, **kwargs)\u001b[0m\n\u001b[1;32m 715\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 716\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0min_deferred_mode\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 717\u001b[0;31m \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 718\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0moutputs\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 719\u001b[0m raise ValueError('A layer\\'s `call` method should return a Tensor '\n", + "\u001b[0;32m~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/layers/normalization.py\u001b[0m in \u001b[0;36mcall\u001b[0;34m(self, inputs, training)\u001b[0m\n\u001b[1;32m 612\u001b[0m \u001b[0moffset\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 613\u001b[0m \u001b[0mscale\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 614\u001b[0;31m self.epsilon)\n\u001b[0m\u001b[1;32m 615\u001b[0m \u001b[0;31m# If some components of the shape got lost due to adjustments, fix that.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 616\u001b[0m \u001b[0moutputs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_shape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_shape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/ops/nn_impl.py\u001b[0m in \u001b[0;36mbatch_normalization\u001b[0;34m(x, mean, variance, offset, scale, variance_epsilon, name)\u001b[0m\n\u001b[1;32m 828\u001b[0m \"\"\"\n\u001b[1;32m 829\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname_scope\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"batchnorm\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmean\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvariance\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mscale\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moffset\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[0;32m--> 830\u001b[0;31m \u001b[0minv\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmath_ops\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrsqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvariance\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mvariance_epsilon\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 831\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mscale\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 832\u001b[0m \u001b[0minv\u001b[0m \u001b[0;34m*=\u001b[0m \u001b[0mscale\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'Tensor' and 'float'" + ] + } + ], + "source": [ + "a = tf.constant([[1,2,3], [4,5,6]])\n", + "\n", + "with tf.Session() as sess:\n", + " b = tf.layers.batch_normalization(a, axis = 0)\n", + " print(b.eval())" + ] + }, + { + "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.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/VQA_deep_learning.ipynb b/VQA_deep_learning.ipynb deleted file mode 100644 index f0d5517..0000000 --- a/VQA_deep_learning.ipynb +++ /dev/null @@ -1,319 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.5/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n", - " from ._conv import register_converters as _register_converters\n" - ] - } - ], - "source": [ - "import tensorflow as tf \n", - "import numpy as np\n", - "import cv2\n", - "import matplotlib.pyplot as plt\n", - "from datetime import datetime" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "# for Tensorboard logging and visualization\n", - "now = datetime.utcnow().strftime(\"%Y%m%d%H%M%S\")\n", - "root_logdir = \"tf_logs\"\n", - "logdir = \"{}/run-{}/\".format(root_logdir, now)" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "# a list that specifies convolution-pooling architecture; \n", - "# list index indicate layer position in stack; \n", - "# a pooling layer is represented by a tuple: (pooling type, kernel_size, strides) \n", - "# a convolution layer is represented by a typle: (filter_height, filter_width, depth)\n", - "layers = [(5, 5, 6),\n", - " ('max', (1,2,2,1), (1,2,2,1)),\n", - " (5, 5, 16), \n", - " ('max', (1,2,2,1), (1,2,2,1)),\n", - " (5, 5, 60),\n", - " ('max', (1,2,2,1), (1,2,2,1))] \n", - "\n", - "def conv_pool(x, layers):\n", - " out = x\n", - " n_conv, n_pool = 0, 0\n", - " prev_depth = int(x.shape[3])\n", - " for l in layers:\n", - " if type(l[0]) == int:\n", - " n_conv += 1\n", - " with tf.variable_scope('conv_{}'.format(n_conv), reuse = tf.AUTO_REUSE):\n", - " w = tf.get_variable('filter', initializer=tf.truncated_normal((l[0], l[1], prev_depth, l[2]),0,0.1))\n", - " b = tf.get_variable('bias', initializer=tf.zeros(l[2])) \n", - " out = tf.nn.relu(tf.nn.conv2d(out, w, strides=(1,1,1,1), padding='SAME') + b)\n", - " prev_depth = l[2]\n", - " elif l[0] == 'max':\n", - " n_pool += 1\n", - " out = tf.nn.max_pool(out, l[1], l[2], padding='SAME', name='pool_{}'.format(n_pool))\n", - " elif l[0] == 'avg':\n", - " n_pool += 1\n", - " out = tf.nn.avg_pool(out, l[1], l[2], padding='SAME', name='pool_{}'.format(n_pool))\n", - " return out\n", - "\n", - "# get all frames from video downscaled by a factor\n", - "# return an ndarray of shape (n_frames, height, width, channels)\n", - "def get_frames(path, n_frames, downscale_factor):\n", - " cap = cv2.VideoCapture(path)\n", - " seq = []\n", - " count = 0\n", - " while True:\n", - " success,frame = cap.read()\n", - " if count == n_frames or not success:\n", - " break\n", - " # downscale frame\n", - " width = int(frame.shape[1] / downscale_factor)\n", - " height = int(frame.shape[0] / downscale_factor)\n", - " seq.append(cv2.resize(frame, (width, height), interpolation = cv2.INTER_AREA))\n", - " count += 1\n", - " return np.stack(seq)\n", - "\n", - "# mini-batch generator\n", - "def next_batch(path, labels, n_batches, batch_size, n_frames, downscale_factor):\n", - " for i in range(n_batches):\n", - " x_batch, y_batch = [], []\n", - " for j in range(0, batch_size):\n", - " x_batch.append(get_frames(path.format(i*batch_size+j+1), n_frames, downscale_factor))\n", - " y_batch.append(labels[i*batch_size+j])\n", - " x_batch = np.stack(x_batch)\n", - " yield x_batch, y_batch\n", - " \n", - "# generate feature maps for each video in mini-batch\n", - "# x has shape (batch_size, n_frames, height, width, channels)\n", - "def get_feature_maps(x):\n", - " instances = []\n", - " for i in range(x.shape[0]):\n", - " instances.append(tf.contrib.layers.flatten(conv_pool(x[i, :, :, :, :], layers)))\n", - " return tf.stack(instances, axis=0)\n", - "\n", - "def score_to_label(scores, thresh_1, thresh_2):\n", - " for x in np.nditer(scores, op_flags=['readwrite']):\n", - " if x < thresh_1:\n", - " x[...] = 0\n", - " elif x < thresh_2:\n", - " x[...] = 1\n", - " else:\n", - " x[...] = 2\n", - " return scores" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/datasets/base.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.\n", - "Instructions for updating:\n", - "Use the retry module or similar alternatives.\n", - "(20, 100, 30600)\n" - ] - } - ], - "source": [ - "path = '/home/mallesh/video-qoe-labeling/dataset/trace_{}.mp4'\n", - "\n", - "height, width, n_channels = 1080, 1920, 3\n", - "downscale_factor = 8\n", - "n_frames = 100\n", - "n_classes = 3\n", - "n_batches, batch_size = 4, 20\n", - "n_hidden = 100 # number of hidden cells in LSTM\n", - "\n", - "X = tf.placeholder(tf.float32, shape=\n", - " (batch_size, n_frames, int(height/downscale_factor), int(width/downscale_factor), n_channels))\n", - "y = tf.placeholder(tf.int32, shape=(batch_size,))\n", - "\n", - "labels = score_to_label(np.loadtxt('/home/mallesh/video-qoe-labeling/dataset/mos.txt'), 2, 3.8)\n", - "\n", - "X_features = get_feature_maps(X)\n", - "print(X_features.shape)\n", - "\n", - "cell = tf.contrib.rnn.BasicLSTMCell(n_hidden)\n", - "output, _ = tf.nn.dynamic_rnn(cell, X_features, initial_state = cell.zero_state(batch_size, dtype=tf.float32))\n", - "\n", - "with tf.variable_scope('out', reuse = tf.AUTO_REUSE):\n", - " w = tf.get_variable('weight', shape=(n_hidden, n_classes))\n", - " b = tf.get_variable('bias', initializer=tf.zeros(n_classes))\n", - " pred = tf.matmul(output[:,-1,:], w) + b\n", - "\n", - "loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=pred, labels=y))\n", - "optimizer = tf.train.AdamOptimizer()\n", - "training_op = optimizer.minimize(loss)\n", - "loss_summary = tf.summary.scalar('loss', loss)\n", - "file_writer = tf.summary.FileWriter(logdir, tf.get_default_graph())" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(20, 100, 135, 240, 3)\n", - "[[ 0.37927836 -0.08560888 2.6771262 ]\n", - " [ 0.44744128 0.3947954 2.5882244 ]\n", - " [ 0.04256314 0.39614558 1.9952923 ]\n", - " [ 0.01711836 0.41108784 2.0334034 ]\n", - " [ 0.32527617 0.24322288 3.2082634 ]\n", - " [-0.40870816 0.18336628 2.033424 ]\n", - " [ 0.35842422 0.00692615 1.7578257 ]\n", - " [-0.32743627 0.318483 1.9235626 ]\n", - " [ 0.56437546 0.28331208 3.1881766 ]\n", - " [-0.38265842 -0.08463313 2.4024298 ]\n", - " [ 0.01732781 0.41098124 2.033123 ]\n", - " [ 0.01711985 0.41108695 2.0334013 ]\n", - " [ 0.27588528 0.25923365 1.6460352 ]\n", - " [ 0.05016926 0.39167893 1.9839 ]\n", - " [ 0.05264747 0.39260918 1.9831704 ]\n", - " [ 0.30169457 0.24605171 3.2600179 ]\n", - " [ 0.07404689 0.41454732 2.0233574 ]\n", - " [ 0.32336068 0.2669493 1.6475667 ]\n", - " [ 0.36009893 0.5279878 2.7528164 ]\n", - " [ 0.31793475 0.2614837 1.6379923 ]]\n", - "1.7771614\n", - "(20, 100, 135, 240, 3)\n", - "[[-0.06204156 0.79496956 1.2368748 ]\n", - " [ 0.19840315 1.3091224 0.39372188]\n", - " [-0.0292217 0.8915585 0.75091344]\n", - " [ 0.0919654 0.88935757 0.7646267 ]\n", - " [ 0.1628941 0.7908838 1.2623284 ]\n", - " [ 0.38111767 0.8404923 1.1870992 ]\n", - " [ 0.0832461 0.88951564 0.76364017]\n", - " [-0.06204156 0.79496956 1.2368748 ]\n", - " [ 0.08344238 0.8895122 0.76366234]\n", - " [ 0.07251229 1.0132546 0.71706533]\n", - " [ 0.08342844 0.8895123 0.7636608 ]\n", - " [ 0.08324607 0.88951564 0.76364017]\n", - " [ 0.0832461 0.88951564 0.76364017]\n", - " [-0.06160454 0.7949616 1.2369243 ]\n", - " [ 0.19840315 1.3091224 0.39372188]\n", - " [ 0.11835345 0.88887787 0.7676129 ]\n", - " [ 0.11835345 0.88887787 0.7676129 ]\n", - " [ 0.11844786 0.8888762 0.76762354]\n", - " [ 0.15422454 0.8446137 1.1614242 ]\n", - " [ 0.0832461 0.88951564 0.76364017]]\n", - "1.2838373\n", - "(20, 100, 135, 240, 3)\n", - "[[ 6.6104129e-02 9.5988196e-01 5.6221539e-01]\n", - " [-1.5516879e-01 8.9468837e-01 4.0705174e-01]\n", - " [ 2.9765752e-01 1.0281045e+00 7.2458786e-01]\n", - " [-3.0302963e-01 8.0091304e-01 8.8270134e-01]\n", - " [ 7.1249202e-02 9.6139783e-01 5.6582326e-01]\n", - " [-1.5259342e-01 9.6641046e-01 5.4156667e-01]\n", - " [-3.0302963e-01 8.0091304e-01 8.8270134e-01]\n", - " [ 1.1315355e-01 1.4946108e+00 5.0605452e-01]\n", - " [ 7.1171537e-02 9.6137494e-01 5.6576878e-01]\n", - " [-1.6045438e-01 9.2747623e-01 4.0413094e-01]\n", - " [ 5.6517433e-02 9.8093265e-01 5.8736938e-01]\n", - " [ 7.1892157e-02 9.6383816e-01 5.6365997e-01]\n", - " [ 6.1070051e-02 1.5441496e+00 3.7803373e-01]\n", - " [-1.5515684e-01 8.9469188e-01 4.0706015e-01]\n", - " [-1.6489974e-04 1.0756075e+00 8.7444943e-01]\n", - " [ 7.0583269e-02 9.6120173e-01 5.6535625e-01]\n", - " [ 7.1248129e-02 9.6139753e-01 5.6582248e-01]\n", - " [-1.5516931e-01 8.9468843e-01 4.0705168e-01]\n", - " [-1.5516931e-01 8.9468843e-01 4.0705168e-01]\n", - " [ 9.0059519e-02 1.5057209e+00 3.3565113e-01]]\n", - "1.1355282\n", - "(20, 100, 135, 240, 3)\n", - "[[-0.05554762 1.2411804 0.7248899 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [ 0.0207992 1.1436464 1.2259097 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [ 0.09306119 1.028489 0.9170438 ]\n", - " [ 0.0207992 1.1436464 1.2259097 ]\n", - " [ 0.0207992 1.1436464 1.2259097 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [ 0.19181803 0.91051793 0.36328435]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [-0.05554762 1.2411804 0.7248898 ]\n", - " [ 0.09306119 1.028489 0.9170438 ]\n", - " [ 0.09306119 1.028489 0.9170438 ]\n", - " [ 0.34042683 0.6978265 0.5554383 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]\n", - " [-0.05554762 1.2411804 0.7248899 ]]\n", - "1.1465046\n" - ] - } - ], - "source": [ - "saver = tf.train.Saver()\n", - "with tf.Session() as sess:\n", - " sess.run(tf.global_variables_initializer())\n", - " batch_num = 0\n", - " for X_batch, y_batch in next_batch(path, labels, n_batches, batch_size, n_frames, downscale_factor): \n", - " print(X_batch.shape)\n", - " batch_num += 1\n", - " summary_str = loss_summary.eval(feed_dict={X: X_batch, y: y_batch})\n", - " file_writer.add_summary(summary_str, batch_num)\n", - " sess.run(training_op, feed_dict={X: X_batch, y: y_batch})\n", - " saver.save(sess, '/tmp/after_batch_{}.ckpt'.format(batch_num))\n", - " print(pred.eval(feed_dict={X: X_batch, y: y_batch}))\n", - " print(loss.eval(feed_dict={X: X_batch, y: y_batch}))\n", - " \n", - " saver.save(sess, '/tmp/final.ckpt')\n", - "\n", - "file_writer.close()" - ] - }, - { - "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.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/extract.py b/extract.py deleted file mode 100644 index 4061929..0000000 --- a/extract.py +++ /dev/null @@ -1,33 +0,0 @@ -import os -import random -import numpy as np - -seqSize = 10 -dirs = os.listdir('directory path') -count1 = 0 -count2 = 0 -for d in dirs: - files = os.listdir('file path'): - totalFiles = len(files) - transFrameIndex = getTransFrameIndex() - startTransSeq = transFrameIndex - random.randint(3,7) - if startTransSeq < 0: - startTransSeq = 0 - endTransSeq = min(startTransSeq + seqSize, totalFiles) - transSeq = (startTransSeq, endTransSeq) - count1 += 1 - startNonTransSeq = None - endNonTransSeq = None - if totalFiles > 2*seqSize: - if endTransSeq <= totalFiles/2: - count2 += 1 - startNonTransSeq = endTransSeq + 1 - endNonTransSeq = startNonTransSeq + seqSize - elif startTransSeq >= totalFiles/2: - count2 += 1 - startNonTransSeq = 0 - endNonTransSeq = seqSize - nonTransSeq = (startNonTransSeq, endNonTransSeq) - seq = (transSeq, nonTransSeq) -print('transCount: ', count1) -print('nonTransCount: ', count2) diff --git a/model1.h5 b/model1.h5 deleted file mode 100644 index aa3ea77..0000000 Binary files a/model1.h5 and /dev/null differ diff --git a/prepareData.ipynb b/prepareData.ipynb deleted file mode 100644 index 7535430..0000000 --- a/prepareData.ipynb +++ /dev/null @@ -1,107 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import cv2\n", - "import glob\n", - "import random\n", - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "videos = glob.glob('../dataset/first-set/*.mp4')\n", - "mos = np.loadtxt('../dataset/first-set/mos.txt')" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [], - "source": [ - "def scaleDownVideos(videos, path):\n", - " for video in videos:\n", - " os.system('ffmpeg -i '+video+' -qp 1 -vf scale=120:68 '+path+'/'+video.split('/')[-1])\n", - "\n", - "def extractImages(videos, path):\n", - " for video in videos:\n", - " os.system('ffmpeg -i '+video+' -vf fps=10 '+path+'/'+video.split('/')[-1][:-4]+'_%d.png')" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [], - "source": [ - "#scaleDownVideos(videos, '../dataset/first-set/images')\n", - "videos = glob.glob('../dataset/first-set/images/*.mp4')\n", - "extractImages(videos, '../dataset/first-set/images')" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "def makeImagesNumpy(videos, mos, path):\n", - " mosNumpyArray = np.zeros((80, 5))\n", - " for video in videos:\n", - " images = glob.glob(path+'/'+video.split('/')[-1][:-4]+'_*.png')\n", - " images = images[:200]\n", - " frames = []\n", - " for image in images:\n", - " image = cv2.imread(image)\n", - " image = np.array(image)\n", - " frames.append(image)\n", - " frames = np.array(frames)\n", - " np.save('../dataset/first-set/numpys/'+video.split('/')[-1][:-4]+'.npy', frames)\n", - " mosIndex = int(video.split('/')[-1][:-4].split('_')[1])\n", - " m = int(round(mos[mosIndex-1]-1))\n", - " mosNumpyArray[mosIndex-1][m] = 1\n", - " #mosNumpy = np.full(200, mos[mosIndex-1])\n", - " np.save('../dataset/first-set/numpys/'+video.split('/')[-1][:-4]+'_mos.npy', mosNumpyArray)\n", - "makeImagesNumpy(videos, mos, '../dataset/first-set/images')" - ] - }, - { - "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.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}