From 0d958a845a0a2d556887511b53b1b41ddd994c03 Mon Sep 17 00:00:00 2001 From: zsdonghao Date: Fri, 13 Apr 2018 17:10:10 +0100 Subject: [PATCH] update docs --- docs/modules/files.rst | 33 ++++++++++++++++++++++++++++++++- tensorlayer/db.py | 5 ----- tensorlayer/files.py | 34 +--------------------------------- tensorlayer/visualize.py | 2 +- 4 files changed, 34 insertions(+), 40 deletions(-) diff --git a/docs/modules/files.rst b/docs/modules/files.rst index 9f5c8d889..272c8c829 100644 --- a/docs/modules/files.rst +++ b/docs/modules/files.rst @@ -1,6 +1,8 @@ API - Files =================================== +A collections of helper functions to work with dataset. +Load benchmark dataset, save and restore model, save and load variables. .. automodule:: tensorlayer.files @@ -50,6 +52,7 @@ API - Files npz_to_W_pdf + Load dataset functions ------------------------ @@ -109,7 +112,7 @@ VOC 2007/2012 ^^^^^^^^^^^^^^^^ .. autofunction:: load_voc_dataset -MPII +MPII ^^^^^^^^^^^^^^^^ .. autofunction:: load_mpii_pose_dataset @@ -159,6 +162,34 @@ Load network from ckpt Load and save variables ------------------------ +TensorFlow provides ``.ckpt`` file format to save and restore the models, while +we suggest to use standard python file format ``.npz`` to save models for the +sake of cross-platform. + +.. code-block:: python + + ## save model as .ckpt + saver = tf.train.Saver() + save_path = saver.save(sess, "model.ckpt") + # restore model from .ckpt + saver = tf.train.Saver() + saver.restore(sess, "model.ckpt") + + ## save model as .npz + tl.files.save_npz(network.all_params , name='model.npz') + # restore model from .npz (method 1) + load_params = tl.files.load_npz(name='model.npz') + tl.files.assign_params(sess, load_params, network) + # restore model from .npz (method 2) + tl.files.load_and_assign_npz(sess=sess, name='model.npz', network=network) + + ## you can assign the pre-trained parameters as follow + # 1st parameter + tl.files.assign_params(sess, [load_params[0]], network) + # the first three parameters + tl.files.assign_params(sess, load_params[:3], network) + + Save variables as .npy ^^^^^^^^^^^^^^^^^^^^^^^^^ .. autofunction:: save_any_to_npy diff --git a/tensorlayer/db.py b/tensorlayer/db.py index 3ffe2f957..f1c1e3da2 100644 --- a/tensorlayer/db.py +++ b/tensorlayer/db.py @@ -1,10 +1,5 @@ #! /usr/bin/python # -*- coding: utf-8 -*- -""" -Experimental Database Management System. - -Latest Version -""" import inspect import pickle diff --git a/tensorlayer/files.py b/tensorlayer/files.py index d8939c39c..b9052b4e2 100644 --- a/tensorlayer/files.py +++ b/tensorlayer/files.py @@ -1,36 +1,4 @@ # -*- coding: utf-8 -*- -""" -A collections of helper functions to work with dataset. - -Load benchmark dataset, save and restore model, save and load variables. -TensorFlow provides ``.ckpt`` file format to save and restore the models, while -we suggest to use standard python file format ``.npz`` to save models for the -sake of cross-platform. - -.. code-block:: python - - ## save model as .ckpt - saver = tf.train.Saver() - save_path = saver.save(sess, "model.ckpt") - # restore model from .ckpt - saver = tf.train.Saver() - saver.restore(sess, "model.ckpt") - - ## save model as .npz - tl.files.save_npz(network.all_params , name='model.npz') - # restore model from .npz (method 1) - load_params = tl.files.load_npz(name='model.npz') - tl.files.assign_params(sess, load_params, network) - # restore model from .npz (method 2) - tl.files.load_and_assign_npz(sess=sess, name='model.npz', network=network) - - ## you can assign the pre-trained parameters as follow - # 1st parameter - tl.files.assign_params(sess, [load_params[0]], network) - # the first three parameters - tl.files.assign_params(sess, load_params[:3], network) - -""" import gzip import math @@ -1345,7 +1313,7 @@ def load_mpii_pose_dataset(path='data', is_16_pos_only=False): >>> import tensorlayer as tl >>> img_train_list, ann_train_list, img_test_list, ann_test_list = tl.files.load_mpii_pose_dataset() >>> image = tl.vis.read_image(img_train_list[0]) - >>> tl.vis.draw_mpii_people_to_image(image, ann_train_list[0], 'image.png') + >>> tl.vis.draw_mpii_pose_to_image(image, ann_train_list[0], 'image.png') >>> pprint.pprint(ann_train_list[0]) References diff --git a/tensorlayer/visualize.py b/tensorlayer/visualize.py index d80a971ff..d868dba10 100644 --- a/tensorlayer/visualize.py +++ b/tensorlayer/visualize.py @@ -247,7 +247,7 @@ def draw_mpii_pose_to_image(image, poses, save_name='image.png'): >>> import tensorlayer as tl >>> img_train_list, ann_train_list, img_test_list, ann_test_list = tl.files.load_mpii_pose_dataset() >>> image = tl.vis.read_image(img_train_list[0]) - >>> tl.vis.draw_mpii_people_to_image(image, ann_train_list[0], 'image.png') + >>> tl.vis.draw_mpii_pose_to_image(image, ann_train_list[0], 'image.png') >>> pprint.pprint(ann_train_list[0]) References