migueldeicaza / TensorFlowSharp

TensorFlow API for .NET languages
MIT License
3.14k stars 577 forks source link

RNN state data feed on TensorflowSharp : How to get the state data on .pb model #111

Open hjh010501 opened 7 years ago

hjh010501 commented 7 years ago

Hi guys

'char-rnn-tensorflow to Tensorflowsharp', but I don't know how to get the state and feed the state in .pb model

Hello, I tried to use RNN model in tensorflowSharp, but I have some problems to use it This is a model what i used. link

  1. I trained this model and made it into a single pb file (freeze graph)

Gist Import GraphDef result link

tensorboardgraph

  1. I analyzed char-rnn-tensorflow model.py and change model.py into tensorflowsharp version BUT, I can't know how to change this code (model.py)
 self.initial_state = cell.zero_state(args.batch_size, tf.float32)
        ...
     outputs, last_state = legacy_seq2seq.rnn_decoder(inputs, self.initial_state, cell, loop_function=loop if not training else None, scope='rnnlm')
        ...
     state = sess.run(self.cell.zero_state(1, tf.float32))
        ...
     feed = {self.input_data: x, self.initial_state: state} 
                 [state] = sess.run([self.final_state], feed) 
        ...
                 [probs, state] = sess.run([self.probs, self.final_state], feed)

I tried to input input_data to input node(Placeholder) and output the result data in output node(output) but I got strange result... I think I failed to feed rnn cell's state data

my C# code: link

How can i input the state and output the state in model?

ghost commented 7 years ago

did you figure out how to correctly save the rnn to include initial and final states?