栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何加载caffe模型并转换为numpy数组?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何加载caffe模型并转换为numpy数组?

这是一个很好的函数,可以将caffe net转换为python词典列表,因此您可以按需要对其进行腌制和读取:

import caffedef shai_net_to_py_readable(prototxt_filename, caffemodel_filename):  net = caffe.Net(prototxt_filename, caffemodel_filename, caffe.TEST) # read the net + weights  pynet_ = []   for li in xrange(len(net.layers)):  # for each layer in the net    layer = {}  # store layer's information    layer['name'] = net._layer_names[li]    # for each input to the layer (aka "bottom") store its name and shape    layer['bottoms'] = [(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape)    for bi in list(net._bottom_ids(li))]     # for each output of the layer (aka "top") store its name and shape    layer['tops'] = [(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape) for bi in list(net._top_ids(li))]    layer['type'] = net.layers[li].type  # type of the layer    # the internal parameters of the layer. not all layers has weights.    layer['weights'] = [net.layers[li].blobs[bi].data[...]   for bi in xrange(len(net.layers[li].blobs))]    pynet_.append(layer)  return pynet_


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/636851.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号