昇思25天学习打卡营第5天|网络构建

we check how is the network created.

Hopefully this blog can be helpful, so I would try to depicit t more detailed.

This is what your need. Surely you can also use other architectures, the principles are the same,

%%capture captured_output
# 实验环境已经预装了mindspore==2.2.14,如需更换mindspore版本,可更改下面mindspore的版本号
!pip uninstall mindspore -y
!pip install -i https://pypi.mirrors.ustc.edu.cn/simple mindspore==2.2.14

import mindspore
from mindspore import nn, ops

in I show a cell first:

class Network(nn.Cell):
    def __init__(self):
        super().__init__()
        self.flatten = nn.Flatten()
        self.dense_relu_sequential = nn.SequentialCell(
            nn.Dense(28*28, 512, weight_init="normal",bias_init="zeros"),
            nn.Relu(),
            nn.Dense(512, 512, weight_init="init",bias_init = "zeros"),
            nn.Relu(),
            nn.Dense(512, 10, weight_init="normal", bias_init="zeros")
        )
    def construct(self, x):
        x = self.flatten(x)
        logits = self.dense_relu_sequential(x)
        return logits

in code above. it is just needed to remember 2 item: init and construct.

In fact, init  is just tell what the blocks you want look like, and construct just connect them.

For example, 'Dense' means a kind of block(layer) that every neuron is connected to each other, and 'relu' is a acitvation function doing nothing but control some calculations and pass the result to next layer.'Construct', or 'forward' sometimes, means you building a Lego hall by stacking each layer, i.e. you choose 1st floor to be kitchen, 2nd to be auditory... they are connected in someway(just the order you choose.)   

other network like resnet, googlenet follows this classical architecture with different blocks and constructions.

we run:

model = Network()

we print(model)
 and see some strange thing:

Network<
  (flatten): Flatten<>
  (dense_relu_sequential): SequentialCell<
    (0): Dense<input_channels=784, output_channels=512, has_bias=True>
    (1): ReLU<>
    (2): Dense<input_channels=512, output_channels=512, has_bias=True>
    (3): ReLU<>
    (4): Dense<input_channels=512, output_channels=10, has_bias=True>
    >
  >

we do not need to dive into it to check our model, since we just think it like your brain, you have lots of neurons and they connected in all kinds of ways, but we just care the input and output, and how your neuron works leaves for those biologists.

X = ops.ones((1,28,28),mindspore.float32)
logits = model(X)
logits

logits is what we predict,all though we didnot even train the model,

random values. 10 is the output channels that we chosen in :

nn.Dense(512, 10, weight_init="normal",bias_init="zeros")

so  what we train is just those weight and bias.

for example, now our bias in each dense layer is zeros, so we can check them:

for name, param in model.parameters_and_names():
    print(f"layer:{name}\n Size:{param.shape}\nValues:{param[:2]}\n")

one layer may have weight and bias:

 

later we train them. If any errors, thanks for pointing out.

  • 25
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的微信小程序制作学习计划打卡记录页面的代码示例,其中包含了前几学习时间: ``` <view class="container"> <view class="header"> <text>学习计划打卡记录</text> </view> <view class="content"> <view class="card"> <view class="card-header"> <text>今</text> <text>2021-07-01</text> </view> <view class="card-body"> <view class="card-row"> <text>学习时间:</text> <input type="number" placeholder="请输入学习时间(分钟)"/> </view> </view> </view> <view class="card"> <view class="card-header"> <text>昨</text> <text>2021-06-30</text> </view> <view class="card-body"> <view class="card-row"> <text>学习时间:</text> <input type="number" placeholder="请输入学习时间(分钟)"/> </view> <view class="card-row"> <text>已学习:</text> <text>120分钟</text> </view> </view> </view> <view class="card"> <view class="card-header"> <text>前</text> <text>2021-06-29</text> </view> <view class="card-body"> <view class="card-row"> <text>学习时间:</text> <input type="number" placeholder="请输入学习时间(分钟)"/> </view> <view class="card-row"> <text>已学习:</text> <text>90分钟</text> </view> </view> </view> </view> </view> ``` 在上面的代码中,我们使用了三个 `card` 元素来展示前几打卡记录。每个 `card` 元素都包含一个 `card-header` 元素和一个 `card-body` 元素。`card-header` 元素中包含了日期信息,而 `card-body` 元素中包含了输入框和已学习时间的显示。 在实际开发中,你需要将上面的代码替换成你自己的样式和数据。同时,你还需要编写处理用户输入和计算已学习时间的逻辑代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值