3

I am trying to extract features using caffenet.caffemodel. I implement extract_features.cpp in Visual Studio. My caffe library is also build as static library and link to extract_features.exe. When I run the code, I have error as

E0906 02:10:00.842056  4356 extract_features.cpp:74] Using CPU
F0906 02:10:04.035171  4356 layer_factory.hpp:88] Check failed: registry.count(t
ype) == 1 (0 vs. 1) Unknown layer type: ImageData (known types: )
*** Check failure stack trace: ***

The error happens at layer_factory.hpp

static shared_ptr<Layer<Dtype> > CreateLayer(const LayerParameter& param)
     {
    if (Caffe::root_solver()) {
      LOG(INFO) << "Creating layer " << param.name();
    }
    const string& type = param.type();
    CreatorRegistry& registry = Registry();
    CHECK_EQ(registry.count(type), 1) << "Unknown layer type: " << type
        << " (known types: " << LayerTypeListString() << ")";
    return registry[type](param);
  }

Initially was I thought Link error. Now I look more carefully and realized that not linker issue. What could be the error?

Shai
  • 111,146
  • 38
  • 238
  • 371
batuman
  • 7,066
  • 26
  • 107
  • 229
  • I think the problem is that you have caffe as static library. I recall similar issue in mac-os, you'll have to dig there for a solution. – Shai Sep 06 '15 at 05:18
  • Yeah they (http://stackoverflow.com/questions/30325108/caffe-layer-creation-failure) also have the same issue and considered static library problem as layer registration code is not included in linking. But in debugging, I can run through all those source code inside layer_factory.hpp. Thanks I'll dig into that. – batuman Sep 06 '15 at 17:46
  • running through code in header files during debug does not necessarily means it is available in release. – Shai Sep 07 '15 at 08:38

2 Answers2

3

I've met recently familiar problem to run my applicatin that has been linked with static library of Caffe (compiled in Visual Studio). There I've found 2 different solutions:

  1. Add Caffe project to your solution and set the next option in your main project:

    Project properties -> Common Properties -> Framework and References -> Caffe -> Use Library Dependency Inputs -> True

This method is simple, but sometimes we want to use only caffe.lib without project and here comes the 2nd method.

  1. Create header files in your project and add there all layer classes declarations externally to oblige a linker to use their symbols. See an example below:

Example

#include "caffe/common.hpp"
namespace caffe
{
    extern INSTANTIATE_CLASS(ConvolutionLayer);
    extern INSTANTIATE_CLASS(PoolingLayer);
    extern INSTANTIATE_CLASS(ReLULayer);
    extern INSTANTIATE_CLASS(TanHLayer);
}

Finally include the very header file in your application where you're using caffe.

Also check the Layer you met mentioned in your problem, for instance, in your case it is "ImageData" (or to be more corrected ImageDataLayer), open "image_data_layer.cpp" file in VS and check there that "REGISTER_LAYER_CLASS(ImageData);" is available there.

Hope it will help to solve the problem.

Community
  • 1
  • 1
vvvs
  • 31
  • 4
0

make sure your caffe is compiled with opencv

yihui.dev
  • 602
  • 8
  • 10