Skip to content

Instantly share code, notes, and snippets.

@ProGamerGov
Created March 29, 2018 19:46
Show Gist options
  • Save ProGamerGov/8fba74ed24062641bfa263954397c599 to your computer and use it in GitHub Desktop.
Save ProGamerGov/8fba74ed24062641bfa263954397c599 to your computer and use it in GitHub Desktop.
# Fixes from here: https://github.com/jcjohnson/pytorch-vgg/issues/3
from collections import OrderedDict
from torch.utils.model_zoo import load_url
import torch
sd = load_url("https://s3-us-west-2.amazonaws.com/jcjohns-models/vgg19-d01eb7cb.pth")
map = {'classifier.1.weight':u'classifier.0.weight', 'classifier.1.bias':u'classifier.0.bias', 'classifier.4.weight':u'classifier.3.weight', 'classifier.4.bias':u'classifier.3.bias'}
sd = OrderedDict([(map[k] if k in map else k,v) for k,v in sd.iteritems()])
torch.save(sd, "vgg19-d01eb7cb.pth")
sd = load_url("https://s3-us-west-2.amazonaws.com/jcjohns-models/vgg16-00b39a1b.pth")
map = {'classifier.1.weight':u'classifier.0.weight', 'classifier.1.bias':u'classifier.0.bias', 'classifier.4.weight':u'classifier.3.weight', 'classifier.4.bias':u'classifier.3.bias'}
sd = OrderedDict([(map[k] if k in map else k,v) for k,v in sd.iteritems()])
torch.save(sd, "vgg16-00b39a1b.pth")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment