@@ -40,8 +40,18 @@ class L2Rel(base.Metric):
4040 keep_batch (bool, optional): Whether keep batch axis. Defaults to False.
4141
4242 Examples:
43- >>> import ppsci
44- >>> metric = ppsci.metric.L2Rel()
43+ >>> import paddle
44+ >>> from ppsci.metric import L2Rel
45+ >>> output_dict = {'u': paddle.to_tensor([[0.5, 0.9], [1.1, -1.3]]),
46+ ... 'v': paddle.to_tensor([[0.5, 0.9], [1.1, -1.3]])}
47+ >>> label_dict = {'u': paddle.to_tensor([[-1.8, 1.0], [-0.2, 2.5]]),
48+ ... 'v': paddle.to_tensor([[0.1, 0.1], [0.1, 0.1]])}
49+ >>> loss = L2Rel()
50+ >>> result = loss(output_dict, label_dict)
51+ >>> print(result)
52+ {'u': Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
53+ 1.42658269), 'v': Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
54+ 9.69535923)}
4555 """
4656
4757 # NOTE: Avoid divide by zero in result
@@ -85,8 +95,24 @@ class MeanL2Rel(base.Metric):
8595 keep_batch (bool, optional): Whether keep batch axis. Defaults to False.
8696
8797 Examples:
88- >>> import ppsci
89- >>> metric = ppsci.metric.MeanL2Rel()
98+ >>> import paddle
99+ >>> from ppsci.metric import MeanL2Rel
100+ >>> output_dict = {'u': paddle.to_tensor([[0.5, 0.9], [1.1, -1.3]]),
101+ ... 'v': paddle.to_tensor([[0.5, 0.9], [1.1, -1.3]])}
102+ >>> label_dict = {'u': paddle.to_tensor([[-1.8, 1.0], [-0.2, 2.5]]),
103+ ... 'v': paddle.to_tensor([[0.1, 0.1], [0.1, 0.1]])}
104+ >>> loss = MeanL2Rel()
105+ >>> result = loss(output_dict, label_dict)
106+ >>> print(result)
107+ {'u': Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
108+ 1.35970235), 'v': Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
109+ 9.24504089)}
110+ >>> loss = MeanL2Rel(keep_batch=True)
111+ >>> result = loss(output_dict, label_dict)
112+ >>> print(result)
113+ {'u': Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
114+ [1.11803389, 1.60137081]), 'v': Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
115+ [6.32455540 , 12.16552544])}
90116 """
91117
92118 # NOTE: Avoid divide by zero in result
0 commit comments