tensorlayer / TensorLayer

Deep Learning and Reinforcement Learning Library for Scientists and Engineers
http://tensorlayerx.com
Other
7.33k stars 1.61k forks source link

How does only using tensorlayer convert ckpt to npz? #224

Closed MatsumotoHiroko closed 7 years ago

MatsumotoHiroko commented 7 years ago

I'm looking for the way about to convert ckpt to npz. I have founded this page http://tensorlayer.readthedocs.io/en/latest/modules/files.html. I think if we use tensorlayer, we can convert its format.

I try running blow code.

with tf.Session() as sess:
  ckpt = tf.train.get_checkpoint_state(FLAGS.train_dir)
  if ckpt:
    last_model = ckpt.model_checkpoint_path # last model's path
    saver.restore(sess, last_model)
    tl.files.save_npz(name='{}/cifar10.npz'.format(FLAGS.output_dir), sess=sess)

After trainning, npz file was created. But this file's rows are few lines. It was failer to make.

Can tensorlayer convert ckpt to npz by unless making "network"?

zsdonghao commented 7 years ago

yes, you can load ckpt model and then save it to npz.

MatsumotoHiroko commented 7 years ago

Thank you for your response. I have revised my code, then tensorlayer has made npz file successfully!

    with tf.Session() as sess:
      sess.run(tf.global_variables_initializer())
      ckpt = tf.train.get_checkpoint_state(FLAGS.train_dir)
      if ckpt: 
        target_list = []
        for v in tf.global_variables():
          if v.shape != ():
            target_list.append(v.name)
        last_model = ckpt.model_checkpoint_path
        tl.files.load_ckpt(sess=sess, mode_name=last_model, printable=True)
    tl.files.save_npz(target_list, name='{}/cifar10.npz'.format(FLAGS.output_dir), sess=sess)