mindscience.models.neural_operator.FNO2D
- class mindscience.models.neural_operator.FNO2D(in_channels, out_channels, n_modes, resolutions, hidden_channels=20, lifting_channels=None, projection_channels=128, n_layers=4, data_format='channels_last', fnoblock_act='gelu', mlp_act='gelu', add_residual=False, positional_embedding=True, dft_compute_dtype=mstype.float32, fno_compute_dtype=mstype.float16)[source]
The 2D Fourier Neural Operator, which usually contains a Lifting Layer, a Fourier Block Layer and a Projection Layer. The details can be found in Zongyi Li, et. al: FOURIER NEURAL OPERATOR FOR PARAMETRIC PARTIAL DIFFERENTIAL EQUATIONS.
- Parameters
in_channels (int) – The number of channels in the input space.
out_channels (int) – The number of channels in the output space.
n_modes (Union[int, list(int)]) – The number of modes reserved after linear transformation in Fourier Layer.
resolutions (Union[int, list(int)]) – The resolutions of the input tensor.
hidden_channels (int, optional) – The number of channels of the FNOBlock input and output. Default:
20.lifting_channels (int, optional) – The number of channels of the lifting layer mid channels. Default:
None.projection_channels (int, optional) – The number of channels of the projection layer mid channels. Default:
128.n_layers (int, optional) – The number that Fourier Layer nests. Default:
4.data_format (str, optional) – The input data channel sequence. Support value:
"channels_last","channels_first". Default:"channels_last".fnoblock_act (Union[str, class], optional) – The activation function for FNOBlock, could be either str or class. Default:
"gelu".mlp_act (Union[str, class], optional) – The activation function for MLP layers, could be either str or class. Default:
"gelu".add_residual (bool, optional) – Whether to add residual in FNOBlock or not. Default:
False.positional_embedding (bool, optional) – Whether to embed positional information or not. Default:
True.dft_compute_dtype (dtype.Number, optional) – The computation type of DFT in SpectralConvDft. Default:
mstype.float32.fno_compute_dtype (dtype.Number, optional) – The computation type of MLP in fno skip. Should be
mstype.float32ormstype.float16.mstype.float32is recommended for the GPU backend,mstype.float16is recommended for the Ascend backend. Default:mstype.float16.
- Inputs:
x (Tensor) - Tensor of shape \((batch\_size, resolution[0], resolution[1], in\_channels)\).
- Outputs:
output (Tensor) -Tensor of shape \((batch\_size, resolution[0], resolution[1], out\_channels)\).
- Raises
ValueError – If the dimension of n_modes is not equal to
2.ValueError – If the dimension of resolutions is not equal to
2.
Examples
>>> import numpy as np >>> import mindspore >>> from mindspore import Tensor >>> import mindspore.common.dtype as mstype >>> from mindscience.models.neural_operator.fno import FNO2D >>> data = Tensor(np.ones([2, 128, 128, 3]), mstype.float32) >>> net = FNO2D(in_channels=3, out_channels=3, n_modes=[20, 20], resolutions=[128, 128]) >>> out = net(data) >>> print(data.shape, out.shape) (2, 128, 128, 3) (2, 128, 128, 3)