View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

4.7 | 7 ratings Rate this file 94 Downloads (last 30 days) File Size: 1.06 MB File ID: #25247 Version: 1.4
image thumbnail




06 Sep 2009 (Updated )

myCNN is a Matlab implementation of convolutional neural network (CNN).

| Watch this File

File Information

The first CNN appeared in the work of Fukushima in 1980 and was called Neocognitron. The basic architectural ideas behind the CNN (local receptive fields,shared weights, and spatial or temporal subsampling) allow such networks to achieve some degree of shift and deformation invariance and at the same time reduce the number of training parameters.
Since 1989, Yann LeCun and co-workers have introduced a series of CNNs with the general name LeNet, which contrary to the Neocognitron use supervised training. In this case, the major advantage is that the whole network is optimized for the given task, making this approach useable for real-world applications.
LeNet has been successfully applied to character recognition, generic object recognition, face detection and pose estimation, obstacle avoidance in an autonomous robot etc.
myCNN class allows to create, train and test generic convolutional networks (e.g., LeNet) as well as more general networks with features:
- any directed acyclic graph can be used for connecting the layers of the network;
- the network can have any number of arbitrarily sized input and output layers;
- the neuron’s receptive field (RF) can have an arbitrary stride (step of local RF tiling), which means that in the S-layer, RFs can overlap and in the C-layer the stride can differ from 1;
- any layer or feature map of the network can be switched from trainable to nontrainable (and vice versa) mode even during the training;
- a new layer type: softmax-like M-layer.
The archive contains the myCNN class source (with comments) and a simple example of LeNet5 creation and training.

All updates and new releases can be found here:


Cnn Convolutional Neural Network Class inspired this file.

MATLAB release MATLAB 7.2 (R2006a)
Other requirements For the proper training, the example needs the MNIST dataset, which can be downloaded from Yann LeCun's website or, in Matlab format, from my web page
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
29 Feb 2016 eason YI

06 Nov 2015 Josh

Josh (view profile)

Hi, I tried working with this code. It is a commendable effort. I am able to see the code work fine for the handwritten application. However, when i try to solve one of my problem on the code, it pops out an error. Basically, the output of the network is not obtained. I tried debugging, and I see that at the fourth layer (second step of convolution), there is no output. Please help me with this.

Comment only
13 Oct 2015 Mat Labber

18 Oct 2011 ben kamy

Can any one tell me is it possible to implement face recognition application using neural networks cNN with eigenfaces i don knw muchh abt cNn . if possible please
send me a reply..

Comment only
17 Dec 2010 syaiza syaiza

hi,i need to know how to insert alphabet characters (A-Z) into your code besides numeric characters (0-9). Any suggestions?

Comment only
25 Oct 2010 José Méndez


I'm testing your implementation for doing some work on face recognition. But I have to use more than 10 classes. I wonder if you can help me doing this modification on the code. I have been studying the code this day but I can't find where to modify for using 40 classes. I hope you can help me, please.


27 Jan 2010 Evgeniy Mzokov

You did a great job! Thanks )

16 Nov 2009 Ryan

Ryan (view profile)

This requires the NN toolbox and this should be mentioned. For example, mapstd() is a function from this toolbox which is used.

26 Oct 2009 Amiin

Amiin (view profile)

09 Oct 2009 Nikolay Chumerin

[to Birkan Tunc]
Thank you for your response. Concerning your question...
The problem is in the way how the standard 2D convolution is done. Usually, when you convolve a matrix A (of format let say N-by-M) with a kernel k (of format n-by-m where n<=N and m<=M) you get a result C of format (N+n-1)-by-(M-m+1).
So, all kernels, except scalars (1-by-1), produce convolution result of format less then convolved matrix (A). Of course, you can use 'same' parameter in conv2 matlab function (e.g.
>> C = conv2(A, k, 'same');
and you will get the result of the same format as input (size(C) == size(A)).
But in this case you need to adapt the training routines as well. Theoretically it's a piece of cake, but technically it's not a trivial task (one has to properly handle borders during the backward convolution). Anyway, you can try. It would be nice to see the results of your work.

Comment only
08 Oct 2009 Birkan Tunc

I have a few questions: I need a CNN for image processing instead of classification. That means I feed the network with an image and want get another image as the single output with the same size of input. How can I manage that? Is it possible by making simple modification to this code? Are there any references for this kind of CNNs?

I'll appreciate any kind of help

Comment only
02 Oct 2009 Mihail Sirotenko

Mihail Sirotenko (view profile)

  • 1 file
  • 4.94444

A respectable job have been done in this realization of CNN. There's a progress in comparison with my version. Particularly more flexible architecture of CNN, ability to make an arbitrary dimentions of kernel weight and other usefull things.

09 Sep 2009 1.1

- fixed some bugs related to system dependencies;
- added ChangeLog and content.m;
- more comments in the example.

23 Sep 2009 1.2

see ChangeLog inside the archive.

28 Sep 2009 1.3

- the first attempt to make the M-layer trainable
- a new private functions unfold.m and unfold2.m added
- soft_max now suppots n-dimensional array (not only 2D and 3D)
- improved myCNN object description

30 Sep 2009 1.4

- a graphical demo (demo_myCNN) added (thanks to Mikhail Sitotenko, submission 24291)
  - an example of pretrained network (myLeNet5-example.mat) added
  - the myCNN constructor is fixed (loading from file)

Contact us