@@ -645,6 +645,10 @@ def load_and_assign_npz(sess=None, name=None, network=None):
645645 network : a :class:`Layer` class
646646 The network to be assigned
647647
648+ Returns
649+ --------
650+ Returns False if faild to model is not exist.
651+
648652 Examples
649653 ---------
650654 >>> tl.files.load_and_assign_npz(sess=sess, name='net.npz', network=net)
@@ -655,13 +659,13 @@ def load_and_assign_npz(sess=None, name=None, network=None):
655659 print ("[!] Load {} failed!" .format (name ))
656660 return False
657661 else :
658- params = tl . files . load_npz (name = name )
659- tl . files . assign_params (sess , params , network )
662+ params = load_npz (name = name )
663+ assign_params (sess , params , network )
660664 print ("[*] Load {} SUCCESS!" .format (name ))
661665 return network
662666
663667# Load and save variables
664- def save_any_to_npy (save_dict = {}, name = 'any .npy' ):
668+ def save_any_to_npy (save_dict = {}, name = 'file .npy' ):
665669 """Save variables to .npy file.
666670
667671 Examples
@@ -673,19 +677,24 @@ def save_any_to_npy(save_dict={}, name='any.npy'):
673677 """
674678 np .save (name , save_dict )
675679
676- def load_npy_to_any (path = '' , name = 'any .npy' ):
680+ def load_npy_to_any (path = '' , name = 'file .npy' ):
677681 """Load .npy file.
678682
679683 Examples
680684 ---------
681685 - see save_any_to_npy()
682686 """
687+ file_path = os .path .join (path , name )
683688 try :
684- npy = np .load (path + name ).item ()
689+ npy = np .load (file_path ).item ()
685690 except :
686- npy = np .load (path + name )
691+ npy = np .load (file_path )
687692 finally :
688- return npy
693+ try :
694+ return npy
695+ except :
696+ print ("[!] Fail to load %s" % file_path )
697+ exit ()
689698
690699
691700# Visualizing npz files
@@ -750,30 +759,33 @@ def load_folder_list(path=""):
750759 """
751760 return [os .path .join (path ,o ) for o in os .listdir (path ) if os .path .isdir (os .path .join (path ,o ))]
752761
753-
754762def exists_or_mkdir (path , verbose = True ):
755- """Check a directory , if not exist, create the folder and return False,
763+ """Check a folder by given name , if not exist, create the folder and return False,
756764 if directory exists, return True.
757765
758766 Parameters
759767 ----------
760768 path : a string
761769 A folder path.
762770 verbose : boolean
763- If true prints results, deaults to True
771+ If True, prints results, deaults is True
772+
773+ Returns
774+ --------
775+ True if folder exist, otherwise, returns False and create the folder
764776
765777 Examples
766778 --------
767779 >>> tl.files.exists_or_mkdir("checkpoints/train")
768780 """
769781 if not os .path .exists (path ):
770782 if verbose :
771- print ("[!] Create %s ..." % path )
783+ print ("[*] creates %s ..." % path )
772784 os .makedirs (path )
773785 return False
774786 else :
775787 if verbose :
776- print ("[* ] %s exists ..." % path )
788+ print ("[! ] %s exists ..." % path )
777789 return True
778790
779791def maybe_download_and_extract (filename , working_directory , url_source , extract = False , expected_bytes = None ):
0 commit comments