facebookarchive / C3D

C3D is a modified version of BVLC caffe to support 3D ConvNets.
Other
1.16k stars 506 forks source link

Can the weights of a pretrained model be transferred to a new model? #246

Open youssefoumate opened 7 years ago

youssefoumate commented 7 years ago

Hi Sir, As a first part of my project, I have to transfer the weights of the three first 3D convolutional layers of a pretrained model (conv3d_deepnetA_sport1m_iter_1900000 for example) to a new model, is it possible to do that in C3D ?

dutran commented 7 years ago

can you explain more detail of your need? If that mean fine-tune another net that initializes weights only from the first few layers of C3D, then the answer is yes.

youssefoumate commented 7 years ago

Thank you for your reply Sir, Yes, I think this is a fine-tuning problem. Actually I want to do something similar to what MDNet did to prepare their model, something like this :

**% conv1-3 layers from VGG-M network pretrained on ImageNet src_model = './models/imagenet-vgg-m-conv1-3.mat';

% output network dst_model = './models/mdnet_init.mat';

if exist(dst_model,'file') return; end

%% load conv layers load(src_model);

new_layers = {}; for i=1:numel(layers) if strcmp(layers{i}.name,'conv4'), break; end switch (layers{i}.type) case 'conv' layers{i}.filters = layers{i}.weights{1}; layers{i}.biases = layers{i}.weights{2}; layers{i} = rmfield(layers{i},'weights'); layers{i}.pad = 0; last_dim = size(layers{i}.biases,2); case 'pool' layers{i}.pad = 0; end new_layers{end+1} = layers{i}; end**