机器学习图形生成库

aifig的Python项目详细描述


人工智能图

目的

aifig是一个python库,用于生成机器学习模型的图形。

libary允许您生成以下图形,这些图形可能对演示文稿、论文等有用。

aifig是我的一些个人代码的重构版本。功能自然会受到限制,不适合每次使用。我鼓励任何有兴趣贡献额外功能的人。

如果你在论文中使用aifig,你可以这样引用库(bibtex):

@misc{aifig,
  author = {Sigve Rokenes},
  title = {AI-FIG},
  year = {2019},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/evgiz/aifig}}}

安装

带有SVG导出的AI-FIG库:

pip install aifig

如果需要导出为PNG或PDF格式:

pip install svglib

用法

简单示例
# Import libraryimportaifig# Create new figure, title and author is optionalmy_figure=aifig.figure("Figure 1","Sigve Rokenes")# Figures consist of graphs (eg. each network in a model)my_graph=aifig.graph("gen")# Graphs contain elements (inputs, outputs, layers)my_graph.add(aifig.dense("input",16))my_graph.add(aifig.dense("hidden_1",64))my_graph.add(aifig.dense("hidden_2",128))my_graph.add(aifig.dense("hidden_3",64))my_graph.add(aifig.dense("output",1))my_graph.add(aifig.arrow("prediction"))# Add the graph to the figure at position (0,0)my_figure.add(graph,0,0)# Save the figure my_figure.save_png("my_figure.png",scale=1)my_figure.save_svg("my_figure.svg")my_figure.save_pdf("my_figure.pdf")

以上代码生成此图:

多图示例(gan模型)

importaifigfigure=aifig.figure()# Define generator networkgenerator_elements=[aifig.dense("noise_vector",128,comment="norm_dist",simple=True),aifig.conv("tconv_1",48,comment="5x5"),aifig.conv("tconv_2",32,comment="5x5"),aifig.conv("tconv_3",8,comment="5x5"),aifig.conv("tconv_4",3,comment="5x5"),aifig.image("gen_result",comment="(fake image)")]# Define discriminator networkdiscriminator_elements=[aifig.image("image_input",comment="real/fake"),aifig.conv("conv_1",16,comment="5x5"),aifig.pool("max_pool")aifig.conv("conv_2",32,comment="5x5"),aifig.pool("max_pool"),aifig.conv("conv_3",48,comment="5x5"),aifig.dense("dense_1",64),aifig.dense("output",1),aifig.arrow("prediction",comment="log prob")]# Create graphs with elementsgen_graph=aifig.graph("gen",generator_elements)dsc_graph=aifig.graph("dsc",discriminator_elements)dat_graph=aifig.graph("dat",[aifig.image("real_image",comment="(dataset)")])# Add graphs to figurefigure.add(gen_graph,0,0)figure.add(dat_graph,1,0)figure.add(dsc_graph,0,1)# Connect inputs to discriminator networkfigure.connect("gen","dsc")figure.connect("dat","dsc")# Save figure as pngfigure.save_png("gan.png")

此代码生成下图:

API

图形由一个或多个图形组成。这些图使用figure.add(graph, x, y)放置在网格中。可以使用mygraph.add(element)将元素添加到图中,也可以使用figure.connect("graph_name1", "graph_name2")将图与箭头连接。最后,要保存一个图形,使用不同格式的my_figure.save_svg("fig.svg")或变体。

# ===================== ##        Figure         ## ===================== ##  title			figure title#  author			figure authormy_figure=aifig.figure()# figure.add#  graph			graph to add#  x				x position in grid#  y				y position in gridmy_figure.add(graph,0,0)# figure.connect#  from				name of first graph#  to				name of second graph#  position			grid position of arrow, use this if #				different arrows overlap#  offset			arrow offset in units, useful to#				distinguish different arrows at same positionmy_figure.connect("graph1","graph2")# figure.save (path)#  path				file path to save to#  scale			upscale (png only)#  debug			enable debug draw modemy_figure.save_png("my_figure.png",scale=1)my_figure.save_svg("my_figure.svg")my_figure.save_pdf("my_figure.pdf")# ===================== ##         Graph         ## ===================== ## 	name			(required)# 	elements		[list of elements]# 	spacing			(between elements, default 32)my_graph=aifig.graph("graph_name")my_graph.add(element)# ===================== ##    Layer elements     ## ===================== ## 	label			text label, use None to hide# 	size			size of layer (nodes, filters)#	comment			additional comment text#	size_label		set to False to hide size label#	simple			(dense only) set True to render as simple rectangledense=aifig.dense()# Dense (fully connected)conv=aifig.conv()# Convolutional layer# ===================== ##    Simple elements    ## ===================== ##	label			text label, use None to hide#	comment			additional comment textpool=aifig.pool()# Pooling layerimage=aifig.image()# Image (usually input)arrow=aifig.arrow()# Arrow# ===================== ##    Special elements   ## ===================== ## 	width			width of padding (use negative to reduce)padding=aifig.padding(10)

依赖性

  • svgwrite
  • svglib(仅保存为pdf/png)
  • ReportLab(仅保存为PDF/PNG)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java无法从spring resttemplate访问sms网关   使用spark上下文方法参数的java并行化集合不正确   java中ReadLock的并发检查副本   java基于属性比较两个列表是否具有相同的元素   字符串Java文本块:缩进前缀中的制表符和空格的混合   java如何将带有@SpringBootApplication的maven模块作为测试范围中的依赖项添加到另一个maven模块   我需要一些关于在Java中使用2个jar文件的帮助   mysql JPA Java Spring Boot执行查找/连接表   java对话框选择具有特定名称的文件   java如何修复Spring工具套件4中的端口8080错误?   Java中的apache poi Excel阅读器   java如何在tomcat访问日志中记录线程上下文值   java有一种方法可以创建类<T>的实例,该类将类作为传递泛型的构造函数中的参数   默认情况下,java GORM onetomany映射执行即时抓取   java不能在安卓中接受全局变量   统计系统的java MongoDB异步驱动程序排名   java如何解析:无法解析插件“org.springframework.ide.eclipse.ui”?   用Java从一副牌中随机抽取5张牌   javaapachecamel动态消费者   java如何克服使用Flood Fill 4算法时的“薄边界”问题?