PyTorch module to use OpenFace's nn4.small2.v1.t7 model

Overview

OpenFace for Pytorch

  • Disclaimer: This codes require the input face-images that are aligned and cropped in the same way of the original OpenFace. *

I made a dirty code to use OpenFace in PyTorch. I converted 'nn4.small2.v1.t7' to a .hdf5 file using 'torch-hdf5'. Then I read layer informations from .hdf5 file, which can be displayed as follows:

nn.Sequential {
  [input -> (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) -> output]
  (1): nn.SpatialConvolutionMM(3 -> 64, 7x7, 2,2, 3,3)
  (2): nn.SpatialBatchNormalization (4D) (64)
  (3): nn.ReLU
  (4): nn.SpatialMaxPooling(3x3, 2,2, 1,1)
  (5): nn.SpatialCrossMapLRN
...

Then I manually coded layers in PyTorch (see loadOpenFace.py) with some tentative layers code which may be supported by PyTorch officially laters (SpatialCrossMapLRN_temp.py, adopted from PyTorch's nn.legacy). The final model is 'openface.pth' (which may need to be renamed to 'openface_nn4_small2_v1.pth'), which can be loaded by codes in loadOpenFace.py.

Please see main section of loadOpenFace.py for how-to-use. Simply,

net = prepareOpenFace(useCuda=True, gpuDevice=0, useMultiGPU=False).eval()
feature = net(input_tensor)    # input_tensor should be (batch_size, 3, 96, 96)
  • License
    This is released under Apache 2.0 license.
Comments
  • Is input size (batchseize,3,96,96) right?

    Is input size (batchseize,3,96,96) right?

    When I'm trying outputs_128, outputs_726 = face_net(imgs_tensor) (imgs_tensor is [3,3,96,96]) , I got an error : ValueError: Expected more than 1 value per channel when training, got input size [1, 96, 1, 1]. can you solve that?

    opened by CXMANDTXW 2
  • AttributeError: 'tuple' object has no attribute 'size'

    AttributeError: 'tuple' object has no attribute 'size'

    I see that f is a tuple, consisting of (x, x_736), the result of the forward() method in the netOpenFace class. I am getting AttributeError: 'tuple' object has no attribute 'size' when I run your code as is.

    Is this expected?

    The following code is from the last few lines in loadOpenFace.py.

    for i in range(f.size(0) - 1):
            for j in range(i + 1, f.size(0)):
                df = f[i] - f[j]
                print(img_paths[i].split('/')[-1], img_paths[j].split('/')[-1], torch.dot(df, df))
    
    opened by surfertas 2
  • How to run your codes with multiple GPU?

    How to run your codes with multiple GPU?

    Hi, thnkim!

    I'm using your codes to fine tune our face recognition network in pytorch, it works well when using single GPU (gpuDevice=0), I want to know how to run it with multiple GPU?

    thanks!

    opened by bluer555 1
  • How about 'openface_server.lua'

    How about 'openface_server.lua'

    Hello, thnkim! The code of openface for pytorch is help me. I am trying to run it but didn't work at last step, it's the problem of the file of 'openface_server.lua'.I'm not family with Torch and appreciate you can transform this file to pytorch !

    opened by Jacktofine 1
  • Question: which pth-model is the recommended?

    Question: which pth-model is the recommended?

    As the subject says: you provide openface.pth and openface_20180119.pth where the first one is referenced in your source code while the second one is newer.

    Which model is the recommended one and yields best results?

    Thanks in advance.

    opened by domcross 0
  • Lenon with glasses is closer to clapton with glasses than to lennon without glasses.

    Lenon with glasses is closer to clapton with glasses than to lennon without glasses.

    Thanks for the code. I have learned a lot.

    But when I run the example I got that lennon with glasses was closer to clapton with glasses than to lennon without glasses. I think this is completely wrong.

    I get the same exact resulto with both: openface_20180119.pth and openface.pth

    Thanks.

    opened by educob 0
  • bbox detection and face align

    bbox detection and face align

    Hey, I'm new to face detection. It seems the codes replace the network part of the torch version openface. But the face box detection and face align API in openface is not contained. Is there easy way to do that without install the torch version openface?

    opened by zhangyuygss 0
Owner
Pete Tae-hoon Kim
Deeping Source Inc.
Pete Tae-hoon Kim
In this project we investigate the performance of the SetCon model on realistic video footage. Therefore, we implemented the model in PyTorch and tested the model on two example videos.

Contrastive Learning of Object Representations Supervisor: Prof. Dr. Gemma Roig Institutions: Goethe University CVAI - Computational Vision & Artifici

Dirk Neuhäuser 6 Dec 8, 2022
Torch-mutable-modules - Use in-place and assignment operations on PyTorch module parameters with support for autograd

Torch Mutable Modules Use in-place and assignment operations on PyTorch module p

Kento Nishi 7 Jun 6, 2022
计算机视觉中用到的注意力模块和其他即插即用模块PyTorch Implementation Collection of Attention Module and Plug&Play Module

PyTorch实现多种计算机视觉中网络设计中用到的Attention机制,还收集了一些即插即用模块。由于能力有限精力有限,可能很多模块并没有包括进来,有任何的建议或者改进,可以提交issue或者进行PR。

PJDong 599 Dec 23, 2022
Use MATLAB to simulate the signal and extract features. Use PyTorch to build and train deep network to do spectrum sensing.

Deep-Learning-based-Spectrum-Sensing Use MATLAB to simulate the signal and extract features. Use PyTorch to build and train deep network to do spectru

null 10 Dec 14, 2022
Step by Step on how to create an vision recognition model using LOBE.ai, export the model and run the model in an Azure Function

Step by Step on how to create an vision recognition model using LOBE.ai, export the model and run the model in an Azure Function

El Bruno 3 Mar 30, 2022
This codebase is the official implementation of Test-Time Classifier Adjustment Module for Model-Agnostic Domain Generalization (NeurIPS2021, Spotlight)

Test-Time Classifier Adjustment Module for Model-Agnostic Domain Generalization This codebase is the official implementation of Test-Time Classifier A

null 47 Dec 28, 2022
😇A pyTorch implementation of the DeepMoji model: state-of-the-art deep learning model for analyzing sentiment, emotion, sarcasm etc

------ Update September 2018 ------ It's been a year since TorchMoji and DeepMoji were released. We're trying to understand how it's being used such t

Hugging Face 865 Dec 24, 2022
Convert Pytorch model to onnx or tflite, and the converted model can be visualized by Netron

Convert Pytorch model to onnx or tflite, and the converted model can be visualized by Netron

Roxbili 5 Nov 19, 2022
this is a lite easy to use virtual keyboard project for anyone to use

virtual_Keyboard this is a lite easy to use virtual keyboard project for anyone to use motivation I made this for this year's recruitment for RobEn AA

Mohamed Emad 3 Oct 23, 2021
A collection of easy-to-use, ready-to-use, interesting deep neural network models

Interesting and reproducible research works should be conserved. This repository wraps a collection of deep neural network models into a simple and un

Aria Ghora Prabono 16 Jun 16, 2022
Transfer style api - An API to use with Tranfer Style App, where you can use two image and transfer the style

Transfer Style API It's an API to use with Tranfer Style App, where you can use

Brian Alejandro 1 Feb 13, 2022
High performance, easy-to-use, and scalable machine learning (ML) package, including linear model (LR), factorization machines (FM), and field-aware factorization machines (FFM) for Python and CLI interface.

What is xLearn? xLearn is a high performance, easy-to-use, and scalable machine learning package that contains linear model (LR), factorization machin

Chao Ma 3k Jan 3, 2023
High performance, easy-to-use, and scalable machine learning (ML) package, including linear model (LR), factorization machines (FM), and field-aware factorization machines (FFM) for Python and CLI interface.

What is xLearn? xLearn is a high performance, easy-to-use, and scalable machine learning package that contains linear model (LR), factorization machin

Chao Ma 2.8k Feb 12, 2021
A complete end-to-end demonstration in which we collect training data in Unity and use that data to train a deep neural network to predict the pose of a cube. This model is then deployed in a simulated robotic pick-and-place task.

Object Pose Estimation Demo This tutorial will go through the steps necessary to perform pose estimation with a UR3 robotic arm in Unity. You’ll gain

Unity Technologies 187 Dec 24, 2022
An efficient and easy-to-use deep learning model compression framework

TinyNeuralNetwork 简体中文 TinyNeuralNetwork is an efficient and easy-to-use deep learning model compression framework, which contains features like neura

Alibaba 441 Dec 25, 2022
A Pytorch implementation of CVPR 2021 paper "RSG: A Simple but Effective Module for Learning Imbalanced Datasets"

RSG: A Simple but Effective Module for Learning Imbalanced Datasets (CVPR 2021) A Pytorch implementation of our CVPR 2021 paper "RSG: A Simple but Eff

null 120 Dec 12, 2022
Implementation of the Triangle Multiplicative module, used in Alphafold2 as an efficient way to mix rows or columns of a 2d feature map, as a standalone package for Pytorch

Triangle Multiplicative Module - Pytorch Implementation of the Triangle Multiplicative module, used in Alphafold2 as an efficient way to mix rows or c

Phil Wang 22 Oct 28, 2022
Neural Module Network for VQA in Pytorch

Neural Module Network (NMN) for VQA in Pytorch Note: This is NOT an official repository for Neural Module Networks. NMN is a network that is assembled

Harsh Trivedi 111 Nov 24, 2022