From dd62d6fa4a85f18a29de009a972f5599b19ec946 Mon Sep 17 00:00:00 2001 From: natanielruiz <nataniel777@hotmail.com> Date: 星期四, 14 九月 2017 00:51:53 +0800 Subject: [PATCH] Fixing hopenet --- code/train.py | 2 practice/load_AFLW-KEPLER_split.ipynb | 190 ++++++++++++++ practice/.ipynb_checkpoints/load_AFLW-Copy1-checkpoint.ipynb | 30 +- practice/remove_KEPLER_test_split.ipynb | 128 +++++++++ practice/create_filtered_datasets.ipynb | 12 code/batch_testing.py | 6 practice/.ipynb_checkpoints/load_AFLW-KEPLER_split-checkpoint.ipynb | 225 +++++++++++++++++ code/test.py | 7 practice/load_AFLW-Copy1.ipynb | 4 practice/.ipynb_checkpoints/remove_KEPLER_test_split-checkpoint.ipynb | 128 +++++++++ 10 files changed, 704 insertions(+), 28 deletions(-) diff --git a/code/batch_testing.py b/code/batch_testing.py index 237ea54..db688a9 100644 --- a/code/batch_testing.py +++ b/code/batch_testing.py @@ -123,9 +123,9 @@ label_roll = labels[:,2].float() pre_yaw, pre_pitch, pre_roll, angles = model(images) - yaw = angles[args.iter_ref-1][:,0].cpu().data - pitch = angles[args.iter_ref-1][:,1].cpu().data - roll = angles[args.iter_ref-1][:,2].cpu().data + yaw = angles[args.iter_ref][:,0].cpu().data + pitch = angles[args.iter_ref][:,1].cpu().data + roll = angles[args.iter_ref][:,2].cpu().data # Mean absolute error yaw_error += torch.sum(torch.abs(yaw - label_yaw) * 3) diff --git a/code/test.py b/code/test.py index 41db842..7f76714 100644 --- a/code/test.py +++ b/code/test.py @@ -110,11 +110,12 @@ label_roll = labels[:,2].float() pre_yaw, pre_pitch, pre_roll, angles = model(images) - yaw = angles[args.iter_ref-1][:,0].cpu().data - pitch = angles[args.iter_ref-1][:,1].cpu().data - roll = angles[args.iter_ref-1][:,2].cpu().data + yaw = angles[args.iter_ref][:,0].cpu().data + pitch = angles[args.iter_ref][:,1].cpu().data + roll = angles[args.iter_ref][:,2].cpu().data # Mean absolute error + print yaw.numpy(), label_yaw.numpy() yaw_error += torch.sum(torch.abs(yaw - label_yaw) * 3) pitch_error += torch.sum(torch.abs(pitch - label_pitch) * 3) roll_error += torch.sum(torch.abs(roll - label_roll) * 3) diff --git a/code/train.py b/code/train.py index 50eeb82..6e1ae5b 100644 --- a/code/train.py +++ b/code/train.py @@ -241,7 +241,7 @@ # Finetuning loss loss_seq = [loss_yaw, loss_pitch, loss_roll] - for idx in xrange(args.iter_ref): + for idx in xrange(args.iter_ref+1): loss_angles = reg_criterion(angles[idx], label_angles.float()) loss_seq.append(loss_angles) diff --git a/practice/.ipynb_checkpoints/load_AFLW-Copy1-checkpoint.ipynb b/practice/.ipynb_checkpoints/load_AFLW-Copy1-checkpoint.ipynb index 5c0a9b6..856fbb4 100644 --- a/practice/.ipynb_checkpoints/load_AFLW-Copy1-checkpoint.ipynb +++ b/practice/.ipynb_checkpoints/load_AFLW-Copy1-checkpoint.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, "metadata": { "collapsed": true }, @@ -36,20 +36,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { - "ename": "KeyboardInterrupt", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-8-1f2606c2a679>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0;32mif\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misfile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_path\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0;31m#image = cv2.imread(input_path, 0) #load in grayscale\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 36\u001b[0;31m \u001b[0mimage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 37\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 38\u001b[0m \u001b[0;31m#Image dimensions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + "name": "stdout", + "output_type": "stream", + "text": [ + "Done\n" ] } ], @@ -148,11 +144,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "test\n" + ] + } + ], "source": [ "print 'test'" ] diff --git a/practice/.ipynb_checkpoints/load_AFLW-KEPLER_split-checkpoint.ipynb b/practice/.ipynb_checkpoints/load_AFLW-KEPLER_split-checkpoint.ipynb new file mode 100644 index 0000000..e882f99 --- /dev/null +++ b/practice/.ipynb_checkpoints/load_AFLW-KEPLER_split-checkpoint.ipynb @@ -0,0 +1,225 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "import numpy as np\n", + "import torch\n", + "from torch.utils.serialization import load_lua\n", + "import os\n", + "import scipy.io as sio\n", + "import cv2\n", + "import math\n", + "from matplotlib import pyplot as plt\n", + "\n", + "import sqlite3" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#Change this paths according to your directories\n", + "images_path = \"/Data/nruiz9/data/facial_landmarks/AFLW/aflw/data/flickr/\"\n", + "storing_path = \"/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped_loose/\"" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(573, 1)\n", + "(232, 1)\n", + "(165, 1)\n", + "3\n" + ] + } + ], + "source": [ + "#Load KEPLER split file\n", + "test_set = sio.loadmat('/Data/nruiz9/data/facial_landmarks/AFLW/testset.mat')\n", + "print test_set['test'][0][0][0].shape\n", + "print test_set['test'][0][0][1].shape\n", + "print test_set['test'][0][0][2].shape\n", + "print len(test_set['test'][0][0])\n", + "\n", + "# I will just use every single one for now. If results are not good I'll sample equally." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Done\n" + ] + } + ], + "source": [ + "#Image counter\n", + "counter = 1\n", + "\n", + "#Open the sqlite database\n", + "conn = sqlite3.connect('/Data/nruiz9/data/facial_landmarks/AFLW/aflw/data/aflw.sqlite')\n", + "c = conn.cursor()\n", + "\n", + "#Creating the query string for retriving: roll, pitch, yaw and faces position\n", + "#Change it according to what you want to retrieve\n", + "select_string = \"faceimages.filepath, faces.face_id, facepose.roll, facepose.pitch, facepose.yaw, facerect.x, facerect.y, facerect.w, facerect.h\"\n", + "from_string = \"faceimages, faces, facepose, facerect\"\n", + "where_string = \"faces.face_id = facepose.face_id and faces.file_id = faceimages.file_id and faces.face_id = facerect.face_id\"\n", + "query_string = \"SELECT \" + select_string + \" FROM \" + from_string + \" WHERE \" + where_string\n", + "\n", + "#It iterates through the rows returned from the query\n", + "for row in c.execute(query_string):\n", + "\n", + " #Using our specific query_string, the \"row\" variable will contain:\n", + " # row[0] = image path\n", + " # row[1] = face id\n", + " # row[2] = rollgma\n", + " # row[3] = pitch\n", + " # row[4] = yaw\n", + " # row[5] = face coord x\n", + " # row[6] = face coord y\n", + " # row[7] = face width\n", + " # row[8] = face heigh\n", + "\n", + " #Creating the full path names for input and output\n", + " input_path = images_path + str(row[0])\n", + " output_path = storing_path + str(row[0])\n", + "\n", + " #If the file exist then open it \n", + " if(os.path.isfile(input_path) == True):\n", + " #image = cv2.imread(input_path, 0) #load in grayscale\n", + " image = cv2.imread(input_path)\n", + "\n", + " #Image dimensions\n", + " image_h, image_w, _ = image.shape\n", + " #Roll, pitch and yaw\n", + " roll = row[2]\n", + " pitch = row[3]\n", + " yaw = row[4]\n", + " #Face rectangle coords\n", + " face_x = row[5]\n", + " face_y = row[6]\n", + " face_w = row[7]\n", + " face_h = row[8]\n", + "\n", + " #Error correction\n", + " k = 0.35\n", + " x_min = face_x - face_w * k * 0.6\n", + " x_max = face_x + face_w + face_w * k * 0.6\n", + " y_min = face_y - face_h * k * 2\n", + " y_max = face_y + face_h + face_h * k * 0.6\n", + " \n", + " x_min = int(max(0, x_min))\n", + " x_max = int(min(image_w, x_max))\n", + " y_min = int(max(0, y_min))\n", + " y_max = int(min(image_h, y_max))\n", + " \n", + " #Crop the face from the image\n", + " image_cropped = np.copy(image[y_min:y_max, x_min:x_max])\n", + " #Uncomment the lines below if you want to rescale the image to a particular size\n", + " to_size = 240\n", + " image_cropped = cv2.resize(image_cropped, (to_size,to_size), interpolation = cv2.INTER_AREA)\n", + " #Uncomment the line below if you want to use adaptive histogram normalisation\n", + " #clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(5,5))\n", + " #image_normalised = clahe.apply(image_rescaled)\n", + " #Save the image\n", + " #change \"image_cropped\" with the last uncommented variable name above\n", + " cv2.imwrite(output_path, image_cropped)\n", + " \n", + " txt_path = os.path.splitext(output_path)[0]+'.txt'\n", + " directory = os.path.dirname(output_path)\n", + " if not os.path.exists(directory):\n", + " os.makedirs(directory)\n", + " fid = open(txt_path, 'wb')\n", + " fid.write(input_path + ' ' + str(yaw) + ' ' + str(pitch) + ' ' + str(roll) + ' ' + str(face_x) + ' ' + str(face_y) + ' ' + str(face_w) + ' ' + str(face_h) + '\\n')\n", + " fid.close()\n", + " #Increasing the counter\n", + " counter = counter + 1 \n", + "\n", + " #if the file does not exits it return an exception\n", + " else:\n", + " raise ValueError('Error: I cannot find the file specified: ' + str(input_path))\n", + "\n", + "#Once finished the iteration it closes the database\n", + "c.close()\n", + "print 'Done'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "test\n" + ] + } + ], + "source": [ + "print 'test'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [conda root]", + "language": "python", + "name": "conda-root-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/practice/.ipynb_checkpoints/remove_KEPLER_test_split-checkpoint.ipynb b/practice/.ipynb_checkpoints/remove_KEPLER_test_split-checkpoint.ipynb new file mode 100644 index 0000000..0628c13 --- /dev/null +++ b/practice/.ipynb_checkpoints/remove_KEPLER_test_split-checkpoint.ipynb @@ -0,0 +1,128 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "AFLW2000 = '/Data/nruiz9/data/facial_landmarks/AFLW2000/'\n", + "AFLW = '/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped/'" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "list_2000 = '/Data/nruiz9/data/facial_landmarks/AFLW2000/filename_list_filtered.txt'\n", + "list_normal = '/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped/filename_list.txt'" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1969\n" + ] + } + ], + "source": [ + "fid = open(list_2000, 'r')\n", + "dict_2000 = dict()\n", + "for line in fid:\n", + " line = line.strip('\\n').split('/')\n", + " dict_2000[line[-1]] = 1\n", + "print len(dict_2000)\n", + "fid.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1966 19109\n" + ] + } + ], + "source": [ + "fid = open(list_normal, 'r')\n", + "naked = list_normal.strip('.txt')\n", + "train = open(naked + '_train.txt', 'wb')\n", + "test = open(naked + '_test.txt', 'wb')\n", + "test_dict = dict()\n", + "train_dict = dict()\n", + "for line in fid:\n", + " line = line.strip('\\n')\n", + " name = line.split('/')[-1]\n", + " if name in dict_2000.keys():\n", + " test.write(line + '\\n')\n", + " test_dict[line] = 1\n", + " else:\n", + " train.write(line + '\\n')\n", + " train_dict[line] = 1\n", + "\n", + "print len(test_dict), len(train_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [conda root]", + "language": "python", + "name": "conda-root-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/practice/create_filtered_datasets.ipynb b/practice/create_filtered_datasets.ipynb index 7e1fe4d..e5bbf42 100644 --- a/practice/create_filtered_datasets.ipynb +++ b/practice/create_filtered_datasets.ipynb @@ -96,19 +96,19 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ - "AFLW = '/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped/'\n", - "filenames = '/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped/filename_list_train.txt'" + "AFLW = '/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped_loose/'\n", + "filenames = '/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped_loose/filename_list.txt'" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -117,13 +117,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "246\n" + "243\n" ] } ], "source": [ "fid = open(filenames, 'r')\n", - "out = open(os.path.join(AFLW, 'filename_list_train_filtered.txt'), 'wb')\n", + "out = open(os.path.join(AFLW, 'filename_list_filtered.txt'), 'wb')\n", "counter = 0\n", "for line in fid:\n", " original_line = line\n", diff --git a/practice/load_AFLW-Copy1.ipynb b/practice/load_AFLW-Copy1.ipynb index 2b6bf67..856fbb4 100644 --- a/practice/load_AFLW-Copy1.ipynb +++ b/practice/load_AFLW-Copy1.ipynb @@ -36,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -144,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": { "collapsed": false }, diff --git a/practice/load_AFLW-KEPLER_split.ipynb b/practice/load_AFLW-KEPLER_split.ipynb new file mode 100644 index 0000000..fa8ab5f --- /dev/null +++ b/practice/load_AFLW-KEPLER_split.ipynb @@ -0,0 +1,190 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "import numpy as np\n", + "import torch\n", + "from torch.utils.serialization import load_lua\n", + "import os\n", + "import scipy.io as sio\n", + "import cv2\n", + "import math\n", + "from matplotlib import pyplot as plt\n", + "\n", + "import sqlite3" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#Change this paths according to your directories\n", + "images_path = \"/Data/nruiz9/data/facial_landmarks/AFLW/aflw/data/flickr/\"\n", + "storing_path = \"/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped_loose_test/\"" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(573, 1)\n", + "(232, 1)\n", + "(165, 1)\n", + "3\n", + "(970, 1)\n" + ] + } + ], + "source": [ + "#Load KEPLER split file\n", + "test_set = sio.loadmat('/Data/nruiz9/data/facial_landmarks/AFLW/testset.mat')\n", + "print test_set['test'][0][0][0].shape\n", + "print test_set['test'][0][0][1].shape\n", + "print test_set['test'][0][0][2].shape\n", + "print len(test_set['test'][0][0])\n", + "\n", + "id_test_set = np.concatenate([test_set['test'][0][0][0], test_set['test'][0][0][1], test_set['test'][0][0][2]])\n", + "print id_test_set.shape\n", + "\n", + "# I will just use every single one for now. If results are not good I'll sample equally." + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "970\n", + "Done\n" + ] + } + ], + "source": [ + "#Image counter\n", + "counter = 0\n", + "\n", + "#Open the sqlite database\n", + "conn = sqlite3.connect('/Data/nruiz9/data/facial_landmarks/AFLW/aflw/data/aflw.sqlite')\n", + "c = conn.cursor()\n", + "\n", + "#Creating the query string for retriving: roll, pitch, yaw and faces position\n", + "#Change it according to what you want to retrieve\n", + "select_string = \"faceimages.filepath, faces.face_id, facepose.roll, facepose.pitch, facepose.yaw, facerect.x, facerect.y, facerect.w, facerect.h\"\n", + "from_string = \"faceimages, faces, facepose, facerect\"\n", + "where_string = \"faces.face_id = facepose.face_id and faces.file_id = faceimages.file_id and faces.face_id = facerect.face_id\"\n", + "query_string = \"SELECT \" + select_string + \" FROM \" + from_string + \" WHERE \" + where_string\n", + "\n", + "test_file_txt = '/Data/nruiz9/data/facial_landmarks/AFLW/KEPLER_test_split.txt'\n", + "out_txt = open(test_file_txt, 'w')\n", + "#It iterates through the rows returned from the query\n", + "for row in c.execute(query_string):\n", + "\n", + " #Using our specific query_string, the \"row\" variable will contain:\n", + " # row[0] = image path\n", + " # row[1] = face id\n", + " # row[2] = rollgma\n", + " # row[3] = pitch\n", + " # row[4] = yaw\n", + " # row[5] = face coord x\n", + " # row[6] = face coord y\n", + " # row[7] = face width\n", + " # row[8] = face heigh\n", + " if row[1] in id_test_set:\n", + " #Creating the full path names for input and output\n", + " input_path = images_path + str(row[0])\n", + " output_path = storing_path + str(row[0])\n", + "\n", + " #If the file exist then open it \n", + " if(os.path.isfile(input_path) == True):\n", + "\n", + " out_txt.write(str(row[0]) + '.jpg\\n')\n", + " #Increasing the counter\n", + " counter = counter + 1 \n", + "\n", + " #if the file does not exits it return an exception\n", + " else:\n", + " raise ValueError('Error: I cannot find the file specified: ' + str(input_path))\n", + "\n", + "#Once finished the iteration it closes the database\n", + "print counter\n", + "out_txt.close()\n", + "c.close()\n", + "print 'Done'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "test\n" + ] + } + ], + "source": [ + "print 'test'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [conda root]", + "language": "python", + "name": "conda-root-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/practice/remove_KEPLER_test_split.ipynb b/practice/remove_KEPLER_test_split.ipynb new file mode 100644 index 0000000..239e56a --- /dev/null +++ b/practice/remove_KEPLER_test_split.ipynb @@ -0,0 +1,128 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "AFLW2000 = '/Data/nruiz9/data/facial_landmarks/AFLW2000/'\n", + "AFLW = '/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped_loose/'" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "list_2000 = '/Data/nruiz9/data/facial_landmarks/AFLW/KEPLER_test_split.txt'\n", + "list_normal = '/Data/nruiz9/data/facial_landmarks/AFLW/aflw_cropped_loose/filename_list_filtered.txt'" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "961\n" + ] + } + ], + "source": [ + "fid = open(list_2000, 'r')\n", + "dict_2000 = dict()\n", + "for line in fid:\n", + " line = line.strip('\\n').split('/')\n", + " dict_2000[line[-1]] = 1\n", + "print len(dict_2000)\n", + "fid.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "954 19842\n" + ] + } + ], + "source": [ + "fid = open(list_normal, 'r')\n", + "naked = list_normal.strip('.txt')\n", + "train = open(naked + '_train.txt', 'wb')\n", + "test = open(naked + '_test.txt', 'wb')\n", + "test_dict = dict()\n", + "train_dict = dict()\n", + "for line in fid:\n", + " line = line.strip('\\n')\n", + " name = line.split('/')[-1]\n", + " if name+'.jpg' in dict_2000.keys():\n", + " test.write(line + '\\n')\n", + " test_dict[line] = 1\n", + " else:\n", + " train.write(line + '\\n')\n", + " train_dict[line] = 1\n", + "\n", + "print len(test_dict), len(train_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [conda root]", + "language": "python", + "name": "conda-root-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} -- Gitblit v1.8.0