Avis
Avis

Reputation: 1086

Caffe - How to change the dtype of caffe weights using pycaffe?

I have a pre-trained faster-rcnn caffemodel. I'm able to get the weights of the model using net.params[pr][0].data. As of now the weights are of numpy float32 type. I would like to reduce it to float 16 just to reduce the size of the model.

Upvotes: 3

Views: 1103

Answers (1)

rkellerm
rkellerm

Reputation: 5522

To change the type of the weights in order to save memory for the storage, you can use NumPy's astype(float16), for example

net.params[pr][0].data = net.params[pr][0].data.astype(numpy.float16)

However Caffe won't support it at inference / training time so you'll need to reconvert it to float32. However there are some caffe repositories that support float16, such as Ristretto, or NVCaffe for NVidia / Intel's clCaffe for OpenCL on Intel GPUs.

Upvotes: 1

Related Questions