Skip to content

Instantly share code, notes, and snippets.

@kayhide
Created February 13, 2017 12:08
Show Gist options
  • Save kayhide/19a172a9513a9ffd4e6aa2624ea815d4 to your computer and use it in GitHub Desktop.
Save kayhide/19a172a9513a9ffd4e6aa2624ea815d4 to your computer and use it in GitHub Desktop.
Dump yaml from python pickle file
import pickle
import numpy
import yaml
network_file = 'sample_weight.pkl'
print("read: %(network_file)s" % locals())
with open(network_file, 'rb') as f:
network = pickle.load(f)
for key in network.keys():
dst = "%(key)s.yml" % locals()
print("write: %(dst)s" % locals())
with open(dst, 'w') as f:
f.write(yaml.dump(network[key].tolist()))
@kayhide
Copy link
Author

kayhide commented Feb 13, 2017

このファイルを他の言語でも扱えるように yaml に変換するスクリプト。

python3 系が必要。

使い方

データファイルをダウンロードする。

$ wget "https://github.com/oreilly-japan/deep-learning-from-scratch/blob/master/ch03/sample_weight.pkl?raw=true" -O sample_weight.pkl

スクリプトを実行する。

$ python --version
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)

$ python dump_sample_weight.py
read: sample_weight.pkl
write: W3.yml
write: b3.yml
write: b1.yml
write: b2.yml
write: W1.yml
write: W2.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment