Lua version Deep Learning from scratch 1 [Implémentation de Perceptron] Lua version Deep Learning from scratch 2 [Fonction d'activation] Lua version Deep Learning from scratch Part 3 [Implémentation d'un réseau neuronal à 3 couches] [Version Lua Deep Learning from scratch 4 [Implémentation de la fonction softmax]] (http://qiita.com/Kazuki-Nakamae/items/20e53a02a8b759583d31) Lua version Deep Learning from scratch Part 5 [Afficher l'image MNIST]
Vous pouvez le faire avec le script suivant.
pkl2npz.py
#!/usr/local/bin/python3
# coding: utf-8
"""
Exportez le contenu du fichier pkl dans le fichier npz.
"""
__author__ = "Kazuki Nakamae <[email protected]>"
__version__ = "0.00"
__date__ = "22 Jun 2017"
import sys
import numpy as np
import pickle
def pkl2npz(infn, outfn):
    """
    @function   pkl2npz();
Exportez le contenu du fichier pkl dans le fichier npz.
    @param  {string} infn :Nom du fichier d'entrée
    @param  {string} outfn :Nom du fichier de sortie
    """
    with open(infn, 'rb') as f:
            ndarr = pickle.load(f)
            np.savez(outfn, W1=ndarr['W1'],W2=ndarr['W2'],W3=ndarr['W3'],b1=ndarr['b1'],b2=ndarr['b2'],b3=ndarr['b3'])
if __name__ == '__main__':
    argvs = sys.argv
    argc = len(argvs)
    if (argc != 3):   # Checking input
        print("USAGE : python3 pkl2npz.py <INPUT_PKLFILE> <OUTPUT_NPZFILE>")
        quit()
    pkl2npz(str(argvs[1]),str(argvs[2]))
quit()
pkl2npz.Exécuter py
$ python3 pkl2npz.py sample_weight.pkl sample_weight.npz
Maintenant, chargeons le sample_weight.npz créé sur Lua. Sans tracas. Les personnes suivantes ont créé un package (npy4th) à cet effet. htwaijry/npy4th
npy4th installation
$ git clone https://github.com/htwaijry/npy4th.git
$ cd npy4th
$ luarocks make
Il est facile à utiliser et peut être lu en insérant simplement loadnpz ([nom de fichier]).
loadnpz()Comment utiliser
npy4th = require 'npy4th'
-- read a .npz file into a table
tbl = npy4th.loadnpz('sample_weight.npz')
print(tbl["W1"])
Résultat de sortie
Columns 1 to 6
-7.4125e-03 -7.9044e-03 -1.3075e-02  1.8526e-02 -1.5346e-03 -8.7649e-03
-1.0297e-02 -1.6167e-02 -1.2284e-02 -1.7926e-02  3.3988e-03 -7.0708e-02
-1.3092e-02 -2.4475e-03 -1.7722e-02 -2.4240e-02 -2.2041e-02 -5.0149e-03
-1.0008e-02  1.9586e-02 -5.6170e-03  3.8307e-02 -5.2507e-02 -2.3568e-02
(Omis)
 1.1210e-02  1.0272e-02
-1.2299e-02  2.4070e-02
 7.4309e-03 -4.0211e-02
[torch.FloatTensor of size 784x50]
Torch n'est pas populaire au Japon, mais je pense que ce serait plus facile à utiliser si de nombreuses ressources pouvaient être utilisées de cette manière. c'est tout. Merci beaucoup.