Error making a prediction in C++

3,934 views
Skip to first unread message

Sebastian Sierra

unread,
Oct 22, 2014, 3:13:59 PM10/22/14
to caffe...@googlegroups.com
Hi, I am working doing predictions in C++ using the following code
#include <glog/logging.h>
...
#include "caffe/caffe.hpp"
  using namespace caffe;

int main(int argc, char** argv) {
  Net<float> caffe_test_net(argv[1]);
  caffe_test_net.CopyTrainedLayersFrom(argv[2]);
  float loss;
  const vector<Blob<float>*>& result =  caffe_test_net.ForwardPrefilled(&loss);

 const float* argmaxs = result[0]->cpu_data();
  for (int i = 0; i < result[0]->num(); ++i) {
   LOG(INFO) << " Image: "<< i << " class:" << argmaxs[i];
  }
return 0;
}

This was based mainly on a Github thread 499. However this was done with a previous version of Caffe and therefore I am getting the following errors while compiling with actual version in master:
/tmp/ccxqR1yE.o: In function `main':
prediction.cpp:(.text+0x64): undefined reference to `caffe::Net<float>::Net(std::string const&)'
prediction.cpp:(.text+0xd1): undefined reference to `caffe::Net<float>::CopyTrainedLayersFrom(std::string)'
prediction.cpp:(.text+0x108): undefined reference to `caffe::Net<float>::ForwardPrefilled(float*)'
prediction.cpp:(.text+0x12e): undefined reference to `caffe::Blob<float>::cpu_data() const'
prediction.cpp:(.text+0x179): undefined reference to `google::LogMessage::LogMessage(char const*, int)'
prediction.cpp:(.text+0x188): undefined reference to `google::LogMessage::stream()'
prediction.cpp:(.text+0x1d7): undefined reference to `google::LogMessage::~LogMessage()'
prediction.cpp:(.text+0x2a8): undefined reference to `google::LogMessage::~LogMessage()'
collect2: error: ld returned 1 exit status

I wanted to know if there is a mistake in my syntaxis or what should I change?
Thanks in advance.

mingcong song

unread,
Oct 24, 2014, 12:34:49 AM10/24/14
to caffe...@googlegroups.com
I also encounter this error. Could you tell me how to write Makefile?

在 2014年10月22日星期三UTC-4下午3时13分59秒,Sebastian Sierra写道:

Seungyeop Han

unread,
Nov 13, 2014, 10:29:39 PM11/13/14
to caffe...@googlegroups.com
Did you link caffe library and glog in compiling?

Caffe User

unread,
Dec 20, 2014, 7:44:43 PM12/20/14
to caffe...@googlegroups.com
Hello. I am having the same problem with running .cpp file. 
If you figured out, could you help me? Did you make makefile for this?
Thank you! 

ikki Chung

unread,
Jan 20, 2015, 11:03:55 PM1/20/15
to caffe...@googlegroups.com

Maybe you can try this steps.

The base idea is to create you code on caffe master directories. 


Caffe User於 2014年12月21日星期日 UTC+8上午8時44分43秒寫道:

Bartosz Ludwiczuk

unread,
Mar 2, 2015, 6:25:14 AM3/2/15
to caffe...@googlegroups.com
Here us Makefile which I use to compile C++ code, which use Caffe. You have to change directories pointing to Caffe include/lib
CXX=g++
CFLAGS=-c -Wall -std=c++0x -g3 -Ofast -msse2  -I. -I/usr/local/cuda/include -I/home/blcv/LIB/caffe_bn/include/ -I/home/blcv/LIB/caffe_bn/src/
LDFLAGS= -L/usr/local/lib -L/usr/local/cuda/lib64 -L/usr/local/cuda/lib -lcudart -lcublas -lcurand -lglog -lgflags -lprotobuf -lleveldb -lsnappy -llmdb -lboost_system -lhdf5_hl -lhdf5 -lm -lopencv_core -lopencv_highgui -lopencv_imgproc -lboost_thread -lstdc++ -lcudnn -lcblas -latlas -L/home/blcv/LIB/caffe_bn/build/lib/ -lcaffe -lproto
SOURCES=${wildcard *.cpp }
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=predict

all:  $(SOURCES) $(EXECUTABLE)


clean:
rm -f *.o
rm -f $(EXECUTABLE)
find ./ -name \*.o  -delete

$(EXECUTABLE): $(OBJECTS)
$(CXX) $(OBJECTS) $(LDFLAGS) -o $@

.cpp.o:
$(CXX) $(CFLAGS) $< -o $@


Vasant Srinivasan

unread,
Mar 19, 2015, 12:42:57 PM3/19/15
to caffe...@googlegroups.com
Hello,

I am having problem compiling c++ code outside of caffe (inside the caffe main directories works fine!). I wrote my own Makefile and since that didn't seem to work, I even tried the one Bartosz provided. I keep getting these does not name a type errors (attached below). I have a feeling this has to do with the Makefile. Is there something I am supposed to be doing that I am not? Any help would be deeply appreciated.

Thanks!
Vasant

Error Msgs -

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:27: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:27: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:32: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::NeuronLayer<Dtype>::NeuronLayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:28: error: ‘param’ was not declared in this scope

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:52: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:52: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:57: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::AbsValLayer<Dtype>::AbsValLayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:53: error: ‘param’ was not declared in this scope

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:113: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:113: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:116: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::BNLLLayer<Dtype>::BNLLLayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:114: error: ‘param’ was not declared in this scope

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:169: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:169: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:176: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::DropoutLayer<Dtype>::DropoutLayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:170: error: ‘param’ was not declared in this scope

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:230: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:230: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:235: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::PowerLayer<Dtype>::PowerLayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:231: error: ‘param’ was not declared in this scope

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:303: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:303: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:306: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::ReLULayer<Dtype>::ReLULayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:304: error: ‘param’ was not declared in this scope

In file included from ../caffe/include/caffe/loss_layers.hpp:11,

                 from ../caffe/include/caffe/common_layers.hpp:12,

                 from ../caffe/include/caffe/vision_layers.hpp:10,

                 from ../caffe/include/caffe/caffe.hpp:16,

                 from prediction_example.cpp:8:

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:399: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:399: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:402: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::SigmoidLayer<Dtype>::SigmoidLayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:400: error: ‘param’ was not declared in this scope

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:483: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:483: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:486: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::TanHLayer<Dtype>::TanHLayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:484: error: ‘param’ was not declared in this scope

../caffe/include/caffe/neuron_layers.hpp: At global scope:

../caffe/include/caffe/neuron_layers.hpp:571: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/neuron_layers.hpp:571: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/neuron_layers.hpp:576: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/neuron_layers.hpp: In constructor ‘caffe::ThresholdLayer<Dtype>::ThresholdLayer(int)’:

../caffe/include/caffe/neuron_layers.hpp:572: error: ‘param’ was not declared in this scope

In file included from ../caffe/include/caffe/common_layers.hpp:12,

                 from ../caffe/include/caffe/vision_layers.hpp:10,

                 from ../caffe/include/caffe/caffe.hpp:16,

                 from prediction_example.cpp:8:

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:33: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:33: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp:40: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::AccuracyLayer<Dtype>::AccuracyLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:34: error: ‘param’ was not declared in this scope

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:98: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:98: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::LossLayer<Dtype>::LossLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:99: error: ‘param’ was not declared in this scope

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:151: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:151: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp:157: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::ContrastiveLossLayer<Dtype>::ContrastiveLossLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:152: error: ‘param’ was not declared in this scope

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:240: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:240: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp:245: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::EuclideanLossLayer<Dtype>::EuclideanLossLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:241: error: ‘param’ was not declared in this scope

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:351: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:351: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp:354: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::HingeLossLayer<Dtype>::HingeLossLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:352: error: ‘param’ was not declared in this scope

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:429: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:429: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp:443: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::InfogainLossLayer<Dtype>::InfogainLossLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:430: error: ‘param’ was not declared in this scope

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:522: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:522: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp:527: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::MultinomialLogisticLossLayer<Dtype>::MultinomialLogisticLossLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:523: error: ‘param’ was not declared in this scope

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:600: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:600: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp:609: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::SigmoidCrossEntropyLossLayer<Dtype>::SigmoidCrossEntropyLossLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:601: error: ‘param’ was not declared in this scope

../caffe/include/caffe/loss_layers.hpp: At global scope:

../caffe/include/caffe/loss_layers.hpp:699: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/loss_layers.hpp:699: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/loss_layers.hpp:707: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/loss_layers.hpp: In constructor ‘caffe::SoftmaxWithLossLayer<Dtype>::SoftmaxWithLossLayer(int)’:

../caffe/include/caffe/loss_layers.hpp:700: error: ‘param’ was not declared in this scope

In file included from ../caffe/include/caffe/vision_layers.hpp:10,

                 from ../caffe/include/caffe/caffe.hpp:16,

                 from prediction_example.cpp:8:

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:39: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:39: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:46: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::ArgMaxLayer<Dtype>::ArgMaxLayer(int)’:

../caffe/include/caffe/common_layers.hpp:40: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:82: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:82: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:89: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::ConcatLayer<Dtype>::ConcatLayer(int)’:

../caffe/include/caffe/common_layers.hpp:83: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:162: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:162: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:169: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp:185: error: ‘EltwiseParameter_EltwiseOp’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::EltwiseLayer<Dtype>::EltwiseLayer(int)’:

../caffe/include/caffe/common_layers.hpp:163: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:205: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:205: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:210: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::FlattenLayer<Dtype>::FlattenLayer(int)’:

../caffe/include/caffe/common_layers.hpp:206: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:256: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:256: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:263: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::InnerProductLayer<Dtype>::InnerProductLayer(int)’:

../caffe/include/caffe/common_layers.hpp:257: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:294: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:294: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:299: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::MVNLayer<Dtype>::MVNLayer(int)’:

../caffe/include/caffe/common_layers.hpp:295: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:328: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:328: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:333: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::SilenceLayer<Dtype>::SilenceLayer(int)’:

../caffe/include/caffe/common_layers.hpp:329: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:360: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:360: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:365: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::SoftmaxLayer<Dtype>::SoftmaxLayer(int)’:

../caffe/include/caffe/common_layers.hpp:361: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:424: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:424: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:429: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::SplitLayer<Dtype>::SplitLayer(int)’:

../caffe/include/caffe/common_layers.hpp:425: error: ‘param’ was not declared in this scope

../caffe/include/caffe/common_layers.hpp: At global scope:

../caffe/include/caffe/common_layers.hpp:457: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/common_layers.hpp:457: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/common_layers.hpp:464: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/common_layers.hpp: In constructor ‘caffe::SliceLayer<Dtype>::SliceLayer(int)’:

../caffe/include/caffe/common_layers.hpp:458: error: ‘param’ was not declared in this scope

In file included from ../caffe/include/caffe/caffe.hpp:16,

                 from prediction_example.cpp:8:

../caffe/include/caffe/vision_layers.hpp: At global scope:

../caffe/include/caffe/vision_layers.hpp:66: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/vision_layers.hpp:66: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/vision_layers.hpp:73: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/vision_layers.hpp: In constructor ‘caffe::ConvolutionLayer<Dtype>::ConvolutionLayer(int)’:

../caffe/include/caffe/vision_layers.hpp:67: error: ‘param’ was not declared in this scope

../caffe/include/caffe/vision_layers.hpp: At global scope:

../caffe/include/caffe/vision_layers.hpp:166: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/vision_layers.hpp:166: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/vision_layers.hpp:173: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/vision_layers.hpp: In constructor ‘caffe::Im2colLayer<Dtype>::Im2colLayer(int)’:

../caffe/include/caffe/vision_layers.hpp:167: error: ‘param’ was not declared in this scope

../caffe/include/caffe/vision_layers.hpp: At global scope:

../caffe/include/caffe/vision_layers.hpp:208: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/vision_layers.hpp:208: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/vision_layers.hpp:215: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/vision_layers.hpp: In constructor ‘caffe::LRNLayer<Dtype>::LRNLayer(int)’:

../caffe/include/caffe/vision_layers.hpp:209: error: ‘param’ was not declared in this scope

../caffe/include/caffe/vision_layers.hpp: At global scope:

../caffe/include/caffe/vision_layers.hpp:285: error: ISO C++ forbids declaration of ‘LayerParameter’ with no type

../caffe/include/caffe/vision_layers.hpp:285: error: expected ‘,’ or ‘...’ before ‘&’ token

../caffe/include/caffe/vision_layers.hpp:292: error: ‘LayerParameter_LayerType’ does not name a type

../caffe/include/caffe/vision_layers.hpp: In constructor ‘caffe::PoolingLayer<Dtype>::PoolingLayer(int)’:

../caffe/include/caffe/vision_layers.hpp:286: error: ‘param’ was not declared in this scope

../caffe/include/caffe/vision_layers.hpp: In member function ‘virtual int caffe::PoolingLayer<Dtype>::MaxTopBlobs() const’:

../caffe/include/caffe/vision_layers.hpp:301: error: ‘PoolingParameter_PoolMethod_MAX’ was not declared in this scope


Makefile Used - 


CXX=g++


CFLAGS=-c -Wall -std=c++0x -g3 -msse2  -I. -I/usr/local/cuda/include -I../caffe/include/ -I../caffe/src/

LDFLAGS= -L/usr/local/lib -L/usr/local/cuda/lib64 -L/usr/local/cuda/lib -lcudart -lcublas -lcurand -lglog -lgflags -lprotobuf -lleveldb -lsnappy -llmdb -lboost_system -lhdf$

Vasant Srinivasan

unread,
Mar 19, 2015, 12:47:20 PM3/19/15
to caffe...@googlegroups.com
Sorry about re-posting. The Makefile copy paste got cut off -

CXX=g++
CFLAGS=-c -Wall -std=c++0x -g3 -msse2 -I. -I/usr/local/cuda/include -I../caffe/include/ -I../caffe/src/
LDFLAGS= -L/usr/local/lib -L/usr/local/cuda/lib64 -L/usr/local/cuda/lib -lcudart -lcublas -lcurand -lglog -lgflags -lprotobuf -lleveldb -lsnappy -llmdb -lboost_system -lhdf5_hl -lhdf5 -lm -lopencv_core -lopencv_highgui -lopencv_imgproc -lboost_thread -lstdc++ -lcudnn -lcblas -latlas -L../caffe/build/lib/ -lcaffe -lproto
SOURCES=${wildcard *.cpp }
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=predict

all:  $(SOURCES) $(EXECUTABLE)


clean:
rm -f *.o
rm -f $(EXECUTABLE)
find ./ -name \*.o  -delete

$(EXECUTABLE): $(OBJECTS)
$(CXX) $(OBJECTS) $(LDFLAGS) -o $@

.cpp.o:
$(CXX) $(CFLAGS) $< -o $@


Caffe User

unread,
Mar 19, 2015, 3:39:04 PM3/19/15
to caffe...@googlegroups.com
Dear Caffe User, 

Hello. I am attaching my cpp file and makefile. I hope these helps!
Were you able to compile "make all" and "make test" successfully? 
Also, please make sure your bashrc file includes correct caffe version! 
 
Best Regards,

Dong Ki Kim

cpp file
// Libary
#include <cuda_runtime.h>
#include <stdio.h>
#include <stdlib.h> 
#include <cstdlib>
#include <string>
#include <fstream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <time.h>
#include "/home/dkkim930122/caffe-cudnn/include/caffe/caffe.hpp"
#include "/home/dkkim930122/caffe-cudnn/include/caffe/util/io.hpp"
#include "/home/dkkim930122/caffe-cudnn/include/caffe/blob.hpp"
#include "/usr/include/opencv2/core/core.hpp"
#include "/usr/include/opencv2/highgui/highgui.hpp"
#include "/usr/include/python2.7/Python.h"

using namespace caffe;
using namespace std; 

int main(int argc, char** argv) 
{
  // Set GPU
  Caffe::set_mode(Caffe::GPU);
  int device_id = 0;
  Caffe::SetDevice(device_id);
  LOG(INFO) << "Using GPU";
  
  // Load net
  Net<float> net("/home/dkkim930122/caffe-cudnn/include/exercise.prototxt", caffe::TEST);//<-- depends on caffe version

  // Load pre-trained net
  net.CopyTrainedLayersFrom("/home/dkkim930122/caffe-cudnn/examples/imagenet/caffe_reference_imagenet_model");

  // Load image
  cv::Mat image = cv::imread("/home/dkkim930122/caffe-dev/examples/images/1.jpg"); // or cat.jpg

  // Set vector for image
  vector<cv::Mat> imageVector;
  imageVector.push_back(image); // image is a cv::Mat, as I'm using #1416 //push_back()

  // Set vector for label
  vector<int> labelVector;
  labelVector.push_back(0);//push_back 0 for initialize purpose

  // Net initialization
  float loss = 0.0;

  shared_ptr<MemoryDataLayer<float> > memory_data_layer;

  memory_data_layer = boost::static_pointer_cast<MemoryDataLayer<float> >(net.layer_by_name("data"));

  memory_data_layer->AddMatVector(imageVector,labelVector);

  // Run ForwardPrefilled 
  vector<Blob<float>*> results = net.ForwardPrefilled(&loss);

  // Display result
  const shared_ptr<Blob<float> >& probs = net.blob_by_name("prob");
  const float* probs_out = probs->cpu_data();

  for (int i = 0 ; i < 3 ; i++) 
  {
    LOG(INFO) << "Prob" << i << ": " << probs_out[i];
  }

  LOG(INFO) << "Max element is: " << *max_element(probs_out,probs_out+3);

  // Display result2
  const float* argmaxs = results[1]->cpu_data();
  
  for (int i = 0; i < results[1]->num(); i++) 
  {
    for (int j = 0; j < results[1]->height(); j++) 
    {
      LOG(INFO) << "Image: "<< i << " class:" << argmaxs[i*results[1]->height() + j];
    }
  }

  //printf("%d\n",(int)*argmaxs);

  return 0;
}

makefile
CC=g++

CXXFLAGS = -O2 -Wall -D__STDC_CONSTANT_MACROS 

INCLUDE = -I/home/dkkim930122/caffe-cudnn/include \
   -I/home/dkkim930122/caffe-cudnn/src \
   -I/home/dkkim930122/caffe-cudnn \
   -I/usr/local/cuda/include \
   -I/home/dkkim930122/opencv-2.4.9/include \
   -I/usr/include/python2.7

LIBRARY = -L/usr/local/x86_64-linux-gnu/ -lprotobuf \
-L/usr/lib/x86_64-linux-gnu/ -lglog \
-L/usr/local/cuda/lib64/ -lcudart -lcublas -lcurand \
-L/usr/local/lib/ -lm -lpthread -lavutil -lavformat -lavcodec -lswscale -lopencv_core -lopencv_imgproc -lopencv_highgui \
-L/usr/lib/python2.7/config-x86_64-linux-gnu/ -lpython2.7 \
-L/sur/lib32/ -lrt \
-L../build/lib/ -lcaffe

all:
$(CC) $(INCLUDE) $(OBJS) exercise.cpp -o exercise $(LIBRARY)


Shravani Rao

unread,
Mar 24, 2015, 7:35:47 PM3/24/15
to caffe...@googlegroups.com
Hi Dong,

Thanks for sharing the files. I created my workspace outside caffe's master directory and ran a similar program. The execution stops at 'memory_data_layer->AddMatVector(imageVector,labelVector);'. The error msg I get is :

F0324 16:27:18.655103 26477 data_transformer.cpp:228] Check failed: img_height == data_mean_.height() (323 vs. 256)
*** Check failure stack trace: ***
Aborted (core dumped)

I am a new caffe and learning CNN. If you understand the error, I'd greatly appreciate your help.

Thank you :)

Caffe User

unread,
Mar 24, 2015, 7:45:07 PM3/24/15
to caffe...@googlegroups.com
Hello Shravani.

I think the error is saying that your input image height dimension (which is 323) does not equal to data mean height dimension (which is 256). 
If you are using imagenet data mean file, I believe the data mean file has a dimension of 256x256. Thus, I believe the imagenet CNN accepts 256x256 images (height 256) as input image. 
If you re-size your input image to 256x256 then the error message should go away. 

Best,

Dong Ki Kim

Shravani Rao

unread,
Mar 24, 2015, 8:18:30 PM3/24/15
to caffe...@googlegroups.com
Thanks for the quick response.

I though the model definition we used crops the images to 227 (but the error shows 323). If I am wrong, please correct me. Could you guide me on how to resize the input images.
transform_param
  {
    crop_size: 227
    mirror: false
    mean_file: "caffeMasterDir/data/ilsvrc12/imagenet_mean.binaryproto"
  }

I have used the mean file provided in  ..caffeMasterDir/data/ilsvrc12/imagenet_mean.binaryproto.

For the statement net.CopyTrainedLayersFrom("/home/dkkim930122/caffe-cudnn/examples/imagenet/caffe_reference_imagenet_model");  in your program, I instead used net.CopyTrainedLayersFrom("caffeMasterDir/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel");  .

I have downloaded bvlc_reference_caffenet.caffemodel from Model zoo.

Caffe User

unread,
Mar 24, 2015, 8:25:09 PM3/24/15
to caffe...@googlegroups.com
I think there could be many answers to this, but I personally use gimp program or use my personal program written in Python to re-size images to 256x256 BEFORE using Caffe. AFTER resizing input image to 256x256, I use Caffe. 
Hope this helps!

Vasant Srinivasan

unread,
Mar 24, 2015, 8:36:03 PM3/24/15
to Caffe User, caffe...@googlegroups.com
You could also use cv::size from opencv.


On Tue, Mar 24, 2015 at 7:25 PM, Caffe User <dk...@cornell.edu> wrote:
I think there could be many answers to this, but I personally use gimp program or use my personal program written in Python to re-size images to 256x256 BEFORE using Caffe. AFTER resizing input image to 256x256, I use Caffe. 
Hope this helps!

--
You received this message because you are subscribed to a topic in the Google Groups "Caffe Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/caffe-users/tMwpaf3s8GQ/unsubscribe.
To unsubscribe from this group and all its topics, 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/ac722ba8-6c57-45b7-a858-e354896a2058%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Shravani Rao

unread,
Mar 24, 2015, 10:42:57 PM3/24/15
to caffe...@googlegroups.com, dk...@cornell.edu
Ohh! so we manually resize the images! I thought there is a way to mention in the model definition (prototxt) file that the input images are to be cropped. what does the parameter crop-size:227 do?
I resized and it works well. The image fish-bike.jpg got mapped to class 770. Is there a way I could extract the real name of the class (like 'fish') . Could you point me to the file that has (label num - label name) information.
Thanks so much guys!!
Message has been deleted

s501082001

unread,
Feb 29, 2016, 9:22:29 PM2/29/16
to Caffe Users

Dear Dong Ki Kim, 

 

Hello. I'm the new in caffe, and I see your code and rewrite it.  As follows.



 
  But I got an error .


error: 'class caffe::MemoryDataLayer<float>' has no member named 'AddMatVector'   

memory_data_layer->AddMatVector(imageVector,labelVector);
                        ^      

    File not found: /home/server/test/mainwindow.cpp


I confirmed the function(AddMatVector) in the file , memory_data_layer.hpp.

   
 

could you help me? 

 

If my description is not clear enough, I will make it clearly. Thank you.

envirnment: Ubuntu 14.04 


Development Platform:Qt Creator


 


#include <cstdlib>
#include <vector>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <time.h>

#include "/home/server/桌面/caffe-master/include/caffe/caffe.hpp"
#include "/home/server/
桌面/caffe-master/include/caffe/util/io.hpp"
#include "/home/server/
桌面/caffe-master/include/caffe/blob.hpp"


#include  "opencv2/core/core.hpp"
#include  "opencv2/imgproc/imgproc.hpp"
#include  "opencv2/imgproc/imgproc_c.h"
#include  "opencv/cv.h"
#include  "opencv/cxcore.h"
#include  "opencv/highgui.h"
//#include  "/home/server/
桌面/opencv-2.4.10/include/opencv/cv.h"
//#include  "/home/server/
桌面/opencv-2.4.10/include/opencv/cxcore.h"
//#include  "/home/server/
桌面/opencv-2.4.10/include/opencv/highgui.h"
#include "/usr/include/glog/logging.h"
#include "/usr/include/gflags/gflags.h"

#include "/usr/include/boost/smart_ptr/shared_ptr.hpp"


// MemoryDataLayer
宣告所需要的條件
#include "/home/server/
桌面/caffe-master/include/caffe/layers/memory_data_layer.hpp"

using namespace cv;


using namespace caffe;
using namespace std;

using namespace boost;


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    // ::google::InitGoogleLogging(argv[0]);
    // ::google::SetLogDestination(0, "/home/server/
桌面/caffe-master/temp");


   // Set GPU
     Caffe::set_mode(Caffe::GPU);
     int device_id = 0;

     Caffe::SetDevice(device_id);
     LOG(INFO) << "Using GPU";

     // Load net

     Net<float> net("/home/server/桌面/caffe-master/examples/myself/lenet_train_test.prototxt", caffe::TEST);



     //<-- depends on caffe version

     // Load pre-trained net

     net.CopyTrainedLayersFrom("/home/server/桌面/caffe-master/examples/myself/lenet_iter_10000.caffemodel");

     // Load image
     cv::Mat image = cv::imread("/home/server/
桌面/caffe-master/data/myself/val/camera.jpg"); // or cat.jpg



     // Set vector for image
     vector<cv::Mat> imageVector;
     imageVector.push_back(image); // image is a cv::Mat, as I'm using #1416 //push_back()

     // Set vector for label
     vector<int> labelVector;
     labelVector.push_back(0);//push_back 0 for initialize purpose

     // Net initialization
     float loss = 0.0;


     shared_ptr<MemoryDataLayer<float> > memory_data_layer;
     memory_data_layer = boost::static_pointer_cast < MemoryDataLayer < float > >(net.layer_by_name("data"));


     memory_data_layer->AddMatVector(imageVector,labelVector);

     // Run ForwardPrefilled
     vector<Blob<float>*> results = net.ForwardPrefilled(&loss);

     // Display result
     const shared_ptr<Blob<float> >& probs = net.blob_by_name("prob");
     const float* probs_out = probs->cpu_data();

     for (int i = 0 ; i < 2 ; i++)


     {
       LOG(INFO) << "Prob" << i << ": " << probs_out[i];
     }

    // LOG(INFO) << "Max element is: " << *max_element(probs_out,probs_out+3);

     /*


     // Display result2
     const float* argmaxs = results[1]->cpu_data();

     for (int i = 0; i < results[1]->num(); i++)
     {
       for (int j = 0; j < results[1]->height(); j++)
       {
         LOG(INFO) << "Image: "<< i << " class:" << argmaxs[i*results[1]->height() + j];
       }
     }

    */
     //printf("%d\n",(int)*argmaxs);



}

 



Reply all
Reply to author
Forward
0 new messages