lizhihao 7ecfc026c5 | 8 months ago | |
---|---|---|
.. | ||
checkpoints | 3 months ago | |
README.md | 3 months ago | |
README_CN.md | 3 months ago | |
example_grad_net.py | 3 months ago | |
example_load_ckpt.py | 3 months ago | |
example_net.py | 3 months ago |
ENGLISH | 简体中文
SciAI base framework consists of several modules covering network setup, network training, validation and auxiliary functions.
The following simple example, indicating the fundamental processes in using SciAI.
The principle of setting up a neural networks in ScAI is the same as in MindSpore,
but in SciAI it is much easier. The following code segment creates a neural networks with 2-D input, 1-D output and two 5-D hidden layers.
from sciai.architecture import MLP
example_net = MLP(layers=[2, 5, 5, 1], weight_init=XavierTruncNormal(), bias_init='zeros', activation="tanh")
MLP
accepts various initialization method and all activation functions provided by MindSpore.
We define the loss function as a sub-class of Cell, and calculate the loss in method construct
.
from mindspore import nn
from sciai.architecture import MSE
class ExampleLoss(nn.Cell):
def __init__(self, network):
super().__init__()
self.network = network
self.mse = MSE()
def construct(self, x, y_true):
y_predict = self.network(x)
return self.mse(y_predict - y_true)
example_loss = ExampleLoss(example_net)
At this moment, we can calculate the prediction loss by calling example_loss
with input x
and ground truth y_true
.
Then, by creating instance of trainer class provided by SciAI, we can start training with datasets.
from mindspore import nn
from sciai.common import TrainCellWithCallBack
from sciai.context.context import init_project
# Get the correct platform automatically and set to GRAPH_MODE by default.
init_project()
example_optimizer = nn.Adam(example_loss.trainable_params())
example_trainer = TrainCellWithCallBack(example_loss, example_optimizer, loss_interval=100, time_interval=100)
for _ in range(num_iters):
example_trainer(x_train, y_true)
When the training of example_net
is finished and loss converges, we can use the net to predict the value at x
by calling y = example_net(x)
.
The complete example code can be found in ./example_net.py
.
Ths example network only indicates the basic ability of SciAI framework and fundamental training process for a neural network.
With this exmpale, you can understand the models in the following model library better, how each model are trained and validated with SciAI and MindSpore.
MindScience is scientific computing kits for various industries based on the converged MindSpore framework.
Jupyter Notebook Python Unity3D Asset Pickle nesC other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》