Load model from a given file, which should be previously saved by Model.save(). This function load can load both the architecture of neural networks and weights (optional, and needs to be saved in Model.save()). When a model is loaded by this function load, there is no need
(filepath, load_weights=True)
| 812 | |
| 813 | @staticmethod |
| 814 | def load(filepath, load_weights=True): |
| 815 | """ |
| 816 | Load model from a given file, which should be previously saved by Model.save(). |
| 817 | This function load can load both the architecture of neural networks and weights (optional, and needs to be saved in Model.save()). |
| 818 | When a model is loaded by this function load, there is no need to reimplement or declare the architecture of the model explicitly in code. |
| 819 | WARNING: If the model contains Lambda / ElementwiseLambda layer, please check the documentation of Lambda / ElementwiseLambda layer and find out the cases that have / have not been supported by Model.load(). |
| 820 | |
| 821 | Parameters |
| 822 | ---------- |
| 823 | filepath : str |
| 824 | Filename from which the model will be loaded. |
| 825 | load_weights : bool |
| 826 | Whether to load model weights. |
| 827 | |
| 828 | Examples |
| 829 | -------- |
| 830 | >>> net = tl.models.vgg16() |
| 831 | >>> net.save('./model.h5', save_weights=True) |
| 832 | >>> new_net = Model.load('./model.h5', load_weights=True) |
| 833 | """ |
| 834 | # TODO: support loading LambdaLayer that includes parametric self defined function with outside variables |
| 835 | M = utils.load_hdf5_graph(filepath=filepath, load_weights=load_weights) |
| 836 | return M |
| 837 | |
| 838 | def save_weights(self, filepath, format=None): |
| 839 | """Input filepath, save model weights into a file of given format. |
no outgoing calls