Check failed: registry.count(t ype) == 1 (0 vs. 1) Unknown layer type: Input (known types: Input )

转自博客 http://www.tk4479.net/birdwcp/article/details/53580068

自己建立一个工程,调用libcaffe.lib ,成功编译,但是运行就会遇到报错
F0519 14:54:12.494139 14504 layer_factory.hpp:77] Check failed: registry.count(t ype) == 1 (0 vs. 1) Unknown layer type: Input (known types: Input )

按网上的方法,解决这个问题可以新建一个头文件,在用到的地方包含这个头文件,内容例如下面,运行时报Unknown哪层就往里面添加那层。

#ifndef CAFFE_REG_H
#define CAFFE_REG_H

#include "caffe/common.hpp"  
#include "caffe/layers/input_layer.hpp"  
#include "caffe/layers/inner_product_layer.hpp"  
#include "caffe/layers/dropout_layer.hpp"  
#include "caffe/layers/conv_layer.hpp"  
#include "caffe/layers/relu_layer.hpp"  

#include "caffe/layers/pooling_layer.hpp"  
#include "caffe/layers/lrn_layer.hpp"  
#include "caffe/layers/softmax_layer.hpp"  
#include "caffe/layers/normalize_layer.hpp"
#include "caffe/layers/permute_layer.hpp"
#include "caffe/layers/flatten_layer.hpp"
#include "caffe/layers/prior_box_layer.hpp"
#include "caffe/layers/concat_layer.hpp"
#include "caffe/layers/reshape_layer.hpp"
#include "caffe/layers/softmax_layer.hpp"
#include "caffe/layers/detection_output_layer.hpp"


namespace caffe
{
extern INSTANTIATE_CLASS(InputLayer);
extern INSTANTIATE_CLASS(ConvolutionLayer);
REGISTER_LAYER_CLASS(Convolution);
extern INSTANTIATE_CLASS(InnerProductLayer);
extern INSTANTIATE_CLASS(DropoutLayer);

extern INSTANTIATE_CLASS(ReLULayer);
REGISTER_LAYER_CLASS(ReLU);
extern INSTANTIATE_CLASS(PoolingLayer);
REGISTER_LAYER_CLASS(Pooling);
extern INSTANTIATE_CLASS(LRNLayer);
//REGISTER_LAYER_CLASS(LRN);
extern INSTANTIATE_CLASS(SoftmaxLayer);
//REGISTER_LAYER_CLASS(Softmax);
extern INSTANTIATE_CLASS(NormalizeLayer);
//REGISTER_LAYER_CLASS(Normalize);
extern INSTANTIATE_CLASS(PermuteLayer);
//REGISTER_LAYER_CLASS(Permute);
extern INSTANTIATE_CLASS(FlattenLayer);
extern INSTANTIATE_CLASS(PriorBoxLayer);
extern INSTANTIATE_CLASS(ConcatLayer);
extern INSTANTIATE_CLASS(ReshapeLayer);
extern INSTANTIATE_CLASS(SoftmaxLayer);
REGISTER_LAYER_CLASS(Softmax);
extern INSTANTIATE_CLASS(DetectionOutputLayer);
}

#endif

这时还会遇到一个麻烦的问题,添加了REGISTER_LAYER_CLASS()他会报重复注册,去掉这一句又报不认识这一层。
在layer_factory.hpp里做如下更改可以解决这个问题:

把static void AddCreator(const string& type, Creator creator){}里的:

    CHECK_EQ(registry.count(type), 0)<< "Layer type " << type << " already registered.";
    registry[type] = creator;

改为:

if (registry.count(type) != 0) {
    std::cout<< "Layer type " << type << " already registered.     ";
} else {
    registry[type] = creator;
}

这样就能确保只注册一次了。

你可能感兴趣的:(深度学习,caffe)