Get weights from tensorflow model

前端 未结 1 1424
春和景丽
春和景丽 2021-02-10 05:55

Hello I would like to finetune VGG model from tensorflow. I have two questions.

How to get the weights from network? The trainable_variables returns empty list for me.

1条回答
  •  北恋
    北恋 (楼主)
    2021-02-10 06:35

    This pretrained VGG-16 model encodes all of the model parameters as tf.constant() ops. (See, for example, the calls to tf.constant() here.) As a result, the model parameters would not appear in tf.trainable_variables(), and the model is not mutable without substantial surgery: you would need to replace the constant nodes with tf.Variable objects that start with the same value in order to continue training.

    In general, when importing a graph for retraining, the tf.train.import_meta_graph() function should be used, as this function loads additional metadata (including the collections of variables). The tf.import_graph_def() function is lower level, and does not populate these collections.

    0 讨论(0)
提交回复
热议问题