由于在实际的项目中,使用DenseNet的模型做文字识别,为了提升识别效果在模型后接LSTM,但是在训练时出现了问题,发现Loss与Accuracy都保持不变。为了解决这个问题尝试打印每层的输出结果以排查问题。

 

测试代码:
# 用于测试 if __name__ == "__main__": reload(densenet2) characters =
keys.alphabet[:] characters = characters[1:] + u'卍' nclass = len(characters)
input = Input(shape=(32, None, 1), name='the_input') x =
densenet2.dense_cnn(input, nclass) rnnunit = 256 x = Bidirectional(GRU(rnnunit,
return_sequences=True, implementation=2), name='blstm1')(x) x = Dense(rnnunit,
name='blstm1_out', activation='linear')(x) x = Bidirectional(GRU(rnnunit,
return_sequences=True, implementation=2), name='blstm2')(x) y_pred =
Dense(nclass, name='out2', activation='softmax')(x) # 根据选择outputs的输出层 basemodel
= Model(inputs= input, outputs=y_pred) #basemodel.summary() #print("the lenth
of layer:{}".format(len(basemodel.layers))) i = -3 model = Model(inputs= input,
outputs=basemodel.layers[i].output)
model.load_weights("..\\100_test_50w_weights_densenet-71-0.08.h5",
by_name=True) out = predict("..\\img1.JPEG", model) name = model.layers[i].name
print("the net name is :{} \n the out is :\n {} ".format(name, np.array(out)))
说明:

*  basemodel 是在densenet后接了lstm的网络
* model最终的模型,可以修改basemodel.layer[i].output的"i","i"指代的是网络的第几层,也可以通过读取网络层的名称的方式
* predict 自定义函数,主要调用的是框架中的model.predict()。其中还包括对图像进行预处理。

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信