Ask Your Question
0

Concatenate failing check for #axes?

asked 2016-04-27 10:48:27 -0600

MCoder1 gravatar image

updated 2016-04-27 11:00:29 -0600

Using OpenCV, I am trying to classify an image. The neural network I used to train it takes in an image and hand-crafted features and late fuses them at the fully-connected layers before classification. I know the image classification only pipeline works properly because I was successfully able to take a trained network and apply it to just images.

As a dummy example... this doesn't seem to run

Size size(n, n);
Mat1f imageBlobMat(size);
// Code to fill values for imageBlobMat here (preprocessing image)

Size sizeFeatures(20,1); // 20 hand-crafted features
Mat1f featBlobMat(sizeFeatures);
// Code to normalize these features here

dnn::Blob imageBlob = dnn::Blob(imageBlobMat);
net.setBlob(".image", imageBlob);
dnn::Blob featBlob = dnn::Blob(featBlobMat);
net.setBlob(".feat", featBlob);
net.forward();
dnn::Blob prob = net.getBlob("prob");

The prototxt file looks like below. I want to reiterate that I trained using the prototxt file and modified the top and bottom to create a deploy.prototxt so I know that these layers work together when to train a caffe model.

name: "NetworkName"
input: "image"
input_dim: 1
input_dim: 1
input_dim: n
input_dim: n
input: "feat"
input_dim: 1
input_dim: 1
input_dim: 1
input_dim: 20

...
Conv Layers on Image input
...

layer{
    name: "flatten"
    type: "Flatten"
    bottom: "drop"
    top: "flatten"
}
layer{
    name: "concat"
    type: "Concat"
    bottom: "flatten"
    bottom: "feat"
    top: "concat"
    concat_param{
        axis: 1
    }
}

I am getting this error:

OpenCV Error: Assertion failed (curShape.dims() == refShape.dims() && inputs[i]->type() == refType) in allocate, file /opt/opencv_contrib/modules/dnn/src/layers/concat_layer.cpp, line 69
terminate called after throwing an instance of 'cv::Exception'
  what():  /opt/opencv_contrib/modules/dnn/src/layers/concat_layer.cpp:69: error: (-215) curShape.dims() == refShape.dims() && inputs[i]->type() == refType in function allocate

It seems related to the size of the inputs, so I've tried modifying the shape of featBlobMat to be 1x20 and 20x1, and changed the input_dims in all possible ways. [1 1 1 20], [1 1 20 1], [1 20], [20 1], and nothing seems to work. Any pointers?

EDIT: Accidentally posted something meant for the Caffe question board... Oops! Revised.

edit retag flag offensive close merge delete

Comments

interesting question, but how is this related to opencv ?

berak gravatar imageberak ( 2016-04-27 10:53:47 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-04-27 10:58:50 -0600

MCoder1 gravatar image

Oops, you're right. My mind completely blanked - this is a Caffe question. Revised to reflect a parallel path I'm pursuing with OpenCV.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-27 10:48:27 -0600

Seen: 328 times

Last updated: Apr 27 '16