如何微调训练前的张量流模型?

时间:2020-06-10 13:57:02

标签: python tensorflow machine-learning pre-trained-model

我有一个预先训练的模型,该模型存储为文件:

  • converted.data-00000-of-00001
  • converted.index
  • converted.meta

我可以下载它,看看其中有哪个tf.variable:

with tf.Session() as sess:

    new_saver = tf.train.import_meta_graph('trackrcnn_init/converted.meta')
    new_saver.restore(sess, 'trackrcnn_init/converted')

    variables = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)

如果您打印其中一些,它将看起来像这样:

...
<tf.Variable 'resnetconv4/group0/block2/conv3/W:0' shape=(1, 1, 64, 256) dtype=float32_ref>
<tf.Variable 'resnetconv4/group0/block2/conv3/bn/beta:0' shape=(256,) dtype=float32_ref>
<tf.Variable 'resnetconv4/group0/block2/conv3/bn/gamma:0' shape=(256,) dtype=float32_ref>
<tf.Variable 'resnetconv4/group0/block2/conv3/bn/mean_ema:0' shape=(256,) dtype=float32_ref>
<tf.Variable 'resnetconv4/group0/block2/conv3/bn/var_ema:0' shape=(256,) dtype=float32_ref>
<tf.Variable 'resnetconv4/group1/block0/conv1/W:0' shape=(1, 1, 256, 128) dtype=float32_ref>
<tf.Variable 'resnetconv4/group1/block0/conv1/W/AccumGrad:0' shape=(1, 1, 256, 128) dtype=float32_ref>
<tf.Variable 'resnetconv4/group1/block0/conv1/W/Momentum:0' shape=(1, 1, 256, 128) dtype=float32_ref>
...

假设我需要将其中一些更改为其他,并用零初始化它们,以便进一步训练这些片段。

例如,我想用<tf.Variable 'resnetconv4/group1/block0/conv1/W:0' shape=(1, 1, 256, 256) dtype=float32_ref>中的<tf.Variable 'resnetconv4/group1/block0/conv1/W:0' shape=(1, 1, 256, 128) dtype=float32_ref>

换句话说,我想调整神经网络的一层的大小,然后开始训练并确定新的权重。

如何进行这样的微调?

0 个答案:

没有答案