GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — deepfeatinterp/demo3.py at master · paulu/deepfeatinterp

Expand file tree

/

demo3.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
126 lines (115 loc) · 4.57 KB
/

demo3.py

Copy path

File metadata and controls

executable file
·
126 lines (115 loc) · 4.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python2
from __future__ import division
from __future__ import with_statement
from __future__ import print_function
import numpy
import os.path
import subprocess
import deepmodels
import json
import argparse
import time
import imageutils
import utils
def make_manifolds_knn(X,S,T,KNN,K):
'''
X is a string
S is a sequence of strings
T is a sequence of strings
KNN is a sequence of strings
K is a number
'''
S=set(S)
T=set(T)
P=[x for x in KNN if x!=X and x in S]
Q=[x for x in KNN if x!=X and x in T]
return P[:K],Q[:K]
if __name__=='__main__':
# configure by command-line arguments
parser=argparse.ArgumentParser(description='Generate inpainting transformations.',formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--backend',type=str,default='caffe+scipy',choices=['torch','caffe+scipy'],help='reconstruction implementation')
parser.add_argument('--device_id',type=int,default=0,help='zero-indexed CUDA device')
parser.add_argument('--K',type=int,default=100,help='number of nearest neighbors')
parser.add_argument('--scaling',type=str,default='beta',choices=['none','beta'],help='type of step scaling')
parser.add_argument('--iter',type=int,default=500,help='number of reconstruction iterations')
parser.add_argument('--postprocess',type=str,default='',help='comma-separated list of postprocessing operations')
parser.add_argument('--delta',type=str,default='2.8',help='comma-separated list of interpolation steps')
config=parser.parse_args()
postprocess=set(config.postprocess.split(','))
print(json.dumps(config.__dict__))
# load CUDA model
minimum_resolution=200
if config.backend=='torch':
import deepmodels_torch
model=deepmodels_torch.vgg19g_torch(device_id=config.device_id)
elif config.backend=='caffe+scipy':
model=deepmodels.vgg19g(device_id=config.device_id)
else:
raise ValueError('Unknown backend')
# download precomputed features (if needed)
if not os.path.exists('images/utzap/Shoes/Boat Shoes/ALDO/8045627.325.jpg'):
url='http://vision.cs.utexas.edu/projects/finegrained/utzap50k/ut-zap50k-images.zip'
subprocess.check_call(['wget',url,'-O','ut-zap50k-images.zip'])
subprocess.check_call(['unzip','ut-zap50k-images.zip','-d','images/utzap'])
subprocess.check_call(['rm','ut-zap50k-images.zip'])
if not os.path.exists('datasets/utzap/vggpool5.200x200.npz'):
url='https://www.dropbox.com/s/mms9jcznmavsxcr/utzap_knn.npz?dl=1'
subprocess.check_call(['wget',url,'-O','datasets/utzap/vggpool5.200x200.npz'])
# read test data
data=numpy.load('datasets/utzap/utzap_test_set.npz')
X=list(data['X']) # test groups
T=list(data['T']) # non-test groups
data=numpy.load('datasets/utzap/vggpool5.200x200.npz')
KNN_A=data['A'] # precomputed nearest neighbors for masked X \cup T
filelist=list(data['filelist'])
assert filelist==[x.replace('utzap','utzap_inpaint').replace('.jpg','.png') for x in X+T]
filelist=X+T
# comment out the line below to generate all the test images
X=X[:1]
# Set the free parameters
K=100
delta_params=[float(x.strip()) for x in config.delta.split(',')]
t0=time.time()
result=[]
original=[]
# for each test image
for i in range(len(X)):
result.append([])
xX=X[i]
o=imageutils.read(xX)
image_dims=(200,200)
o=imageutils.resize(o,image_dims)
utils.center_mask_inplace(o)
XF=model.mean_F([o])
original.append(o)
KNN=[filelist[j] for j in KNN_A[filelist.index(X[i])]]
P,Q=make_manifolds_knn(X[i],T,T,KNN,K)
xP=P
xQ=Q
PF=model.mean_F(utils.image_feed_masked(xP[:K],image_dims))
QF=model.mean_F(utils.image_feed(xQ[:K],image_dims))
if config.scaling=='beta':
WF=(QF-PF)/((QF-PF)**2).mean()
elif config.scaling=='none':
WF=(QF-PF)
max_iter=config.iter
init=o
# for each interpolation step
for delta in delta_params:
print(xX,delta)
t2=time.time()
Y=model.F_inverse(XF+WF*delta,max_iter=max_iter,initial_image=init)
t3=time.time()
print('{} minutes to reconstruct'.format((t3-t2)/60.0))
result[-1].append(Y)
max_iter=config.iter//2
init=Y
result=numpy.asarray(result)
original=numpy.asarray(original)
if 'color' in postprocess:
result=utils.color_match(numpy.expand_dims(original,1),result)
m=imageutils.montage(numpy.concatenate([numpy.expand_dims(original,1),result],axis=1).transpose(1,0,2,3,4))
imageutils.write('results/demo3.png',m)
print('Output is results/demo3.png')
t1=time.time()
print('{} minutes ({} minutes per image).'.format((t1-t0)/60.0,(t1-t0)/60.0/result.shape[0]/result.shape[1]))
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.