Fast Visual Neural Network Design with PrototypeML.com

栏目: IT技术 · 发布时间: 4年前

内容简介:Third, we implement “Block” containers to encapsulate the relationships between child nodes. A block component represents anTo generate code (accessible either via the small download button in the interface, or the View Code button in the block editor), th

Blocks

Third, we implement “Block” containers to encapsulate the relationships between child nodes. A block component represents an nn.Module class, and is represented by a visual graph. Mutators and other blocks may be added to the graph as nodes by dragging and dropping from the library bar, and the edges drawn between the various nodes represents the data flow of the neural network model.

ResNet Bottleneck Layer Demonstrating Skip Connections. Image by author.

Code generation

To generate code (accessible either via the small download button in the interface, or the View Code button in the block editor), the block graph is traversed, and mutator and block init() and forward() code sections are combined into their respective functions, and input and output dependencies and parameters between the various components are resolved. With one click, you can download the compiled code for your model, including all dependencies, conda/pip environment/requirements files etc.

Building an MNIST Classifier

With the nitty-gritty details out of the way, let’s see how all this can help us prototype a neural network faster! We’re going to be building a basic MNIST classifier, since that’s pretty much the “Hello World” of neural networks (however don’t worry, producing a similar network to handle CIFAR-10, or even ImageNet is just as easy!). The project detailed below can be found at https://prototypeml.com/prototypeml/mnist-classifier . Go ahead and fork it (after you’ve created an account), so you can follow along.

  1. Sign in /R egister and fork the MNIST classifier project.
  2. On your project’s page, click the Edit Model button on the top right side. This will bring you to the model editor interface. On your left hand side is the library bar where all your components are managed. In the middle is where you’ll code your mutators, and build your blocks. On the right side is where you edit mutator, block, and component instance properties.
  3. First, add the already built (and automatically generated) PyTorch library from the Package Repository. In the library bar, click the “Add” button, and select “Add Package Dependency”. Next, select PyTorch (it should be near the top), and click the “Use” button. This will add the package as a dependency to your project (same process for adding in any other dependency as well!). You should now see a Packages directory in your library bar. If you navigate into the Packages directory, and click PyTorch, you’ll find the entire PyTorch neural network function library.
  4. Go back to your root directory (click the “/” in the breadcrumbs below the “Add” button), and add a Block through the “Add” button (name it whatever you’d like). Click the block to open it, and you’ll be presented with the block editing interface. If you again navigate to the Packages/PyTorch directory, you can now drag any of the components available within one of the subfolders into your project.
  5. Go ahead and start building your model: Drag components into the block editor from the library bar and begin connecting them by dragging edges from output ports to input ports (ports are the circles at the top/bottom of a component instance). Click on a component instance to view and set the parameters specific to that component. Feel free to view the example project if you want some help figuring out what to drag in.
  6. At any point while in the block editor, click the “</>“ button in the block editor toolbar to view the code that will be generated — explore how the code changes as you drag components and connect them together. Notice that when two edges enter a single input port, the code will automatically include a concatenation operation (configure this, or change it to an alternative combination function by clicking on the input port).
  7. Once you’ve finished editing your model, click the download code button next to the “Add” button in the library bar so you can begin training.

Using an External Library & Designing Mutators

Up until this point we’ve used mutators included in the PyTorch library, however if you find that you need a certain component for which a mutator hasn’t been written in the Package Repository (or you’d like to include entirely custom code in your network) you’ll need to design your own. We’ll build a mutator wrapping a PyTorch implementation of the EfficientNet library .

  1. First, add a mutator by clicking the “Add” button.
  2. In the Properties bar on the right side of the editor, add the two parameters needed for this mutator (model name, and number of output classes) by clicking the “+” button near Parameters.
  3. We’ll need to import the library in the Imports section, like so:
from efficientnet_pytorch import EfficientNet

4. Next, let’s write the code in the Init section necessary to initialize the EfficientNet model, like so. Notice how we use the magic variables ${instance} instead of a variable name, and fill in the parameters using the ${params.<name>} syntax:

self.${instance} = EfficientNet.from_pretrained(${params.model}, num_classes=${params.num_classes})

5. Finally, write the code necessary to call the EfficientNet model in the Forward section, like so (again, notice how we’re using the magic variables ${ports.<name>} to refer to the input/output variables, and ${instance} as before):

${ports.output} = self.${instance}(${ports.input})

6. And we’re done! When dragged into a block (with the configuration set to: name=‘efficientnet’, model=‘efficientnet-b0’, num_classes=10), this mutator will produce the following code (assuming the rest of the block is empty):

import torch
from efficientnet_pytorch import EfficientNetclass EfficientNet_Classifier(torch.nn.Module):
    def __init__(self):
        super(EfficientNet_Classifier, self).__init__() 

        self.efficientnet = EfficientNet.from_pretrained('efficientnet-b0', num_classes=10)def forward(self, input):
        efficientnet_output = self.efficientnet(input)

        return efficientnet_output

The full MNIST example can be found at https://prototypeml.com/prototypeml/mnist-classifier .

Conclusion

PrototypeML implements a powerful and intuitive interface and component standard to allow for quick prototyping of powerful neural network architectures and experiments. We’d love to hear your thoughts and feedback on the platform, and look forward to moving from alpha to beta in the near future. You can access the platform at https://PrototypeML.com, the preprint paper here , the documentation at https://Docs.PrototypeML.com, and our Discord community channel at https://discord.gg/zq8uqSf .


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

大数据技术原理与应用

大数据技术原理与应用

林子雨 / 人民邮电出版社 / 2015-8-1 / 45.00

大数据作为继云计算、物联网之后IT行业又一颠覆性的技术,备受关注。大数据处不在,包括金融、汽车、零售、餐饮、电信、能源、政务、医疗、体育、娱乐等在内的社会各行各业,都融入了大数据的印迹,大数据对人类的社会生产和生活必将产生重大而深远的影响。 大数据时代的到来,迫切需要高校及时建立大数据技术课程体系,为社会培养和输送一大批具备大数据专业素养的高级人才,满足社会对大数据人才日益旺盛的需求。本书定......一起来看看 《大数据技术原理与应用》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具