Giter Site home page Giter Site logo

pytorch-jaanet's Introduction

PyTorch-JAANet

This repository is the PyTorch implementation of JAA-Net, as well as its extended journal version. "*v1.py" is for the ECCV version, and "*v2.py" is for the IJCV version. The trained models can be downloaded here. The original Caffe implementation can be found here

Getting Started

Installation

  • This code was tested with PyTorch 1.1.0 and Python 3.5
  • Clone this repo:
git clone https://github.com/ZhiwenShao/PyTorch-JAANet
cd PyTorch-JAANet

Datasets

BP4D and DISFA

Put these datasets into the folder "dataset" following the paths shown in the list files of the folder "data/list". You can refer to the example images for BP4D and DISFA

Preprocessing

  • Put the landmark annotation files into the folder "dataset". Two example files "BP4D_combine_1_2_land.txt" and "DISFA_combine_1_2_66land.txt" are also provided
    • For DISFA dataset, we need to select the annotations of 49 landmarks from original 66 landmarks:
    cd dataset
    python read_disfa_49land.py
    
  • Conduct similarity transformation for face images:
    cd dataset
    python face_transform.py
    
  • Compute the inter-ocular distance of each face image:
    cd dataset
    python write_biocular.py
    
  • Compute the weight of the loss of each AU for the training set:
    • The AU annoatation files should be in the folder "data/list"
    cd dataset
    python write_AU_weight.py
    

Training

  • Train on BP4D with the first two folds for training and the third fold for testing:
python train_JAAv1.py --run_name='JAAv1' --gpu_id=0 --train_batch_size=16 --eval_batch_size=28 --train_path_prefix='data/list/BP4D_combine_1_2' --test_path_prefix='data/list/BP4D_part3' --au_num=12
  • Train on DISFA with the first two folds for training and the third fold for testing, using the the well-trained BP4D model for initialization:
python train_JAAv1_disfa.py --run_name='JAAv1_DISFA' --gpu_id=0 --train_batch_size=16 --eval_batch_size=32 --train_path_prefix='data/list/DISFA_combine_1_2' --test_path_prefix='data/list/DISFA_part3' --au_num=8 --pretrain_path='JAAv1_combine_1_3' --pretrain_epoch=5 

Testing

  • Test the models saved in different epochs:
python test_JAAv1.py --run_name='JAAv1' --gpu_id=0 --start_epoch=1 --n_epochs=12 --eval_batch_size=28 --test_path_prefix='data/list/BP4D_part3' --au_num=12
  • Visualize attention maps
python test_JAAv1.py --run_name='JAAv1' --gpu_id=0 --pred_AU=False --vis_attention=True --start_epoch=5 --n_epochs=5 --test_path_prefix='data/list/BP4D_part3' --au_num=12

Supplement

  • The PyTorch implementation for the ECCV version conducts two minor revisions to make the proposed method more general:
    • The redundant cropping of attention maps is removed
    • The assembling of local feature maps uses element-wise average instead of element-wise sum
  • The differences in the extended journal version are detailed here

Citation

  • If you use this code for your research, please cite our papers
@inproceedings{shao2018deep,
  title={Deep Adaptive Attention for Joint Facial Action Unit Detection and Face Alignment},
  author={Shao, Zhiwen and Liu, Zhilei and Cai, Jianfei and Ma, Lizhuang},
  booktitle={European Conference on Computer Vision},
  year={2018},
  pages={725--740},
  organization={Springer}
}
@article{shao2020jaa,
  title={J{\^A}A-Net: Joint Facial Action Unit Detection and Face Alignment via Adaptive Attention},
  author={Shao, Zhiwen and Liu, Zhilei and Cai, Jianfei and Ma, Lizhuang},
  journal={International Journal of Computer Vision},
  year={2020},
  publisher={Springer}
}

pytorch-jaanet's People

Contributors

zhiwenshao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pytorch-jaanet's Issues

Unable to configure DISFA as required

Hi,
I try to train the model on DISFA, but the DISFA database I applied for has only left and right view videos and no images. How can I deal with this?

preproccess

how to make BP4d .mat landmark to land.txt of combine , any code of here?

DISFA action Unit

Hello @ZhiwenShao
In DISFA dataset, each action unit was labeled within a scale of 0 to 5.
here are the 4 first frames of SN001.
AU_1 AU_2 AU_4 AU_5 AU_6 AU_9 AU_12 AU_15 AU_17 AU_20 AU_25 AU_26
0 0 0 0 0 0 0 2 0 0 0 0 0
1 0 0 0 0 0 0 2 0 0 0 0 0
2 0 0 0 0 0 0 2 0 0 0 0 0
3 0 0 0 0 0 0 2 0 0 0 0 0
4 0 0 0 0 0 0 2 0 0 0 0 0
I am wondering that you have used a binary scaling (convert all label>1 to 1 )as the problem is a multi-label classification?

Output of region_learning is NAN when training BP4D

