{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert pre-trained weights from CSV files to binary format" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Important:** before running this notebook, copy the [pre-trained weight CSV files](https://github.com/iwantooxxoox/Keras-OpenFace/tree/master/weights) from the Keras-OpenFace project to the local `weights` directory." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from model import create_model\n", "from utils import load_weights" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Instantiate the [nn4.small2](http://cmusatyalab.github.io/openface/models-and-accuracies/#model-definitions) model of the [OpenFace](https://cmusatyalab.github.io/openface/) project as Keras model." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nn4_small2 = create_model()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the pre-trained model weights from CSV files." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nn4_small2_weights = load_weights()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Update the Keras model with the loaded weights and save the weights in binary format." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for name, w in nn4_small2_weights.items():\n", " if nn4_small2.get_layer(name) != None:\n", " nn4_small2.get_layer(name).set_weights(w)\n", "\n", "nn4_small2.save_weights('weights/nn4.small2.v1.h5')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }