mindflow.pde.SteadyFlowWithLoss

class mindflow.pde.SteadyFlowWithLoss(model, loss_fn='mse')[源代码]

基于数据驱动的定常流动问题求解的基类。

参数:
  • model (mindspore.nn.Cell) - 用于训练或测试的网络模型。

  • loss_fn (Union[str, Cell]) - 损失函数。默认值: 'mse'

支持平台:

Ascend GPU

样例:

>>> import numpy as np
>>> from mindspore import Tensor, nn
>>> import mindspore
>>> from mindflow.pde import SteadyFlowWithLoss
>>> from mindflow.loss import RelativeRMSELoss
...
>>> class Net(nn.Cell):
...    def __init__(self, num_class=10, num_channel=1):
...        super(Net, self).__init__()
...        self.conv1 = nn.Conv2d(num_channel, 6, 5, pad_mode='valid')
...        self.conv2 = nn.Conv2d(6, 16, 5, pad_mode='valid')
...        self.fc1 = nn.Dense(16*5*5, 120, weight_init='ones')
...        self.fc2 = nn.Dense(120, 84, weight_init='ones')
...        self.fc3 = nn.Dense(84, num_class, weight_init='ones')
...        self.relu = nn.ReLU()
...        self.max_pool2d = nn.MaxPool2d(kernel_size=2, stride=2)
...        self.flatten = nn.Flatten()
...
...    def construct(self, x):
...        x = self.max_pool2d(self.relu(self.conv1(x)))
...        x = self.max_pool2d(self.relu(self.conv2(x)))
...        x = self.flatten(x)
...        x = self.relu(self.fc1(x))
...        x = self.relu(self.fc2(x))
...        x = self.fc3(x)
...        return x
...
>>> model = Net()
>>> problem = SteadyFlowWithLoss(model, loss_fn=RelativeRMSELoss())
...
>>> inputs = Tensor(np.random.randn(32, 1, 32, 32), mindspore.float32)
>>> label = Tensor(np.random.randn(32, 10), mindspore.float32)
>>> loss = problem.get_loss(inputs, label)
>>> print(loss)
680855.1
get_loss(inputs, labels)[源代码]

计算训练或测试模型的损失。

参数:
  • inputs (Tensor) - 模型输入数据。

  • labels (Tensor) - 样本真实值。

返回:

float,损失值。