Hello,Shao!Thank you very much for sharing your code!
I got an issue when training BP4D that the output tensor parameters of region_learning always become NAN(sometimes 0) ,have you ever encountered similar issues?Or,What do you think caused it and how to fix it?
Thanks for the help!

Getting output of AU Attention Refinement as image

Hello,
I was wondering is it possible to get output of "AU Attention Refinement" module and save it as image? I was looking on your article and it seems to be possible because you included example image on net structure (Fig 3. - Green Image).
I'm thinking about use this module as preprocessing to CONV LSTM network and see what happen.

The performance of BP4D dataset

Thanks for opening your great work.
Now, we are reproducing your paper performance according to your readme to train JAANet-v2 model on the BP4D dataset, but we cannot get the results you said in the IJCV version. In BP4D-part3, we only get about F1-frame of 0.6 (decrease about 2.5%) .
This makes me very confused.
Can you publish your pre-trained model on BP4D as you said?
Thanks

Problem on the evaluation phase of DISFA Dataset

Hello and thank you for your work! I am trying to run your code on DISFA dataset but when I am running train_JAAv2_disfa.py I am getting an error. The error presents when the program gets to AU_detection_evalv2. Could you please explain me why this happens? The error is that one:

File "C:/Users/pc/Desktop/PyTorch-JAANet/train_JAAv2_disfa.py", line 332, in
main(config)
File "C:/Users/pc/Desktop/PyTorch-JAANet/train_JAAv2_disfa.py", line 189, in main
local_au_net, global_au_feat, au_net, use_gpu=use_gpu)
File "C:\Users\pc\Desktop\PyTorch-JAANet\util.py", line 121, in AU_detection_evalv2
align_feat, align_output, aus_map = align_net(region_feat)
File "C:\Users\pc\social-networks-analysis-pms-master\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "C:\Users\pc\Desktop\PyTorch-JAANet\network.py", line 204, in forward
arr2d[0,4], arr2d[1,4]-ruler/2, arr2d[0,5], arr2d[1,5]-ruler/2)
File "C:\Users\pc\Desktop\PyTorch-JAANet\network.py", line 166, in generate_map
for h in range(int(start_h), int(end_h)+1):
ValueError: cannot convert float NaN to integer
Thank you in advance!

datasets help

Hello,
Thank you for your great work!
I want to run your codes for study, but i could not be able to download the BP4D and DISFA dataset, could you please send these two datasets to me. Thank you very very much!
My email: [email protected]

How to get landmarks

Hello,
Thank you very much for sharing your code!
I've got similar question I don't how to get face landmarks for all files. There is example for two images in BP4D_combine_1_2_land.txt file but I don't get how to get rest of them.

Thank you!

F1_Frame calculation

Hi,
I am wondering how did you define F1_frame! F1_score, precision and recall can not be considered in this context because a lot of examples does not have a positive class

Does the face_transform.py work for DISFA?

Hello, It seems that the preprocess is implemented for BP4D dataset with 49 landmarks, but DISFA has 66 lankmarks. Will the face_transform.py works the same for 66 landmarks?
Thanks for the help!

无法复现 DISFA 数据集的测试结果

您好,感谢您的开源。我在DISFA数据集上用您提供的模型进行测试:
模型用的是: JAAV2/DISFA_combine_1_2, 测试列表是: DISFA_part3, 但测试的 平均 f1 仅有 0.519, 和论文差很多。

Pre-training model error

loading pretrained model ...
Traceback (most recent call last).
aus_output.2.1.weight", "local_aus_output.2.1.bias", "local_aus_output.3.0.weight", "local_aus_output.3.0.bias", "local_aus_output.3. 1.weight", "local_aus_output.3.1.bias", "local_aus_output.4.0.weight", "local_aus_output.4.0.bias", "local_aus_output.4.1.weight", " local_aus_output.4.1.bias", "local_aus_output.5.0.weight", "local_aus_output.5.0.bias", "local_aus_output.5.1.weight", "local_aus_output. output.5.1.bias", "local_aus_output.6.0.weight", "local_aus_output.6.0.bias", "local_aus_output.6.1.weight", "local_aus_output.6.1. bias", "local_aus_output.7.0.weight", "local_aus_output.7.0.bias", "local_aus_output.7.1.weight", "local_aus_output.7.1.bias", "local aus_output.8.0.weight", "local_aus_output.8.0.bias", "local_aus_output.8.1.weight", "local_aus_output.8.1.bias", "local_aus_output.9.0 .weight", "local_aus_output.9.0.bias", "local_aus_output.9.1.weight", "local_aus_output.9.1.bias", "local_aus_output.10.0.weight", " local_aus_output.10.0.bias", "local_aus_output.10.1.weight", "local_aus_output.10.1.bias", "local_aus_output.11.0.weight", "local_aus_ output.11.0.bias", "local_aus_output.11.1.weight", "local_aus_output.11.1.bias".
Hello, thank you for your open source, I am trying to reproduce the test for DISFA however when I try to load the model for BP4D the above error is reported, can you tell me why this is? Thank you very much for your answer!

