MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / CopyTrainedLayersFrom

Method CopyTrainedLayersFrom

rtpose_wrapper/src/caffe/net.cpp:750–785  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

748
749template <typename Dtype>
750void Net<Dtype>::CopyTrainedLayersFrom(const NetParameter& param) {
751 int num_source_layers = param.layer_size();
752 for (int i = 0; i < num_source_layers; ++i) {
753 const LayerParameter& source_layer = param.layer(i);
754 const string& source_layer_name = source_layer.name();
755 int target_layer_id = 0;
756 while (target_layer_id != layer_names_.size() &&
757 layer_names_[target_layer_id] != source_layer_name) {
758 ++target_layer_id;
759 }
760 if (target_layer_id == layer_names_.size()) {
761 LOG(INFO) << "Ignoring source layer " << source_layer_name;
762 continue;
763 }
764 DLOG(INFO) << "Copying source layer " << source_layer_name;
765 vector<shared_ptr<Blob<Dtype> > >& target_blobs =
766 layers_[target_layer_id]->blobs();
767 CHECK_EQ(target_blobs.size(), source_layer.blobs_size())
768 << "Incompatible number of blobs for layer " << source_layer_name;
769 for (int j = 0; j < target_blobs.size(); ++j) {
770 if (!target_blobs[j]->ShapeEquals(source_layer.blobs(j))) {
771 Blob<Dtype> source_blob;
772 const bool kReshape = true;
773 source_blob.FromProto(source_layer.blobs(j), kReshape);
774 LOG(FATAL) << "Cannot copy param " << j << " weights from layer '"
775 << source_layer_name << "'; shape mismatch. Source param shape is "
776 << source_blob.shape_string() << "; target param shape is "
777 << target_blobs[j]->shape_string() << ". "
778 << "To learn this layer's parameters from scratch rather than "
779 << "copying from a saved net, rename the layer.";
780 }
781 const bool kReshape = false;
782 target_blobs[j]->FromProto(source_layer.blobs(j), kReshape);
783 }
784 }
785}
786
787template <typename Dtype>
788void Net<Dtype>::CopyTrainedLayersFrom(const string trained_filename) {

Callers 10

CopyLayersFunction · 0.80
testFunction · 0.80
Net_InitFunction · 0.80
Net_Init_LoadFunction · 0.80
warmupFunction · 0.80
TYPED_TESTFunction · 0.80
net_copy_fromFunction · 0.80

Calls 4

ShapeEqualsMethod · 0.80
FromProtoMethod · 0.80
shape_stringMethod · 0.80
sizeMethod · 0.45

Tested by 1

TYPED_TESTFunction · 0.64