Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions DISTS_pytorch/DISTS_pt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This is a pytoch implementation of DISTS metric.
# Requirements: python >= 3.6, pytorch >= 1.0

import importlib.resources
import numpy as np
import os,sys
import torch
Expand All @@ -27,7 +28,10 @@ def forward(self, input):
class DISTS(torch.nn.Module):
def __init__(self, load_weights=True):
super(DISTS, self).__init__()
vgg_pretrained_features = models.vgg16(pretrained=True).features
vgg_pretrained_features = models.vgg16(pretrained=False).features
vgg_ref = importlib.resources.files('DISTS_pytorch').joinpath('vgg16_features.pt')
with importlib.resources.as_file(vgg_ref) as vgg_weights_path:
vgg_pretrained_features.load_state_dict(torch.load(vgg_weights_path, weights_only=True))
self.stage1 = torch.nn.Sequential()
self.stage2 = torch.nn.Sequential()
self.stage3 = torch.nn.Sequential()
Expand Down Expand Up @@ -60,7 +64,9 @@ def __init__(self, load_weights=True):
self.alpha.data.normal_(0.1,0.01)
self.beta.data.normal_(0.1,0.01)
if load_weights:
weights = torch.load(os.path.join(sys.prefix,'weights.pt'))
w_ref = importlib.resources.files('DISTS_pytorch').joinpath('weights.pt')
with importlib.resources.as_file(w_ref) as weights_path:
weights = torch.load(weights_path, weights_only=True)
self.alpha.data = weights['alpha']
self.beta.data = weights['beta']

Expand Down
Binary file added DISTS_pytorch/vgg16_features.pt
Binary file not shown.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-- __init__.py
-- DISTS_pt.py
-- weights.pt
-- vgg16_features.pt
-- README.md
-- requirements.txt
-- LICENSE
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
long_description=long_description,
long_description_content_type="text/markdown",
packages=['DISTS_pytorch'],
package_data= {'': ['DISTS_pytorch/weights.pt']},
data_files= [('', ['DISTS_pytorch/weights.pt'])],
package_data= {'': ['DISTS_pytorch/weights.pt', 'DISTS_pytorch/vgg16_features.pt']},
data_files= [('', ['DISTS_pytorch/weights.pt', 'DISTS_pytorch/vgg16_features.pt'])],
include_package_data=True,
author='Keyan Ding',
author_email='dingkeyan93@outlook.com',
Expand Down