How to get inference results from Multi-Output Network?

51 views
Skip to first unread message

Diego Durante

unread,
Nov 20, 2019, 12:39:17 PM11/20/19
to Caffe Users
Hello!

I have a network with multiple outputs, that is a caffenet with adding two more outputs (a regression layer and a classification layer), and I don't know hot to get results from sencond and third outputs. I describe details here:

The details of the prototxt model file: it is a caffenet with some changes, I have added two outputs (one additional clasification output and also a regression output):

... # Caffenet until here, some changes:

layers {
  name: "fc8-1"
  type: INNER_PRODUCT
  bottom: "fc7"
  top: "fc8-1"
  inner_product_param {
    num_output: 8
  }
}
layers {
  name: "prob-1"
  type: SOFTMAX
  bottom: "fc8-1"
  top: "prob-1"
}
layers {
  name: "fc8-2"
  type: INNER_PRODUCT
  bottom: "fc7"
  top: "fc8-2"
  inner_product_param {
    num_output: 2
  }
}
layers {
  name: "prob-2"
  type: SOFTMAX
  bottom: "fc8-2"
  top: "prob-2"
}
layers {
  name: "fc8-1-regr"
  type: INNER_PRODUCT
  bottom: "fc7"
  top: "fc8-1-regr"
  inner_product_param {
    num_output: 1
  }
}


I infer and I have not Idea how to get outputs. I define net object to run inference later:

net_weights='./caffenet_mix_iter_50000.caffemodel'
net_model_file='./deploy.prototxt'
net = caffe.Classifier(net_model_file, net_weights,
                       mean=meanOfMean,
                       channel_swap=(2,1,0),
                       raw_scale=255,
                       image_dims=(227, 227))

Also, I load an image:
image = '/home/diego/test_images/test_01.jpg'
input_image = caffe.io.load_image(image)
_ = plt.imshow(image)

Until here all seems normal, but when I try to get results from multiple outputs, I cat only get one output:
prediction = net.predict([image])
prediction.shape
 
(1, 1) 

prediction[0].shape
(1,)

 
print(prediction)
[[2.5250585]]
 
But I can see into the log that Caffe knows multiple outputs (from the running log) :

...

I1120 14:01:09.473515 24579 net.cpp:264] This network produces output fc8-age-regr
I1120 14:01:09.473520 24579 net.cpp:264] This network produces output prob-age
I1120 14:01:09.473526 24579 net.cpp:264] This network produces output prob-gender

...
 
Then, what is the correct way to obtain multiple outputs from this network?

A lot of thanks! I see caffe great but I have not very depth information.

Diego

Diego Durante

unread,
Nov 20, 2019, 1:41:34 PM11/20/19
to Caffe Users
I have changed names and other things to avoid type problems, but I continue with the same problem...

I1120 15:38:59.190704 27301 net.cpp:264] This network produces output fc8-1-regr
I1120 15:38:59.190711 27301 net.cpp:264] This network produces output prob-1
I1120 15:38:59.190717 27301 net.cpp:264] This network produces output prob-2

Moreover that, It has no changes and I cannot stand how to get second and third output results...

Somebody knows how to do it?

Thanks!
Reply all
Reply to author
Forward
0 new messages