Yann LeCun推荐的Github深度学习入门教程,累计9500+星
▲ 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
4defcustom_where(cond, x_1, x_2):
5return (cond * x_1) + ((1-cond) * x_2)
6
7
8classPerceptron():
9def__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
15defforward(self, x):
16 linear = torch.add(torch.mm(x, self.weights), self.bias)
17 predictions = custom_where(linear > 0., 1, 0).float()
18return predictions
19
20defbackward(self, x, y):
21 predictions = self.forward(x)
22 errors = y - predictions
23return errors
24
25deftrain(self, x, y, epochs):
26for e in range(epochs):
27
28for 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
34defevaluate(self, x, y):
35 predictions = self.forward(x).view(-1)
36 accuracy = torch.sum(predictions == y).float() / y.size()[0]
37return accuracy
推荐阅读
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。