File Exchange

image thumbnail

Two stream CNN for biometric recognition

version (350 KB) by Mahmoud Afifi
Implementation of our paper "11K Hands: Gender recognition and biometric identification using hand images"


Updated 01 Jun 2019

GitHub view license on GitHub

This is the Matlab implementation of the paper:
Mahmoud Afifi, "11K Hands: Gender recognition and biometric identification using a large dataset of hand images." Multimedia Tools and Applications, 2019.
Please cite the following work if you use the provided source code, pre-trained models, or the dataset:
Mahmoud Afifi, "11K Hands: Gender recognition and biometric identification using a large dataset of hand images." Multimedia Tools and Applications, 2019
Project webpage:

Cite As

Afifi, Mahmoud. “11K Hands: Gender Recognition and Biometric Identification Using a Large Dataset of Hand Images.” Multimedia Tools and Applications, Springer Nature, Mar. 2019, doi:10.1007/s11042-019-7424-8.

View more styles

Comments and Ratings (21)


@mohamed you may think of using custom trainig loop, you will have all control
Check this

what about sequence input (lstm) how can we use mutiple inputs?

@getnet You can write your own function to prepare the training data. The given code expects input images in .tif format, where each image is 4-channels (3 color channel image for the first stream, and a single channel for the second stream).

@Keke Sorry for the late reply. But I guess it is another problem, my architecture is just for image classification.

Dear how are you? your implementation and the paper is clear but somewhat in the "get_data.mat" how can i retrieve my own data so as to use your model for classification

Keke Zhang

Hi, thanks for your effort. But when training a faster rcnn, the trainingdata must be a table file, where the first column must contain paths and file names to grayscale or truecolor (RGB) images. The remaining columns must contain bounding boxes related to the corresponding image. I tried some methods but failed to feed two different data into a network. Can you give some suggestions?

Yuze Zou

It's really helpful. Thank you very much.

@azza elbagoury: check my answer here
I gave an example of how to split two stacked images via conv layers with no learning rate. Hope it would help.

For "second-stream" what if the input will be 3-channels, to fully utilize the pretrained AlexNet weights. This is done by converting the detailed image (I) to grayscale 3-channels image, by concatenating three copies of the original matrix along the third dimension [cat(3,I,I,I)].
which of the two cases are better for pretrained deep convolution network: The input is 1-channel OR the input is 3-channels (All 3-channels are same).
Regardless the issue of input which will be 6D tensor.

@azza elbagoury: yes you can. But you need to modify it based on your architecture for segmentation. You can use the same idea of using tiff images to store input for two streams and split them by the first conv layer. Then, you can do whatever you want for segmentation.

Many thanks for your great effort.
Could this "two stream" model be modified to segmentation task instead of classification?

@mohamed attia: when you call plot(lgraph), you can see the final form of the network which has two skipConv layers (skipConv1 and skipConv2). The idea is that, I constructed the two input images together as a 4D tensor. So, first 3 layers are for the RGB input image (first stream) and the last layer is for the grayscale image (second stream). skinpConv1 and skipConv2 have zeros in the corresponding layer to split the input into two different inputs (RGB image and grayscale image). Then each stream will be fed with the corresponding input.

Great work, thanks for your effort.
In twoStreams.m you have arranged the layers of net1 and net2 sequentially, where layer(26) 'relu1_2' is taking the output of layer(25) 'fc9_1' as its input.
Isn't this suppose to be two parallel streams? where layer(25) is the last layer in net1 and layer(26) is the first layer in net2.


Did you use Matlab 2016a or higher? The activations function is introduced starting from Matlab 2016a ( I have checked the code again and it is working!


Got an error in get_all_features.m. The errors are as follows:
> In get_all_features (line 20)
Undefined function or variable 'activations'.

Error in getfeatures (line 29)
features.low = reshape ( activations(net, testingImage, featureLayer),[1,531]);

Error in get_all_features (line 28)
please help. Thanks in advance.

Aasma Aslam

Really good effort and help for the others

M Shannon

Great work!


title updated

connected to GitHub repository

preprocessing function is updated


Reference paper was updated.



Paper title was updated

bug fixed in demo.m file

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux