资源算法transfer-learning-tensornets

transfer-learning-tensornets

2020-04-02 | |  40 |   0 |   0

Transfer Learning with Tensornets and the Dataset API

This repository contains the complete code from the blog post Transfer Learning with Tensornets and Dataset API. The goal of this project is to tackle the the 2013 Facial Expression Recognition Challenge using transfer learning implemented with Tensorflow's high-level API's.

Data

You can download the data from the above link, copy it to the data/ folder and subsequently run ./datagen.sh in your Terminal. This function divides the fer2013.csv file into train and validation sets.

Training the model on Google Cloud

While it is possible to train this model locally, I did so on Goolge's ML Engine with the gcloud command-line tool. Make sure you upload both .csv files to a Google Cloud Storage bucket first. The trainer program and its utility functions are located in the ./train/ folder. An example script (to be run from the root of this directory) would look something like the following:

gcloud ml-engine jobs submit training 'jobname' --region europe-west1 
                           --scale-tier 'basic-gpu' 
                           --package-path trainer/ 
                           --staging-bucket 'gs://bucketname' 
                           --runtime-version 1.9 
                           --module-name trainer.task 
                           --python-version 3.5 
                           --packages deps/Cython-0.29.2.tar.gz,deps/tensornets-0.3.6.tar.gz 
                           -- 
                           --train-file 'gs://path/to/train.csv' 
                           --eval-file 'gs://path/to/valid.csv' 
                           --num-epochs 8 
                           --train-batch-size 32 
                           --eval-batch-size 32 
                           --ckpt-out 'gs://path/to/save/model'

Inferece

When the job finishes, the checkpoint files are saved to the location you specified ('gs://path/to/save/model' above). After downloading the files, we can freeze the weights and optimize the graph for inference using the trainer/freeze.py. From the command-line:

./freeze.py --ckpt ~/path/to/model.ckpt --out-file frozen_model.pb

The .pb file can subsequently be used directly with OpenCV for instance, running the model on our webcam:

./videocam.py --cascade-file face_default.xml --pb-file path/to/frozen_model.pb


上一篇:tensornets-master

下一篇: tensornets_counting_things

用户评价
全部评价

热门资源

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...