Skip to content

Instantly share code, notes, and snippets.

@ottonemo
Last active February 26, 2019 12:05
Show Gist options
  • Save ottonemo/9736e5a21ae4db3f58a341c72897320a to your computer and use it in GitHub Desktop.
Save ottonemo/9736e5a21ae4db3f58a341c72897320a to your computer and use it in GitHub Desktop.
#!/bin/sh
git checkout v0.5.0
python <<EOF
import pickle
import skorch
import skorch.toy
model = skorch.toy.make_classifier()
model = skorch.NeuralNetClassifier(model)
model.initialize()
with open('model.pkl', 'wb') as f:
pickle.dump(model, f)
EOF
git checkout master
# Fix issue (2) so loading works
git apply - <<EOF
diff --git a/skorch/net.py b/skorch/net.py
index fdbdf01..ea87905 100644
--- a/skorch/net.py
+++ b/skorch/net.py
@@ -1419,9 +1419,6 @@ class NeuralNet:
f.write(state['cuda_dependent_attributes_'])
f.seek(0)
cuda_attrs = torch.load(f, **load_kwargs)
- for key in self.cuda_dependent_attributes_:
- if key in cuda_attrs:
- del state[key]
state.update(cuda_attrs)
self.__dict__.update(state)
EOF
python <<EOF
import pickle
with open('model.pkl', 'rb') as f:
m = pickle.load(f)
with open('model2.pkl', 'wb') as f:
pickle.dump(m, f)
EOF
#!/bin/sh
git checkout v0.5.0
python <<EOF
import pickle
import skorch
import skorch.toy
model = skorch.toy.make_classifier()
model = skorch.NeuralNetClassifier(model)
model.initialize()
with open('model.pkl', 'wb') as f:
pickle.dump(model, f)
EOF
git checkout master
python <<EOF
import pickle
with open('model.pkl', 'rb') as f:
m = pickle.load(f)
print(m)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment