C++ forward network example on bvlc_reference_caffenet runs well on master, but fails layer_factory

4,434 views
Skip to first unread message

Brandon Amos

unread,
Dec 28, 2014, 2:40:08 PM12/28/14
to caffe...@googlegroups.com
Hi, I'm developing application code with the dev branch so I can use
locally connected layers provided by https://github.com/BVLC/caffe/pull/1271.
I want a C++ program to run an image forward through a trained network
and extract the last layer as a feature vector.

I've created a minimal example using the trained `bvlc_reference_caffenet`
My minimal example is uploaded as a gist at https://gist.github.com/67513f5322e67ce9f430.

The output on both branches is shown in `dev.out`
(commit 68b9b7bf7f4bf963145bc351d8cd829aa1dafe78) and
`master.out` (commit 475502835681862d0a1af26ac84a31533072f8da).
I've only modified `deploy.prototxt` across both branches to use a single blob
as input rather than 10, which is shown at the bottom of the
prototxt in the `.out` files.
`dev.out` results in the following error.


I1228 14:19:33.707913 19950 net.cpp:358] Input 0 -> data
I1228 14:19:33.707924 19950 layer_factory.hpp:78] Creating layer conv1
F1228 14:19:33.707938 19950 layer_factory.hpp:81] Check failed: registry.count(type) == 1 (0 vs. 1)
*** Check failure stack trace: ***
@ 0x7fb08fbf4e0d (unknown)
@ 0x7fb08fbf6cad (unknown)
@ 0x7fb08fbf49fc (unknown)
@ 0x7fb08fbf75ce (unknown)
@ 0x457b8d caffe::Net<>::Init()
@ 0x459261 caffe::Net<>::Net()
@ 0x409fe0 main
@ 0x7fb088b84040 __libc_start_main
@ 0x409e70 (unknown)


Do I need to further modify `test.cpp` or `deploy.prototxt`
to incorporate changes present in the dev branch?

Regards,
Brandon.

Brandon Amos

unread,
Jan 4, 2015, 1:21:00 AM1/4/15
to caffe...@googlegroups.com
Hi, I think I've resolved this error by linking my C++ program with
caffe's `.so` library rather than the `.a` library.
Why do the libraries behave differently?

Regards,
Brandon.

Kyaw Zaw Lin

unread,
Jan 8, 2015, 6:33:34 AM1/8/15
to caffe...@googlegroups.com
I have run into the same issue and I think I found the root cause. The problem is due to the ways layers are registered. Somewhat like this case on stackoverflow http://stackoverflow.com/questions/805555/ld-linker-question-the-whole-archive-option. So if you are linking the static library, some of the object code do not get included(which include layer registration code).

The problem can be fixed by changing your linker flags to this. -Wl,--whole-archive libcaffe.a -Wl,--no-whole-archive

Evan Shelhamer

unread,
Jan 8, 2015, 8:37:23 AM1/8/15
to Kyaw Zaw Lin, caffe...@googlegroups.com
Yes, static linking requires the arguments mentioned because of layer registration. See the Makefile for the exact arguments when static linking with gcc or clang.
--
You received this message because you are subscribed to the Google Groups "Caffe Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caffe-users...@googlegroups.com.
To post to this group, send email to caffe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/caffe-users/3ba4959c-d4b4-402e-91f0-f56c6ffee5e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Caffe_User

unread,
Jan 14, 2015, 2:54:50 AM1/14/15
to caffe...@googlegroups.com
I faced this problem too! After carefully checking, I found that that's because I was not included the related compiling information about the function or module which gave me error information. And the problem gone while I updated the Makefile.

在 2014年12月29日星期一 UTC+8上午3:40:08,Brandon Amos写道:

Brandon Amos

unread,
Jan 14, 2015, 3:46:53 PM1/14/15
to caffe...@googlegroups.com, kzl.z...@gmail.com, shel...@eecs.berkeley.edu
Yes, static linking requires the arguments mentioned because of layer registration. See the Makefile for the exact arguments when static linking with gcc or clang.
Thanks, is this in the user documentation anywhere?
I think it's worth adding because the error message is misleading.

-Brandon.

Prithviraj Dhar

unread,
Oct 27, 2015, 6:14:02 AM10/27/15
to Caffe Users
I decided to implement GoogLenet using Caffe and used the code for TripletLossLayer mentioned here.  http://blog.csdn.net/tangwei2014/article/details/46812153 (Please see the translated version).  

The build was successful. But when I started training GoogleNet, ( ./build/tools/caffe train --solver=models/bvlc_googlenet/solver.prototxt), I got the following error:

F1027 13:23:14.327160 18036 layer_factory.hpp:77] Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: TripletLossLayer (known types: AbsVal, Accuracy, ArgMax, BNLL, Concat, ContrastiveLoss, Convolution, Data, Deconvolution, Dropout, DummyData, Eltwise, EuclideanLoss, Exp, Flatten, HDF5Data, HDF5Output, HingeLoss, Im2col, ImageData, InfogainLoss, InnerProduct, LRN, MVN, MemoryData, MultinomialLogisticLoss, Pooling, Power, ReLU, Sigmoid, SigmoidCrossEntropyLoss, Silence, Slice, Softmax, SoftmaxWithLoss, Split, TanH, Threshold, TripletLoss, WindowData)
*** Check failure stack trace: ***
    @     0x7ff4e045adaa  (unknown)
    @     0x7ff4e045ace4  (unknown)
    @     0x7ff4e045a6e6  (unknown)
    @     0x7ff4e045d687  (unknown)
    @     0x7ff4e07b5ae5  caffe::LayerRegistry<>::CreateLayer()
    @     0x7ff4e07bac91  caffe::Net<>::Init()
    @     0x7ff4e07bc9f2  caffe::Net<>::Net()
    @     0x7ff4e079a6a0  caffe::Solver<>::InitTrainNet()
    @     0x7ff4e079b673  caffe::Solver<>::Init()
    @     0x7ff4e079b846  caffe::Solver<>::Solver()
    @           0x40a170  caffe::GetSolver<>()
    @           0x4060a4  train()
    @           0x403fe1  main
    @     0x7ff4df96bec5  (unknown)
    @           0x404bf6  (unknown)
    @              (nil)  (unknown)
Aborted (core dumped)
 Could you please help me with this error? I have attached the train_val.prototxt.

I'm following this blog post also. http://chrischoy.github.io/blog/research/making-caffe-layer/  But I'm not able to understand how to modify layer_factory.cpp (File 2) and vision_layers.hpp or common_layers.cpp (File 3). 

Could you please help me with this issue?
train_val.prototxt

细胞核

unread,
Oct 28, 2015, 4:57:44 AM10/28/15
to Caffe Users
I used the same code ,met the same problems . thanks for the Wl --whole-archive method.  

but after that , new questions comes.

probably the same as  Prithviraj Dhar

anyone can help me ?

F1028 16:46:23.090169  9277 layer_factory.hpp:80] Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Dropout (known types: Concat, Convolution, Eltwise, InnerProduct, LRN, PReLU, Pooling, Power, ReLU, Sigmoid, Softmax, Split, TanH)
*** Check failure stack trace: ***
    @     0x7f95b14805ed  google::LogMessage::Fail()
    @     0x7f95b1484a87  google::LogMessage::SendToLog()
    @     0x7f95b14828e9  google::LogMessage::Flush()
    @     0x7f95b1482bed  google::LogMessageFatal::~LogMessageFatal()
    @     0x7f95b18341aa  caffe::LayerRegistry<>::CreateLayer()
    @     0x7f95b183caba  caffe::Net<>::Init()
    @     0x7f95b183ef77  caffe::Net<>::Net()
    @     0x7f95b17c3656  AliscIntf::extract()
    @           0x4636af  main
    @       0x3ac821ed1d  (unknown)
    @           0x463389  (unknown)

在 2014年12月29日星期一 UTC+8上午3:40:08,Brandon Amos写道:
Hi, I'm developing application code with the dev branch so I can use
Reply all
Reply to author
Forward
0 new messages