搭建一个简简单单的2D卷积神经网络

import torch
import torch.nn as nn
import torch.nn.functional as F
#2D卷积神经网络
input = torch.randn(1, 1, 28, 28)

# With square kernels and equal stride
conv1 = nn.Conv2d(1, 10, kernel_size=5)
conv2 = nn.Conv2d(10, 20, kernel_size=5)
conv2_drop = nn.Dropout2d()
fc1 = nn.Linear(320, 50)
fc2 = nn.Linear(50, 10)


X = F.relu(F.max_pool2d(conv1(input),2))
X = F.relu(F.max_pool2d(conv2_drop(conv2(X)),2))
X = X.view(-1, 320)
X = F.relu(fc1(X))
X = F.dropout(X, training=True)
X = fc2(X)
X = F.log_softmax(X, dim=0)


print("output shape is {}".format(X.shape))

=================

1、学会了如何快速调整、改变每一层张量的大小;

2、学会了 搭建网络模型准备训练数据 相互解耦的流程;

3、学会了 如何阅读别人网络结构;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个使用Canvas实现樱花飘落的页面,代码中有注释解释每个部分的作用: ```html <!DOCTYPE html> <html> <head> <title>樱花飘落页面</title> <style> body { margin: 0; padding: 0; background-color: #f9d2e9; } </style> </head> <body> <canvas id="canvas"></canvas> <script> // 获取canvas元素 var canvas = document.getElementById("canvas"); // 设置canvas大小为屏幕大小 canvas.width = window.innerWidth; canvas.height = window.innerHeight; // 获取画布上下文 var ctx = canvas.getContext("2d"); // 定义樱花花瓣数组 var sakuras = []; // 定义樱花花瓣类 function Sakura(x, y, r, vx, vy) { this.x = x; this.y = y; this.r = r; this.vx = vx; this.vy = vy; this.alpha = 1; this.color = "#FFC0CB"; } // 定义樱花花瓣渲染方法 Sakura.prototype.render = function() { ctx.beginPath(); ctx.globalAlpha = this.alpha; ctx.fillStyle = this.color; ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2); ctx.fill(); } // 定义樱花花瓣更新方法 Sakura.prototype.update = function() { // 计算新位置 this.x += this.vx; this.y += this.vy; // 计算新透明度 this.alpha -= 0.01; // 如果透明度小于等于0,就从数组中删除 if (this.alpha <= 0) { sakuras.splice(sakuras.indexOf(this), 1); } } // 定义樱花花瓣生成函数 function createSakura() { // 随机生成樱花花瓣的位置、大小和速度 var x = Math.random() * canvas.width; var y = -50; var r = Math.random() * 10 + 10; var vx = Math.random() * 2 - 1; var vy = Math.random() * 2 + 1; // 创建新的樱花花瓣对象并添加到数组中 var sakura = new Sakura(x, y, r, vx, vy); sakuras.push(sakura); } // 定义动画函数 function animate() { // 清空画布 ctx.clearRect(0, 0, canvas.width, canvas.height); // 每隔一段时间生成新的樱花花瓣 if (Math.random() > 0.9) { createSakura(); } // 遍历每个樱花花瓣,更新位置并渲染 for (var i = 0; i < sakuras.length; i++) { var sakura = sakuras[i]; sakura.update(); sakura.render(); } // 循环调用动画函数 requestAnimationFrame(animate); } // 启动动画函数 animate(); </script> </body> </html> ``` 这个页面使用Canvas实现了樱花花瓣的飘落效果,每隔一段时间会随机生成新的花瓣,并使用透明度和速度控制花瓣的位置和渲染。通过循环调用动画函数,使得花瓣会不断地飘落,营造出樱花飞舞的效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值