@@ -555,26 +555,7 @@ def save(obj, path, protocol=2, **configs):
555
555
paddle.save(obj, path)
556
556
557
557
558
- # example 3: Save layer
559
- import paddle
560
- from paddle import nn
561
-
562
- class LinearNet(nn.Layer):
563
- def __init__(self):
564
- super(LinearNet, self).__init__()
565
- self._linear = nn.Linear(224, 10)
566
-
567
- def forward(self, x):
568
- return self._linear(x)
569
-
570
- inps = paddle.randn([1, 224], dtype='float32')
571
- layer = LinearNet()
572
- layer.eval()
573
- path = "example/layer.pdmodel"
574
- paddle.save(layer,path)
575
-
576
-
577
- # example 4: static graph
558
+ # example 3: static graph
578
559
import paddle
579
560
import paddle.static as static
580
561
@@ -601,7 +582,7 @@ def forward(self, x):
601
582
path_state_dict = 'temp/model.pdparams'
602
583
paddle.save(prog.state_dict("param"), path_tensor)
603
584
604
- # example 5 : save program
585
+ # example 4 : save program
605
586
import paddle
606
587
607
588
paddle.enable_static()
@@ -796,27 +777,7 @@ def load(path, **configs):
796
777
obj_load = paddle.load(path)
797
778
798
779
799
- # example 3: Load layer
800
- import paddle
801
- from paddle import nn
802
-
803
- class LinearNet(nn.Layer):
804
- def __init__(self):
805
- super(LinearNet, self).__init__()
806
- self._linear = nn.Linear(224, 10)
807
-
808
- def forward(self, x):
809
- return self._linear(x)
810
-
811
- inps = paddle.randn([1, 224], dtype='float32')
812
- layer = LinearNet()
813
- layer.eval()
814
- path = "example/layer.pdmodel"
815
- paddle.save(layer,path)
816
- layer_load=paddle.load(path)
817
-
818
-
819
- # example 4: static graph
780
+ # example 3: static graph
820
781
import paddle
821
782
import paddle.static as static
822
783
@@ -846,7 +807,7 @@ def forward(self, x):
846
807
load_state_dict = paddle.load(path_tensor)
847
808
848
809
849
- # example 5 : load program
810
+ # example 4 : load program
850
811
import paddle
851
812
852
813
paddle.enable_static()
0 commit comments