mindflow.pde.SteadyFlowWithLoss

View Source On Gitee
class mindflow.pde.SteadyFlowWithLoss(model, loss_fn='mse')[source]

Base class of user-defined steady data-driven problems.

Parameters
  • model (mindspore.nn.Cell) – A training or test model.

  • loss_fn (Union[str, Cell]) – Loss function. Default: "mse".

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, nn
>>> import mindspore
>>> from mindflow.pde import SteadyFlowWithLoss
>>> from mindflow.core 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)[source]

Compute the loss of training or test model.

Parameters
  • inputs (Tensor) – The input data of model.

  • labels (Tensor) – True values of the samples.

Returns

float, loss value.