How to train caffe model with grayscale images?

316 views
Skip to first unread message

Ali MassahKiani

unread,
Aug 19, 2017, 5:48:48 AM8/19/17
to Caffe Users

I have caffe model trained with RGB images. The file size is 300 MB. For speed reasons, i want train this model with grayscale images.

I converted all images to gray and set flag --gray=true to create my gray database but when I retrain the previous network with new gray data, the network is of the size same as old model (300 MB) while my LMDB train and test database is one-third (1/3) than that of the previous databases.

Why is the new model size still 300MB ?

How can i reduce it?

I think caffe still train with 3 channel that make same size model. There is flag in prototxt definition forces to 1 channel train?

Atena Nguyen

unread,
Aug 23, 2017, 4:04:57 AM8/23/17
to Caffe Users
The only different between training gray vs color is your first layer. 

Assuming you use CNN, with M output features. Then the number of parameters you saved compared to the gray image is (NxNx3)xM - (NxNx3)xM = (NxNx2)*M where N is your kernel size. 

In addition, for Deep CNN network, researchers show that the most memory consumption comes from the very first layer while the most parameters are in the late layer. Please see Lecture 7 in CS231n_2016, Stanford course. 
I attach the slide for your information. 

Therefore, you will not benefit much from storage size reduction by switching to training gray image, especially for a very deep neural network. 

 Hope it helps. 

Vào 18:48:48 UTC+9 Thứ Bảy, ngày 19 tháng 8 năm 2017, Ali MassahKiani đã viết:
Untitled.png

Atena Nguyen

unread,
Aug 23, 2017, 4:08:01 AM8/23/17
to Caffe Users
In the example that I posted, if you switch into gray scale training, you only save (3*3*2)*64 = 1152 parameters which account for approximate 8.35*e-4 %. 

Reply all
Reply to author
Forward
0 new messages