Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the advanced API encapsulated MagNet library based on PyTorch

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how the MagNet library, an advanced API package based on PyTorch, is concise and easy to understand. It will definitely make your eyes shine. I hope you can learn something from the detailed introduction of this article.

MagNet, a high-level API wrapper library based on the pytorch library, is very similar to Keras. Children who have written native Tensorflow must know that the process is uncomfortable, and later with keras, tensorlayer and so on, it is much more convenient. Unlike Tensorflow, pytorch is already easy to get started with, but with MagNet, pytorch will be simpler to write. Keras+Tensorflow, MagNet+pytorch will be the two best choices for getting started with deep learning. At present, the library is still under development, and there are still many bugs, but children's shoes who like pytorch may wish to try it first and follow up on the follow-up progress in time.

Address: https://github.com/MagNet-DL/magnet

0, Install Anaconda (www.anaconda.com)

1. Install magnet and create conda environment

$git clone https://github.com/svaisakh/magnet.git

$cd magnet && conda env update

2, Set environment variables, edit ~/.bashrc

export PYTHONPATH=$PYTHONPATH:

export MAGNET_DATAPATH=""

3. Execute script to make settings take effect

$source ~/.bashrc

4. Activate conda environment

$conda activate magnet

5. Test the simple network above first, and try the complex network after mastering the process.

class ResBlock(mn.Node): def __init__(self, c=None, p='same'): super().__ init__(c) def build(self, x): # Tell the ResBlock how it should build itself c = self._ args['c'] p = 'half' if c is None and self._ args['p'] != 'same' else 'same'self.convs = nn.Sequential(mn.Conv(c, p=p), mn.Conv(c, p='same', act=None)) super().build(x) def forward(self, x): res = self.convs(x) # If downsampling, pad using zerosif x.shape[-1] != res.shape[-1]: x = F.avg_pool2d(x, 2, 2, x.shape[2] % 2) x = torch.cat([x, torch.zeros(x.shape[0], res.shape[1] - x.shape[1], x.shape[2], x.shape[3])], dim=1) return F.relu(res + x) res_layer = lambda n, c=None: nn.Sequential(ResBlock(c, p='half'),*[ResBlock(c) for _ in range(n - 1)])resnet34 = nn.Sequential(mn.Conv(64, k=7), nn.MaxPool2d(3, 2, 1), res_layer(3, 64), res_layer(4), res_layer(6), res_layer(3), nn.AvgPool2d(7), mn.Linear(1000, act=None)).eval()

So that's PyTorch-based high-level API encapsulation. What's the MagNet library like? Have you learned anything? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report