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()
08_02VGG19_mat权重文件查看
最新推荐文章于 2024-09-20 21:17:37 发布