2016-11-21 6 views
0

ckpt 파일에서 변수 값을 복원하기 전에 변수를 복원하는 파일에서이 변수를 만들어야합니다. 그러나이 새 파일에는 ckpt 파일에없는 다른 변수가있을 수 있습니다. 복원 된 변수 목록 만 인쇄 할 수 있습니까 (이 경우 tf.all_variables가 작동하지 않습니다)? 당신이 저장할 수있는 변수의 목록을 원하는 경우TensorFlow에서 복원 된 변수 목록

+0

새 파일에서 정확히 무엇을하고 있는지 명확히 할 수 있습니까? 새 변수를 추가하고 다시 저장 하시겠습니까? – Neal

+0

여기, 주어진 ckpt 파일에 저장된 변수 목록을 얻고 싶었습니다. – cerebrou

답변

1

, 나는 당신이 사용할 수 있다고 생각 : 당신은 당신이 복원하여 검사 점에서 변수를 나열 inspect_checkpoint.py 도구를 사용할 수 있습니다

tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES) + tf.get_collection(tf.GraphKeys.SAVEABLE_OBJECTS)

2

.

from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file 

# List ALL tensors. 
print_tensors_in_checkpoint_file(file_name='./model.ckpt', tensor_name='') 

# List contents of a specific tensor. 
print_tensors_in_checkpoint_file(file_name='./model.ckpt', tensor_name='conv1_w') 

또 다른 방법 :

from tensorflow.python import pywrap_tensorflow 
reader = pywrap_tensorflow.NewCheckpointReader('./model.ckpt') 
var_to_shape_map = reader.get_variable_to_shape_map() 
for key in var_to_shape_map: 
    print("tensor_name: ", key) 
    print(reader.get_tensor(key)) # Remove this is you want to print only variable names 

목록 현재 그래프에서 모든 글로벌 변수 :

for v in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES): 
    print(v) 

그것이 도움이되기를 바랍니다.

0

사용 print_tensors_in_checkpoint_file(file_name, tensor_name, all_tensors)

인수 : FILE_NAME : 검사 점 파일의 이름입니다. tensor_name : 인쇄 할 검사 점 파일의 텐서 이름입니다. all_tensors : 모든 텐서를 인쇄할지 여부를 나타내는 부울입니다.

관련 문제