save and load nueral network parameters when using python lasagne

    xiaoxiao2021-03-25  130

    import cPickle as pickle sys.setrecursionlimit(10000) # you may need this if the network is large with open("model_file", 'wb') as f: pickle.dump(nolearnnet , f, -1)

    但是,如果据说在GPU上训练的神经网络要用读取出来用CPU做计算,以上方法不行。而应该使用更暴力的方法:

    weights = lasagne.layers.get_all_param_values(nolearnnet.get_all_layers()[-1])

    这样就可以用numpy.savez()存储和读取这些值了。当你需要把他们赋给一个网络时,可以采用:

    lasagne.layers.set_all_param_values(nolearnnet2.get_all_layers()[-1], weights)
    转载请注明原文地址: https://ju.6miu.com/read-9335.html

    最新回复(0)