基于tensorflow加载部分层的方法

yipeiwu_com7年前Python基础

一般使用

saver.restore(sess, modeldir + "model.ckpt")

即可加载已经训练好的网络,可是有时候想值使用部分层的参数,这时候可以选择在加载网络之后重新初始化剩下的层

var_list = [weights['wd1'], weights['out'], biases['bd1'], biases['out'], global_step]
initfc = tf.variables_initializer(var_list, name='init')

比如我们想从新初始化var_list中的各个层,在restore之后,再初始化即可

sess.run(init)
saver.restore(sess, modeldir + "model.ckpt")
print sess.run(global_step)
#initialize several layer
sess.run(initfc)
print sess.run(global_step)

即可发现部分变量重新初始化了

以上这篇基于tensorflow加载部分层的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python中计算三角函数之cos()方法的使用简介

 cos()方法返回x弧度的余弦值。 语法 以下是cos()方法的语法: cos(x) 注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象...

使用Python微信库itchat获得好友和群组已撤回的消息

使用Python微信库itchat获得好友和群组已撤回的消息

具体代码如下所述: #coding=utf-8 import itchat from itchat.content import TEXT from itchat.content i...

python实现输入的数据在地图上生成热力图效果

我就废话不多说了,直接贴代码,注意要先安装folium #-*-coding:utf8-*- #输入data生成热力图html,借助了leaflet,没网不能用 import o...

Python 通配符删除文件的实例

实例如下所示: # -*- coding: utf-8 -*- """ 使用通配符,获取所有文件,或进行操作。 """ import glob import os def files...

python将四元数变换为旋转矩阵的实例

如下所示: import numpy as np from autolab_core import RigidTransform # 写上用四元数表示的orientation和xy...