Last active
March 31, 2020 17:03
-
-
Save zeryx/039bcfe6d4f60b9e0a4ccf309fd5c029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch as th | |
from torchvision import models, transforms | |
from PIL import Image | |
import numpy as np | |
resnet18 = models.resnet18(pretrained=True) | |
# This stage below removes the last module (aka the softmax layer) to provide raw data for fine-tuning/transfer learning | |
modules=list(resnet18.children())[:-1] | |
model = th.nn.Sequential(*modules) | |
th.save(model, "/tmp/resnet18-headless.th") | |
# Lets check to see if the model was serialized properly | |
reloaded = th.load("/tmp/resnet18-headless.th") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment