Wrong variable scope when using tensorflow.python.layers.core.Dense -


i have following code implement decoder of seq2seq model using tensorflow.

    tf.variable_scope('decoder'):         if self._embedding none:             self._embedding = create_embedding(self._embedding_size,                                                self._vocab_size)             self._build_decoder_cell()          tf.variable_scope('output'):             self._output_layer = _core_layers.dense(                 self._vocab_size, name='output_layer')          _, batch_size, _ = tf.unstack(tf.shape(encoder_outputs))          # train or eval         if targets not none:             eos = tf.fill([1, batch_size], self._eos_id)             targets = tf.concat([targets, eos], axis=0)              embedding_targets = tf.nn.embedding_lookup(                 self._embedding, targets)              helper = tf.contrib.seq2seq.traininghelper(                 embedding_targets, sequence_length=lengths, time_major=true)              decoder = tf.contrib.seq2seq.basicdecoder(                 self._cell, helper, encoder_final_state)              outputs, final_state, _ = tf.contrib.seq2seq.dynamic_decode(                 decoder, output_time_major=true, swap_memory=true)              logits = self._output_layer(outputs.rnn_output)          # inference         else:             import pdb; pdb.set_trace()             bos = tf.fill([batch_size], self._bos_id)              helper = tf.contrib.seq2seq.greedyembeddinghelper(                 self._embedding, bos, self._eos_id)              decoder = tf.contrib.seq2seq.basicdecoder(                 self._cell,                 helper,                 encoder_final_state,                 output_layer=self._output_layer)              outputs, final_state, _ = tf.contrib.seq2seq.dynamic_decode(                 decoder,                 maximum_iterations=tf.reduce_max(lengths),                 output_time_major=true,                 swap_memory=true)              logits = outputs.rnn_output      return logits, final_state 

the tensorflow.python.layers.core.dense layer seems has undetermined scope until 1 calls instance since build function (where weight/kernel , bias defined) called in __call__ function. creating 1 graph training , 1 graph inference, save graph when training , restore when inference. however, got notfounderror (see above traceback): key basic_seq2seq/decoder/decoder/output_layer/kernel not found in checkpoint.

by using checkpoint inspect tool, find saved training graph has tensor basic_seq2seq/decoder/output_layer/kernel when inference graph request basic_seq2seq/decoder/decoder/output_layer/kernel.

even though output layer of both graphs created before if-else statement, have different names.

how can solve this? in advance.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -