Ask Your Question
0

Access output of a Caffe Slice Layer

asked 2019-07-23 09:36:45 -0600

paubau gravatar image

updated 2019-07-28 06:58:14 -0600

I have a caffe model containing a Slice Layer. The input dimension is (1, 96, 128, 128)

layer {
  name: "63_64"
  type: "Slice"
  bottom: "62"
  top: "63"
  top: "64"
  slice_param {
     slice_point: 48
     axis: 1
   }
}

and I want to get both resulting arrays (63 & 64). So what I thought I had to do was the following:

model = cv2.dnn.readNetFromCaffe("model.prototxt", "model.caffemodel")
model.setInput(blob)
r = model.forward(["63_64"])

Which should have given me two matrices with a dimension of (1, 48, 128, 128), but I only got the first one. How do I access the second matrix

edit retag flag offensive close merge delete

Comments

Remove square brackets.

supra56 gravatar imagesupra56 ( 2019-07-28 07:04:06 -0600 )edit

The squere brackets are still there because originally I wanted to receive multiple layers. Removing them does not make any difference except that the output is one numpy array instead of a python list with one numpy array

paubau gravatar imagepaubau ( 2019-07-28 07:28:15 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2019-07-27 05:23:21 -0600

dkurt gravatar image

Try to use forwardAndRetrieve: https://docs.opencv.org/master/db/d30...

edit flag offensive delete link more

Comments

@dkurt Thanks for the answer, r = model.forwardAndRetrieve(["63_64"]) did work as expected.

paubau gravatar imagepaubau ( 2019-07-28 07:41:17 -0600 )edit
0

answered 2019-07-28 05:16:56 -0600

supra56 gravatar image

updated 2019-07-28 07:05:16 -0600

There is typo error square bracket and also some missing blobFromImage:

r = model.forward("63_64"])

to

r = model.forward()

Or:

r = model.forward("63_64")

snippet:

model = cv2.dnn.readNetFromCaffe("model.prototxt", "model.caffemodel")
blob = cv2.dnn.blobFromImages(images, 1, (62, 63), (104, 117, 123))
model.setInput(blob)
r = model.forward()

Btw, I am using VideoCapture not image. The (62, 63), (x, x, x). X denoted of your choice.

edit flag offensive delete link more

Comments

Notice. If you're using image. You'll use cv2.resize.

supra56 gravatar imagesupra56 ( 2019-07-28 05:27:03 -0600 )edit

@supra56 I was using r = model.forward(["63_64"]) by intention to receive the output of that specific layer. model.forward() would give me the result of the final layer. Btw the Code for my blob is: blob = cv2.dnn.blobFromImages([im_c1,im_c2], 1./255., (128, 128), True, crop=True)

paubau gravatar imagepaubau ( 2019-07-28 07:10:56 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-23 09:36:45 -0600

Seen: 722 times

Last updated: Jul 28 '19