Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6292 Discussions

How can i get a layer's weight with openvino 2022.2 ?

ryan34
Beginner
425 Views

I'm trying to draw Class Activation Map for my optimized model's output.

 

featuremap * weights = CAM 

 

When i was using OpenVINO 2020.03ver , i can get the layer's weights like below 

iec   = IECore()
net   = iec.read_Network(model = Openvino_XML, weights = Openvino_BIN)

weight_layer = net.layers[weight_layer_name]
layer_weights = weight_layer.blobs["weights"]

 

But net.layers function is deprecated after 2021.2 ver 

and also, layer. blobs is deprecated..

 

any other good solutions to get weights from specific layer? (with openvino 2022.3 ver)

0 Kudos
5 Replies
Hairul_Intel
Moderator
393 Views

Hi ryan34,

Thank you for reaching out to us.

 

We suggest you use get_ops() or get_ordered_ops() methods from nGraph Python API as the 'ie_api.IENetwork.layers' has been deprecated.

 

Refer to the nGraph Python API Reference for more information.

 

 

Regards,

Hairul


0 Kudos
ryan34
Beginner
375 Views

Hi Hairul, 

Thanks for your kind reply.

 

I've tried nGraph as shown below,

ryan34_0-1667367706261.png

 

but,  get_ordered_ops() function just "return ops used in the function intopological order"

and also the get_ops() funcition

 

How can i get the layer's weight like this code?

layer weights = weight_layer.blobs["weights"] 

weight_layer = net.layers[weight_layer_name] 
layer_weights = weight_layer.blobs["weights"]

 

Regards, 

Ryan

0 Kudos
Hairul_Intel
Moderator
343 Views

Hi Ryan,

We are investigating this issue further and will update you at the earliest.

 

 

Regards,

Hairul


0 Kudos
Hairul_Intel
Moderator
308 Views

Hi Ryan,

Thank you for your patience.

 

For your information, the weights are located in the Constant operations available in the network. You can use get_data() after get_ops() function to get the weight values on specific Constant operation layers.

 

Here is an example code for calling the get_data() method and retrieving the data tensor associated with a Constant node in OpenVINO™ 2022.2:

from openvino.inference_engine import IECore
import ngraph as ng

ie = IECore()
path_xml="vehicle-detection-adas-0002.xml"
path_bin="vehicle-detection-adas-0002.bin"

net = ie.read_network(model=path_xml, weights=path_bin)

func = ng.function_from_cnn(net)

ops = func.get_ops()
print(ops[14]) #Print the node attributes
print(ops[14].get_data()) #Specific Constant operations layer, all weights are located in the Constant operations

 

 

Regards,

Hairul

 

0 Kudos
Hairul_Intel
Moderator
276 Views

Hi Ryan,

This thread will no longer be monitored since we have provided a solution. If you need any additional information from Intel, please submit a new question.

 

 

Regards,

Hairul


0 Kudos
Reply