Get the value of some weights in a model trained by TensorFlow

前端 未结 3 485
温柔的废话
温柔的废话 2020-11-27 12:12

I have trained a ConvNet model with TensorFlow, and I want to get a particular weight in layer. For example in torch7 I would simply access model.modules[2].weights

3条回答
  •  清歌不尽
    2020-11-27 12:53

    So if you proceed this code step by step, you will first get a list of used/trainable variables. Then you could sort them in a list where you sort weight matrices/lists to variable names, just for example how you were possible to deal with that information.

    vars = tf.trainable_variables()
    print(vars) #some infos about variables...
    vars_vals = sess.run(vars)
    for var, val in zip(vars, vars_vals):
        print("var: {}, value: {}".format(var.name, val)) #...or sort it in a list....
    

提交回复
热议问题