Fast Visual Neural Network Design with PrototypeML.com

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

内容简介: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 .


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

查看所有标签

猜你喜欢:

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

C++编程思想(第1卷)

C++编程思想(第1卷)

[美] Bruce Eckel / 刘宗田、袁兆山、潘秋菱 / 机械工业出版社 / 2002-9 / 59.00元

《C++编程思考》第2版与第1版相比,在章节安排上有以下改变。增加了两章:“对象的创建与使用”和“C++中的C”,前者与“对象导言”实际上是第1版“对象的演化”一章的彻底重写,增加了近几年面向对象方法和编程方法的最瓣研究与实践的有效成果,后者的添加使不熟悉C的读者可以直接使用这本书。删去了四章:“输入输出流介绍”、“多重继承”、“异常处理”和“运行时类型识别”,删去的内容属于C++中较复杂的主题,......一起来看看 《C++编程思想(第1卷)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器