打印pytorch每一层的输入输出

打印pytorch每层参数。

采用的是直接在层中加入txt的写入。需要修改的文件位置:./site-packages/torch/nn/modules/

Conv2D

        v = F.conv2d(input, self.weight, self.bias, self.stride,self.padding, self.dilation, self.groups)

        v = v.detach()

        v = v.cpu().numpy().flatten()

        fp = open('conv2d.txt', 'w')

        for d in v:

            fp.write(str(d)+'\n')

        print('conv2d has Convert Completely!') 

        fp.close()  

 

输入数据input

        v = label.detach()

        v = v.cpu().numpy().flatten()

        fp = open('input.txt', 'w')

        for d in v:

            fp.write(str(d)+'\n')

        print('input has Convert Completely!') 

        fp.close()  

其它层仿照上面的就可以了。

posted @ 2020-10-28 11:33  皮卡皮卡妞  阅读(2153)  评论(0编辑  收藏  举报