Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/taming download path #226

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions taming/modules/losses/lpips.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Stripped version of https://github.com/richzhang/PerceptualSimilarity/tree/master/models"""
import os

import torch
import torch.nn as nn
Expand All @@ -10,8 +11,9 @@

class LPIPS(nn.Module):
# Learned perceptual metric
def __init__(self, use_dropout=True):
def __init__(self, use_dropout=True, download_directory: str = "/tmp/"):
super().__init__()
self.download_directory = download_directory
self.scaling_layer = ScalingLayer()
self.chns = [64, 128, 256, 512, 512] # vg16 features
self.net = vgg16(pretrained=True, requires_grad=False)
Expand All @@ -25,7 +27,9 @@ def __init__(self, use_dropout=True):
param.requires_grad = False

def load_from_pretrained(self, name="vgg_lpips"):
ckpt = get_ckpt_path(name, "taming/modules/autoencoder/lpips")
root = os.path.join(self.download_directory, "taming/modules/autoencoder/lpips")
os.makedirs(root, exist_ok=True)
ckpt = get_ckpt_path(name, root)
self.load_state_dict(torch.load(ckpt, map_location=torch.device("cpu")), strict=False)
print("loaded pretrained LPIPS loss from {}".format(ckpt))

Expand Down