natanielruiz
2017-07-07 ce90d92fad8d1e9ad87553ffd8dd9c553cfcc67c
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "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"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "TRAIN_DATA_DIR = '/Data/nruiz9/data/facial_landmarks/300W_LP/'\n",
    "AFW = os.path.join(TRAIN_DATA_DIR, 'AFW')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create filename.txt without poses more than -100, 100 degrees.\n",
    "with open(os.path.join(TRAIN_DATA_DIR, 'filename_list.txt')) as f:\n",
    "    with open(os.path.join(TRAIN_DATA_DIR, 'filename_list_filtered.txt'), 'wb') as wb:\n",
    "        counter = 0\n",
    "        for line in f:\n",
    "            original_line = line\n",
    "            line = line.strip('\\n')\n",
    "            mat_path = os.path.join(TRAIN_DATA_DIR, line + '.mat')\n",
    "            mat = sio.loadmat(mat_path)\n",
    "            pitch, yaw, roll = mat['Pose_Para'][0][0:3] * 180 / np.pi\n",
    "            if abs(pitch) > 99 or abs(yaw) > 99 or abs(roll) > 99:\n",
    "                counter += 1\n",
    "                continue\n",
    "            wb.write(original_line)\n",
    "        print counter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "TRAIN_DATA_DIR = '/Data/nruiz9/data/facial_landmarks'\n",
    "AFLW = os.path.join(TRAIN_DATA_DIR, 'AFLW2000')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create filename.txt without poses more than -100, 100 degrees.\n",
    "with open(os.path.join(AFLW, 'list_filenames.txt')) as f:\n",
    "    with open(os.path.join(AFLW, 'filename_list_filtered.txt'), 'wb') as wb:\n",
    "        counter = 0\n",
    "        for line in f:\n",
    "            original_line = line\n",
    "            line = line.strip('\\n')\n",
    "            mat_path = os.path.join(AFLW, line + '.mat')\n",
    "            mat = sio.loadmat(mat_path)\n",
    "            pitch, yaw, roll = mat['Pose_Para'][0][0:3] * 180 / np.pi\n",
    "            if abs(pitch) > 99 or abs(yaw) > 99 or abs(roll) > 99:\n",
    "                counter += 1\n",
    "                continue\n",
    "            wb.write(original_line)\n",
    "            \n",
    "        print counter"
   ]
  }
 ],
 "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
}