加载预训练模型遇到问题
Created by: bjkite
加载预训练模型遇到如下问题:
-
对预训练模型的fc层做了修改,但是加载模型的时候还是按照原模型的形状加载,报错 2.将上述fc层用name=“xxx”重命名,仍然加载原模型的参数,而且新fc层的形状参数出错。 out = paddle.layer.fc(
name=“gg_fc”,
input=conv10,
size=emb_dim,
act=paddle.activation.Relu(),
layer_attr=paddle.attr.Extra(drop_rate=0.5)) 这里,conv10是1000维,emb_dim是200维,但是报如下错误,变成了(200,2136),后面(1000,41190)是预训练模型在这一层的形状。 ValueError: Value shape mismatch, expect (200, 2136), should (1000, 41190) -
caffe 模型到 paddle模型转换,参数对不上 caffe配置如下 : name: "" layers { layer { name: "conv1" type: "conv" num_output: 64 weight_filler { type: "gaussian" std: 0.001 } bias_filler { type: "constant" value: 0 } pad: 0 kernelsize: 7 group: 1 stride: 2 } bottom: "data" top: "conv1" } layers { layer { name: "conv1_neuron" type: "relu" } bottom: "conv1" top: "conv1" } layers { layer { name: "pool1" type: "pool" kernelsize: 3 stride: 3 pool: MAX } bottom: "conv1" top: "pool1" } layers { layer { name: "cmrnorm1" type: "lrn" local_size: 5 alpha: 0.0005 beta: 0.75 } bottom: "pool1" top: "cmrnorm1" } padlle对应配置如下: conv1 = paddle.networks.simple_img_conv_pool( input=input, num_channel=3, pool_size=3, pool_stride=3, num_filters=64, filter_size=7, conv_stride=2, groups=1, act=paddle.activation.Relu(), pool_type=paddle.pooling.Max()) 使用转化后的模型加载参数,在这一层,报如下错误: ValueError: Value shape mismatch, expect (1, 1179648), should (1, 9408) 形状差别很大,是不是不能使用simple_img_conv_pool,要严格按照单层来映射?