博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Gluon 参数读取
阅读量:7059 次
发布时间:2019-06-28

本文共 1001 字,大约阅读时间需要 3 分钟。

ndarray: save , load

from mxnet import ndfrom mxnet.gluon import nnx = nd.ones(3)# nd.save('x',x)# x2 = nd.load('x')# print(x2)y = nd.zeros(4)# print([x,y])# nd.save('xy',[x,y])# x2, y2 = nd.load('xy')# print(x2,y2)mydict = {
'x':x,'y':y}# nd.save('mydict',mydict)# mydict2 = nd.load('mydict')# print(mydict2)

Gluon 模型参数:save_parameters , load_parameters

from mxnet import ndfrom mxnet.gluon import nnclass MLP(nn.Block):    def __init__(self, **kwargs):        super(MLP, self).__init__(**kwargs)        self.hidden = nn.Dense(256,activation='relu')        self.output = nn.Dense(10)    def forward(self, x):        return self.output(self.hidden(x))# net = MLP()# net.initialize()# X = nd.random.uniform(shape=(2,20))# Y = net(X)# print(Y)# nd.save('X',X)# nd.save('Y',Y)filename = 'mlp.params'# net.save_parameters(filename)net2 = MLP()net2.load_parameters(filename)X = nd.load('X')Y = nd.load('Y')# print(X[0])Y2 = net2(X[0])print(Y[0]==Y2)

 

转载于:https://www.cnblogs.com/TreeDream/p/10237373.html

你可能感兴趣的文章
约瑟夫环(Josehpuse)的模拟
查看>>
CSS小技巧
查看>>
正则匹配 
查看>>
shell 读取文件
查看>>
给视图添加阴影
查看>>
数组2
查看>>
在django中,执行原始sql语句
查看>>
配置eclipse使能打开当前文件所在目录
查看>>
Repeater内RadioButton.GroupName失效
查看>>
【算法学习笔记】17.暴力求解法05 隐式图搜索1 迭代加深搜索 埃及分数
查看>>
X-Frame-Options,X-XSS-Protection,X-Content-Type-Options
查看>>
每日一句(15)
查看>>
读书笔记--SQL必知必会--建立练习环境
查看>>
捕获、冒泡
查看>>
P3369 【模板】普通平衡树(Treap/SBT)
查看>>
托管代码的进程注入&CLR宿主
查看>>
SQL参数化查询的另一个理由——命中执行计划
查看>>
绕任意轴旋转
查看>>
iphone网络编程总结一
查看>>
window.open() target方法
查看>>