1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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
| }
|
|