使用FPGA创建AND / OR / NAND / XOR电路,这可能是使用Polyphony进行深度学习所必需的 |
您所在的位置:网站首页 › py中item › 使用FPGA创建AND / OR / NAND / XOR电路,这可能是使用Polyphony进行深度学习所必需的 |
从头开始阅读深度学习 从头开始编写的《深度学习》这本书很棒。使用Python进行学习正如"深度学习"的副标题所示,这本书旨在通过从头开始使用Python创建深度学习应用程序(?算法?)来加深您的理解。 本书首先制作AND,OR,NAND,XOR。我觉得自己不知所措,但是让我们用Polyphony编译它们并将它们变成硬件。 来源取自github上的以下URL。 https://github.com/ryos36/polyphony-tutorial/ 如果想轻松尝试,请安装polyphony和iverilog,克隆上述URL,然后使用simu.py运行每个源。 12345> pip3 install polyphony > git clone https://github.com/ryos36/polyphony-tutorial/ > cd polyphony-tutorial/DeepLearning > ../bin/simu.py and.py这里总结了使用pyvenv进行的环境构建。 http://qiita.com/ryos36/items/7e7fce9078a79f782380 摘自第2章Perceptron让我们创建 2.3.1示例中所示的AND门。 和.py 123456789101112131415161718from polyphony import testbench def AND(x1, x2): w1, w2, theta = 5, 5, 7 tmp = x1*w1 + x2*w2 if tmp theta: return 1 @testbench def test(): print(AND(0, 0)) print(AND(1, 0)) print(AND(0, 1)) print(AND(1, 1)) test()在 书中,参数为0.5、0.5、0.7,但对于Polyphony,请将其更改为5、5、7的整数值。 (如果您现在考虑一下,也许2,2,3会更好) 结果如下。 12345678910111213[test-0.2.2] Persimmon:polyphony-tutorial> cd DeepLearning/ [test-0.2.2] Persimmon:DeepLearning> ../bin/simu.py and.py 0:AND_0_in_x1= x, AND_0_in_x2= x, AND_0_out_0= x 110:AND_0_in_x1= 0, AND_0_in_x2= 0, AND_0_out_0= x 160:AND_0_in_x1= 0, AND_0_in_x2= 0, AND_0_out_0= 0 0 180:AND_0_in_x1= 1, AND_0_in_x2= 0, AND_0_out_0= 0 0 250:AND_0_in_x1= 0, AND_0_in_x2= 1, AND_0_out_0= 0 0 320:AND_0_in_x1= 1, AND_0_in_x2= 1, AND_0_out_0= 0 370:AND_0_in_x1= 1, AND_0_in_x2= 1, AND_0_out_0= 1 1如预期。未经许可输出的神秘信息冒号左边的数字是时间(时钟号)。这是性能的粗略指南。 使用Python清单现在,我们使用Python列表。 和2.py 1234567891011121314151617181920212223242526272829303132333435from polyphony import testbench def list_mul(lst_r, lst_a, lst_b): for i in range(len(lst_r)): lst_r[i] = lst_a[i] * lst_b[i] def sum(lst): tmp = 0 for i in range(len(lst)): tmp = tmp + lst[i] return tmp def AND(x1, x2): lst_r = [0, 0] lst_a = [x1, x2] lst_b = [5, 5] b = -7 list_mul(lst_r, lst_a, lst_b) tmp = sum(lst_r) + b if tmp ../bin/simu.py and2.py 0:AND_0_in_x1= x, AND_0_in_x2= x, AND_0_out_0= x 110:AND_0_in_x1= 0, AND_0_in_x2= 0, AND_0_out_0= x 550:AND_0_in_x1= 0, AND_0_in_x2= 0, AND_0_out_0= 0 0 570:AND_0_in_x1= 1, AND_0_in_x2= 0, AND_0_out_0= 0 0 1030:AND_0_in_x1= 0, AND_0_in_x2= 1, AND_0_out_0= 0 0 1490:AND_0_in_x1= 1, AND_0_in_x2= 1, AND_0_out_0= 0 1930:AND_0_in_x1= 1, AND_0_in_x2= 1, AND_0_out_0= 1 1使用 列表添加了一些抽象,但是它减慢了速度,因为我对操作使用了for语句。 您也可以创建or.py和nand.py。复制和粘贴有点令人遗憾。 尝试制作XOR基于这些,创建一个XOR并执行它。 xor.py 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869from polyphony import testbench def list_mul(lst_r, lst_a, lst_b): for i in range(len(lst_r)): lst_r[i] = lst_a[i] * lst_b[i] def sum(lst): tmp = 0 for i in range(len(lst)): tmp = tmp + lst[i] return tmp def AND(x1, x2): lst_r = [0, 0] lst_a = [x1, x2] lst_b = [5, 5] b = -7 list_mul(lst_r, lst_a, lst_b) tmp = sum(lst_r) + b if tmp |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |