natanielruiz
2017-09-14 93855b2faf8b795d0058c217ee980d435f23227d
practice/.ipynb_checkpoints/create_filtered_datasets-checkpoint.ipynb
@@ -2,7 +2,7 @@
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
@@ -93,6 +93,65 @@
    "            \n",
    "        print counter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "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": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "601\n"
     ]
    }
   ],
   "source": [
    "fid = open(filenames, 'r')\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",
    "    line = line.strip('\\n')\n",
    "    if not os.path.exists(os.path.join(AFLW, line + '.txt')):\n",
    "        counter += 1\n",
    "        continue\n",
    "    annot_file = open(os.path.join(AFLW, line + '.txt'))\n",
    "    annot = annot_file.readline().strip('\\n').split(' ')\n",
    "    yaw = float(annot[1]) * 180 / np.pi\n",
    "    pitch = float(annot[2]) * 180 / np.pi\n",
    "    roll = float(annot[3]) * 180 / np.pi\n",
    "    if abs(pitch) > 89 or abs(yaw) > 89 or abs(roll) > 89:\n",
    "        counter += 1\n",
    "        continue\n",
    "    out.write(original_line)\n",
    "\n",
    "print counter    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {