natanielruiz
2017-08-12 beb9f36419d0df03c3248757f54af032a633e05c
AFLW training ready.
1个文件已添加
1 文件已重命名
2个文件已修改
38023 ■■■■■ 已修改文件
code/train_AFLW.py 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
practice/.ipynb_checkpoints/remove_AFLW2000-checkpoint.ipynb 补丁 | 查看 | 原始文档 | blame | 历史
practice/create_filtered_datasets.ipynb 37878 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
practice/remove_AFLW2000.ipynb 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code/train_AFLW.py
@@ -41,6 +41,10 @@
          default='', type=str)
    parser.add_argument('--filename_list', dest='filename_list', help='Path to text file containing relative paths for every example.',
          default='', type=str)
    parser.add_argument('--finetune', dest='finetune', help='Boolean: finetune or from Imagenet pretrain.',
          default=False, type=bool)
    parser.add_argument('--snapshot', dest='snapshot', help='Path to finetune snapshot.',
          default='', type=str)
    args = parser.parse_args()
@@ -105,7 +109,7 @@
    transformations = transforms.Compose([transforms.Scale(224),transforms.RandomCrop(224),
                                          transforms.ToTensor()])
    pose_dataset = datasets.Pose_300W_LP_binned(args.data_dir, args.filename_list,
    pose_dataset = datasets.AFLW(args.data_dir, args.filename_list,
                                transformations)
    train_loader = torch.utils.data.DataLoader(dataset=pose_dataset,
                                               batch_size=batch_size,
@@ -113,10 +117,10 @@
                                               num_workers=2)
    model.cuda(gpu)
    criterion = nn.CrossEntropyLoss().cuda()
    reg_criterion = nn.MSELoss().cuda()
    criterion = nn.CrossEntropyLoss().cuda(gpu)
    reg_criterion = nn.MSELoss().cuda(gpu)
    # Regression loss coefficient
    alpha = 0.01
    alpha = 0.1
    idx_tensor = [idx for idx in xrange(66)]
    idx_tensor = torch.FloatTensor(idx_tensor).cuda(gpu)
@@ -135,7 +139,6 @@
            label_roll = Variable(labels[:,2].cuda(gpu))
            optimizer.zero_grad()
            model.zero_grad()
            yaw, pitch, roll = model(images)
@@ -175,13 +178,13 @@
                       %(epoch+1, num_epochs, i+1, len(pose_dataset)//batch_size, loss_yaw.data[0], loss_pitch.data[0], loss_roll.data[0]))
                if epoch == 0:
                    torch.save(model.state_dict(),
                    'output/snapshots/resnet50_AFW_iter_'+ str(i+1) + '.pkl')
                    'output/snapshots/resnet50_AFLW_iter_'+ str(i+1) + '.pkl')
        # Save models at numbered epochs.
        if epoch % 1 == 0 and epoch < num_epochs - 1:
            print 'Taking snapshot...'
            torch.save(model.state_dict(),
            'output/snapshots/resnet50_AFW_epoch_'+ str(epoch+1) + '.pkl')
            'output/snapshots/resnet50_AFLW_epoch_'+ str(epoch+1) + '.pkl')
    # Save the final Trained Model
    torch.save(model.state_dict(), 'output/snapshots/resnet50_AFLW_epoch' + str(epoch+1) + '.pkl')
practice/.ipynb_checkpoints/remove_AFLW2000-checkpoint.ipynb
practice/create_filtered_datasets.ipynb
Diff too large
practice/remove_AFLW2000.ipynb
New file
@@ -0,0 +1,128 @@
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "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": 3,
   "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": 5,
   "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": 6,
   "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
}