DISFA_combine_1_2_weight.txt not found.

Hello and thank you for sharing this code.
I downloaded the DISFA dataset and want to train and run your model with this dataset as you noted in the article.
I put the images as you said regarding the list path files. But in the pre-processing part, you noted:

Put the landmark annotation files into the folder "dataset".

In the DISFA dataset which I downloaded there are .Mat files as Landmarks. How should I use them?

Also i have the error "OSError: data/list/DISFA_combine_1_2_weight.txt not found." which I dont know how I can get this file.

Can you guide me please?

Regards

Error in second iteration in training

Hello,
I've got issue with running code. I made all necessary preprocessing according to readme file.
First iteration works just fine but in second one the following error occurs:

/home/patryk/.conda/envs/venv/lib/python3.8/site-packages/torch/nn/_reduction.py:43: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
warnings.warn(warning.format(ret))
[epoch = 0][iter = 1][total_loss = inf][loss_au_softmax = 0.352187][loss_au_dice = 0.482275][loss_land = inf][loss_attention_refine = 8.406529]
learning rate = 0.010000 0.010000 0.020000 0.010000 0.010000 0.010000
the number of training iterations is 1

Traceback (most recent call last):
File "/home/patryk/git/PyTorch-JAANet/train_JAAv1.py", line 276, in
main(config)
File "/home/patryk/git/PyTorch-JAANet/train_JAAv1.py", line 197, in main
align_feat, align_output, aus_map = align_net(region_feat)
File "/home/patryk/.conda/envs/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "/home/patryk/git/PyTorch-JAANet/network.py", line 203, in forward
generate_map(aus_map[i,0], self.crop_size, self.map_size+8, self.spatial_ratio, self.fill_coeff,
File "/home/patryk/git/PyTorch-JAANet/network.py", line 166, in generate_map
for h in range(int(start_h), int(end_h)+1):
ValueError: cannot convert float NaN to integer

Process finished with exit code 1

I debugged it and it turned out that first conv layer in HierarchicalMultiScaleRegionLayer produces array with all Nans. (73rd line in network.py file)

Have you any ideas what's wrong?

DISFA AU_corr.txt template

Hi,
Thank you for your work. Could you please provide template for AU annotation file on disfa ( + 'AU_occur.txt'). Especially the order of columns.
Thank you in advance.

Training on more FACS poses?

Hi, and thank you for making this code available.

I see that the BP4D dataset used has 7 FACS poses. Is it possible to use this code to train on more poses? I would like to use a 30 pose FACS set.

Obviously I would need to annotate my own data.

Also, how does the speed and accuracy compare to the caffe version?

Thanks again!

Problem regarding to BP4D_combine_1_2_AUoccur.txt

Hello and thank you for shared code.
I am trying to run it on DISFA dataset (without BP4D) but I get an error according this file : BP4D_combine_1_2_AUoccur.txt which doesn't exist. Could you tell me what is this about and how can I solve it. The error is this :
imgs_AUoccur = np.loadtxt(list_path_prefix + 'BP4D_combine_1_2_AUoccur.txt')

Thank you very much!

The performance of DISFA dataset

Thank you very much for sharing your excellent work.
It's very helpful to me.
But I have some questions about this work.

  1. When I apply your pretrained model for DISFA, I got exactly the same performance as your paper (F1-score, Accuracy). But when I use your pretrained model for BP4D (part1, part3), f1-score mean and accuracy mean are 0.527 and 0.915, respectively. Was your pretrained model for DISFA trained after trained by whole BP4D dataset?

  2. When I apply your pretrained model for DISFA, mean error and failure rate are 4.85 and 1.00 respectively. Did I miss something?

  3. For DISFA, I got local f1 score mean 0.576 and local accuracy mean 0.935. The result of using local feature was not good, did you get the same result for DISFA?

Sorry to bother you, but I'd appreciate it if you could answer my question.

Training loss is decreasing while testing loss is increasing

Hi,

Thank you very much for sharing your codes. When I trained the model on BP4D dataset, I found the training loss is decreasing, both F1 score and Accuracy score are increasing. However, the testing loss is increasing, but the F1 score is increasing and the Accuracy score is decreasing. Is it normal? Did you have this problem? Thank you very much!

The performance of BP4D dataset

Hi~, firstly, thanks for opening your great work~, recently, we are working on FAU problems, and we follow your readme to train our model on BP4D dataset, but we can't get the result you said in IJCV version, we just got F1-frame about 0.6 in BP4D-part3.
Is there some tracks that you forget to write in Readme?
Thanks~

'all_pred_land' negative value appears

Hi:
First of all, thank you for your sharing.
I have a problem: When I run the test file test_JAAv1.py, 'all_pred_land' negative value appears, but landmark it can't be negative

License for using the repository

Dear Sir,
I am wondering if it would be possible to use the models from your github repo to build a new model for my research project? It seems that there is no license mentions here, so I am not sure what your rule about using your model for research purposes?
Thank you so much!
Tiankang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.