read .caffemodel

971 views
Skip to first unread message

Wei Wen

unread,
Jul 17, 2015, 1:46:36 PM7/17/15
to caffe...@googlegroups.com
Hi,

I want to use python to parse .caffemodel binary proto.

For the mean file, the following code works well:
    f = open('data/ilsvrc12/imagenet_mean.binaryproto','rb')
    blob = caffe_pb2.BlobProto()
    blob.ParseFromString(f.read())
    f.close()
   
    print blob.ByteSize()
    
    print blob.height, blob.width,blob.channels, blob.num

    f = open(dstmodel,'wb')   
    f.write(blob.SerializeToString())
    f.close()
    print 'Done.'
Outputs:
786446
256 256 3 1
Done.


But when I use the same code to parse caffemodel
f = open('models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel','rb')
#         ...
# other code lines are the same
#         ...
Outputs:
243862418
0 0 0 0
Done.


Oops, the byte size is correct, but all data are 0/empty.

Any guy know about this?

Thanks,
-Wei




Wei Wen

unread,
Jul 17, 2015, 3:12:14 PM7/17/15
to caffe...@googlegroups.com
UPDATE BY ME
www.pittnuts.com

    f = open(srcmodel,'rb')
    blob = caffe_pb2.NetParameter() #caffemodel is a NetParameter proto
    blob.ParseFromString(f.read())
    f.close()

      print blob.ListFields()
    print blob.ByteSize()
    
    f = open(dstmodel,'wb')
    f.write(blob.SerializeToString())
    f.close()
    print 'Done.'
Reply all
Reply to author
Forward
0 new messages