【GitHub项目推荐--Yann LeCun推荐的Github深度学习入门教程】【转载】

▲ Yann LeCun的Twitter

▲ Sebastian Raschka的Twitter:

作者:Sebastian Raschka

项目:Deep Learning Models

Star:9500+⭐

项目链接(点击阅读原文即可访问):

https://github.com/rasbt/deeplearning-models

内容:包含了由TensorFlow/PyTorch实现的80个模型,覆盖了从传统机器学习(逻辑回归、感知器等)到高阶深度网络应用(对抗生成网络等)的内容。具体如下(每个目录下有多个case):

  • 传统机器学习

  • 多层感知器

  • 卷积神经网络

  • 度量学习

  • 自编码器

  • 生成式对抗网络

  • 循环神经网络

  • 有序回归

  • 建议和技巧

  • PyTorch工作流和机制

  • TensorFlow工作流和机制

示例代码(定义感知机)

 1device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
 2
 3
 4def custom_where(cond, x_1, x_2):
 5    return (cond * x_1) + ((1-cond) * x_2)
 6
 7
 8class Perceptron():
 9    def __init__(self, num_features):
10        self.num_features = num_features
11        self.weights = torch.zeros(num_features, 1, 
12                                   dtype=torch.float32, device=device)
13        self.bias = torch.zeros(1, dtype=torch.float32, device=device)
14
15    def forward(self, x):
16        linear = torch.add(torch.mm(x, self.weights), self.bias)
17        predictions = custom_where(linear > 0., 1, 0).float()
18        return predictions
19
20    def backward(self, x, y):  
21        predictions = self.forward(x)
22        errors = y - predictions
23        return errors
24
25    def train(self, x, y, epochs):
26        for e in range(epochs):
27
28            for i in range(y.size()[0]):
29                # use view because backward expects a matrix (i.e., 2D tensor)
30                errors = self.backward(x[i].view(1, self.num_features), y[i]).view(-1)
31                self.weights += (errors * x[i]).view(self.num_features, 1)
32                self.bias += errors
33
34    def evaluate(self, x, y):
35        predictions = self.forward(x).view(-1)
36        accuracy = torch.sum(predictions == y).float() / y.size()[0]
37        return accuracy

原文链接:

 Yann LeCun推荐的Github深度学习入门教程,累计9500+星

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值