08_02VGG19_mat权重文件查看



from scipy import io
import os

"""
# mat 是值MATLAB 的数据特征存储
http://www.vlfeat.org/matconvnet/pretrained/#pretrained-models
"""

def get_vgg_weights():
    data_path = '../datas/vgg/imagenet-vgg-verydeep-19.mat'
    mdict = io.loadmat(data_path)
    print(mdict.keys())
    weights = mdict['layers'][0]
    # print(weights)

    layers1 = ('conv1_1', 'relu1_1', 'conv1_2', 'relu1_2', 'pool1', 'conv2_1', 'relu2_1', 'conv2_2', 'relu2_2',
               'pool2', 'conv3_1', 'relu3_1', 'conv3_2', 'relu3_2', 'conv3_3', 'relu3_3', 'conv3_4', 'relu3_4',
               'pool3', 'conv4_1', 'relu4_1', 'conv4_2', 'relu4_2', 'conv4_3', 'relu4_3', 'conv4_4', 'relu4_4',
               'pool4', 'conv5_1', 'relu5_1', 'conv5_2', 'relu5_2', 'conv5_3', 'relu5_3', 'conv5_4', 'relu5_4', 'pool5')

    for i, name in enumerate(layers1):
        layer_type = name[:4]
        if layer_type == 'conv':
            print('卷积层的序号:{} - 卷积名字:{}'.format(i, name))
            kernels, bias = weights[i][0][0][2][0]
            print(kernels.shape, bias.shape)
            print('**' * 45)

    # todo 获取第0层 conv1_1参数的方式
    i = 0
    weights0 = weights[i][0][0][2][0][0]
    biases0 = weights[i][0][0][2][0][1]
    print(weights0, '\n', biases0)


def load_my_weights():
    weights_path = './model/mnist/matlab/ai20'
    files = os.listdir(weights_path)
    if files:
        weight_file = os.path.join(weights_path, files[0])
    if os.path.isfile(weight_file):
        mdict = io.loadmat(weight_file)
        print(mdict.keys())
    print(mdict['w_conv1:0'], '\n', mdict['b_conv1:0'].shape)


if __name__ == '__main__':
    # get_vgg_weights()
    load_my_weights()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值