2017-02-22 2 views
1

У меня есть модель, прошедшая обучение в Tensorflow r0.12, которая создала файлы контрольных точек, используя SaverV2. Моя модель была RNN с использованием rnn_cell и rnn_cell.GRUCell от tensorflow.python.ops. Поскольку изменения в 1.0, этот пакет перешел к core_rnn_cell_impl в tensorflow.contrib.rnn.python.ops согласно this answerОбновить файлы контрольной точки Tensorflow до 1.0

Я побежал файл tf_update.py из here обновить свои файлы в новой редакции. Однако с момента обновления мои старые файлы контрольных точек не работают. Кажется, что некоторые из переменных, требуемых новой реализацией GRUCell, отсутствовали или имели другое имя.

Пример ошибки (есть 132 таких ошибок):

2017-02-22 11:36:08.037315: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights not found in checkpoint 
2017-02-22 11:36:08.037382: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights/Adam not found in checkpoint 
2017-02-22 11:36:08.037494: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases/Adam not found in checkpoint 
2017-02-22 11:36:08.037499: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights/Adam_1 not found in checkpoint 
2017-02-22 11:36:08.037538: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights not found in checkpoint 
2017-02-22 11:36:08.037615: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases not found in checkpoint 
2017-02-22 11:36:08.037618: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases/Adam_1 not found in checkpoint 
2017-02-22 11:36:08.038098: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights/Adam_1 not found in checkpoint 
2017-02-22 11:36:08.038121: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights/Adam not found in checkpoint 
2017-02-22 11:36:08.038222: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/biases not found in checkpoint 
2017-02-22 11:36:08.038229: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/weights not found in checkpoint 
2017-02-22 11:36:08.038233: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/biases/Adam_1 not found in checkpoint 

Сохранение/загрузка работал отлично до обновления. Что я могу сделать, чтобы обновить старые файлы контрольных точек до r1.0?

Если это имеет значение, я использую python2.7, и такая же ошибка возникает при использовании либо тензорного потока CPU, либо тензорного потока с CUDA.

ответ

4

Там нет простого способа сделать это ... один подход будет использовать get_variable_to_shape_map()

ckpt_reader = tf.train.NewCheckpointReader(filepath) 
    ckpt_vars = ckpt_reader.get_variable_to_shape_map() 

, который даст вам список имен переменных для фигур в сохраненной контрольной точке. то ... создать Dict, переводящий от старых имен новых имен, т.е.

old_to_new={} 
old_to_new[old_name] = new_name 

затем instantitate заставки и восстановить только тот ВАР

saver = tf.Saver(old_to_new) 
saver.restore(filepath) 

Удачи, надеюсь, что это помогает.

+0

Спасибо за простой ответ. Я думаю, что я просто переучиваю модель для простоты, но я рад, что на самом деле есть способ сделать это. – jbird

Смежные вопросы