Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
net_type = pn.alexnet
self.chns = [64,192,384,256,256]
elif(self.pnet_type=='squeeze'):
net_type = pn.squeezenet
self.chns = [64,128,256,384,384,512,512]
if(self.pnet_tune):
self.net = net_type(requires_grad=True)
else:
self.net = [net_type(requires_grad=False),]
self.lin0 = NetLinLayer(self.chns[0],use_dropout=use_dropout)
self.lin1 = NetLinLayer(self.chns[1],use_dropout=use_dropout)
self.lin2 = NetLinLayer(self.chns[2],use_dropout=use_dropout)
self.lin3 = NetLinLayer(self.chns[3],use_dropout=use_dropout)
self.lin4 = NetLinLayer(self.chns[4],use_dropout=use_dropout)
self.lins = [self.lin0,self.lin1,self.lin2,self.lin3,self.lin4]
if(self.pnet_type=='squeeze'): # 7 layers for squeezenet
self.lin5 = NetLinLayer(self.chns[5],use_dropout=use_dropout)
self.lin6 = NetLinLayer(self.chns[6],use_dropout=use_dropout)
self.lins+=[self.lin5,self.lin6]
self.shift = torch.autograd.Variable(torch.Tensor([-.030, -.088, -.188]).view(1,3,1,1))
self.scale = torch.autograd.Variable(torch.Tensor([.458, .448, .450]).view(1,3,1,1))
if(use_gpu):
if(self.pnet_tune):
self.net.cuda()
else:
self.net[0].cuda()
self.shift = self.shift.cuda()
self.scale = self.scale.cuda()
if(self.pnet_type in ['vgg','vgg16']):
net_type = pn.vgg16
self.chns = [64,128,256,512,512]
elif(self.pnet_type=='alex'):
net_type = pn.alexnet
self.chns = [64,192,384,256,256]
elif(self.pnet_type=='squeeze'):
net_type = pn.squeezenet
self.chns = [64,128,256,384,384,512,512]
if(self.pnet_tune):
self.net = net_type(requires_grad=True)
else:
self.net = [net_type(requires_grad=False),]
self.lin0 = NetLinLayer(self.chns[0],use_dropout=use_dropout)
self.lin1 = NetLinLayer(self.chns[1],use_dropout=use_dropout)
self.lin2 = NetLinLayer(self.chns[2],use_dropout=use_dropout)
self.lin3 = NetLinLayer(self.chns[3],use_dropout=use_dropout)
self.lin4 = NetLinLayer(self.chns[4],use_dropout=use_dropout)
self.lins = [self.lin0,self.lin1,self.lin2,self.lin3,self.lin4]
if(self.pnet_type=='squeeze'): # 7 layers for squeezenet
self.lin5 = NetLinLayer(self.chns[5],use_dropout=use_dropout)
self.lin6 = NetLinLayer(self.chns[6],use_dropout=use_dropout)
self.lins+=[self.lin5,self.lin6]
self.shift = torch.autograd.Variable(torch.Tensor([-.030, -.088, -.188]).view(1,3,1,1))
self.scale = torch.autograd.Variable(torch.Tensor([.458, .448, .450]).view(1,3,1,1))
if(use_gpu):
if(self.pnet_tune):
self.net.cuda()
self.chns = [64,128,256,384,384,512,512]
if(self.pnet_tune):
self.net = net_type(requires_grad=True)
else:
self.net = [net_type(requires_grad=False),]
self.lin0 = NetLinLayer(self.chns[0],use_dropout=use_dropout)
self.lin1 = NetLinLayer(self.chns[1],use_dropout=use_dropout)
self.lin2 = NetLinLayer(self.chns[2],use_dropout=use_dropout)
self.lin3 = NetLinLayer(self.chns[3],use_dropout=use_dropout)
self.lin4 = NetLinLayer(self.chns[4],use_dropout=use_dropout)
self.lins = [self.lin0,self.lin1,self.lin2,self.lin3,self.lin4]
if(self.pnet_type=='squeeze'): # 7 layers for squeezenet
self.lin5 = NetLinLayer(self.chns[5],use_dropout=use_dropout)
self.lin6 = NetLinLayer(self.chns[6],use_dropout=use_dropout)
self.lins+=[self.lin5,self.lin6]
self.shift = torch.autograd.Variable(torch.Tensor([-.030, -.088, -.188]).view(1,3,1,1))
self.scale = torch.autograd.Variable(torch.Tensor([.458, .448, .450]).view(1,3,1,1))
if(use_gpu):
if(self.pnet_tune):
self.net.cuda()
else:
self.net[0].cuda()
self.shift = self.shift.cuda()
self.scale = self.scale.cuda()
self.lin0.cuda()
self.lin1.cuda()
self.lin2.cuda()
self.lin3.cuda()
self.chns = [64,128,256,512,512]
elif(self.pnet_type=='alex'):
net_type = pn.alexnet
self.chns = [64,192,384,256,256]
elif(self.pnet_type=='squeeze'):
net_type = pn.squeezenet
self.chns = [64,128,256,384,384,512,512]
if(self.pnet_tune):
self.net = net_type(requires_grad=True)
else:
self.net = [net_type(requires_grad=False),]
self.lin0 = NetLinLayer(self.chns[0],use_dropout=use_dropout)
self.lin1 = NetLinLayer(self.chns[1],use_dropout=use_dropout)
self.lin2 = NetLinLayer(self.chns[2],use_dropout=use_dropout)
self.lin3 = NetLinLayer(self.chns[3],use_dropout=use_dropout)
self.lin4 = NetLinLayer(self.chns[4],use_dropout=use_dropout)
self.lins = [self.lin0,self.lin1,self.lin2,self.lin3,self.lin4]
if(self.pnet_type=='squeeze'): # 7 layers for squeezenet
self.lin5 = NetLinLayer(self.chns[5],use_dropout=use_dropout)
self.lin6 = NetLinLayer(self.chns[6],use_dropout=use_dropout)
self.lins+=[self.lin5,self.lin6]
self.shift = torch.autograd.Variable(torch.Tensor([-.030, -.088, -.188]).view(1,3,1,1))
self.scale = torch.autograd.Variable(torch.Tensor([.458, .448, .450]).view(1,3,1,1))
if(use_gpu):
if(self.pnet_tune):
self.net.cuda()
else:
self.net[0].cuda()
net_type = pn.vgg16
self.chns = [64,128,256,512,512]
elif(self.pnet_type=='alex'):
net_type = pn.alexnet
self.chns = [64,192,384,256,256]
elif(self.pnet_type=='squeeze'):
net_type = pn.squeezenet
self.chns = [64,128,256,384,384,512,512]
if(self.pnet_tune):
self.net = net_type(requires_grad=True)
else:
self.net = [net_type(requires_grad=False),]
self.lin0 = NetLinLayer(self.chns[0],use_dropout=use_dropout)
self.lin1 = NetLinLayer(self.chns[1],use_dropout=use_dropout)
self.lin2 = NetLinLayer(self.chns[2],use_dropout=use_dropout)
self.lin3 = NetLinLayer(self.chns[3],use_dropout=use_dropout)
self.lin4 = NetLinLayer(self.chns[4],use_dropout=use_dropout)
self.lins = [self.lin0,self.lin1,self.lin2,self.lin3,self.lin4]
if(self.pnet_type=='squeeze'): # 7 layers for squeezenet
self.lin5 = NetLinLayer(self.chns[5],use_dropout=use_dropout)
self.lin6 = NetLinLayer(self.chns[6],use_dropout=use_dropout)
self.lins+=[self.lin5,self.lin6]
self.shift = torch.autograd.Variable(torch.Tensor([-.030, -.088, -.188]).view(1,3,1,1))
self.scale = torch.autograd.Variable(torch.Tensor([.458, .448, .450]).view(1,3,1,1))
if(use_gpu):
if(self.pnet_tune):
self.net.cuda()
else:
def __init__(self, chn_in, chn_out=1, use_dropout=False):
super(NetLinLayer, self).__init__()
layers = [nn.Dropout(),] if(use_dropout) else []
layers += [nn.Conv2d(chn_in, chn_out, 1, stride=1, padding=0, bias=False),]
self.model = nn.Sequential(*layers)
net_type = pn.squeezenet
self.chns = [64,128,256,384,384,512,512]
if(self.pnet_tune):
self.net = net_type(requires_grad=True)
else:
self.net = [net_type(requires_grad=False),]
self.lin0 = NetLinLayer(self.chns[0],use_dropout=use_dropout)
self.lin1 = NetLinLayer(self.chns[1],use_dropout=use_dropout)
self.lin2 = NetLinLayer(self.chns[2],use_dropout=use_dropout)
self.lin3 = NetLinLayer(self.chns[3],use_dropout=use_dropout)
self.lin4 = NetLinLayer(self.chns[4],use_dropout=use_dropout)
self.lins = [self.lin0,self.lin1,self.lin2,self.lin3,self.lin4]
if(self.pnet_type=='squeeze'): # 7 layers for squeezenet
self.lin5 = NetLinLayer(self.chns[5],use_dropout=use_dropout)
self.lin6 = NetLinLayer(self.chns[6],use_dropout=use_dropout)
self.lins+=[self.lin5,self.lin6]
self.shift = torch.autograd.Variable(torch.Tensor([-.030, -.088, -.188]).view(1,3,1,1))
self.scale = torch.autograd.Variable(torch.Tensor([.458, .448, .450]).view(1,3,1,1))
if(use_gpu):
if(self.pnet_tune):
self.net.cuda()
else:
self.net[0].cuda()
self.shift = self.shift.cuda()
self.scale = self.scale.cuda()
self.lin0.cuda()
self.lin1.cuda()
self.lin2.cuda()
elif(self.pnet_type=='alex'):
net_type = pn.alexnet
self.chns = [64,192,384,256,256]
elif(self.pnet_type=='squeeze'):
net_type = pn.squeezenet
self.chns = [64,128,256,384,384,512,512]
if(self.pnet_tune):
self.net = net_type(requires_grad=True)
else:
self.net = [net_type(requires_grad=False),]
self.lin0 = NetLinLayer(self.chns[0],use_dropout=use_dropout)
self.lin1 = NetLinLayer(self.chns[1],use_dropout=use_dropout)
self.lin2 = NetLinLayer(self.chns[2],use_dropout=use_dropout)
self.lin3 = NetLinLayer(self.chns[3],use_dropout=use_dropout)
self.lin4 = NetLinLayer(self.chns[4],use_dropout=use_dropout)
self.lins = [self.lin0,self.lin1,self.lin2,self.lin3,self.lin4]
if(self.pnet_type=='squeeze'): # 7 layers for squeezenet
self.lin5 = NetLinLayer(self.chns[5],use_dropout=use_dropout)
self.lin6 = NetLinLayer(self.chns[6],use_dropout=use_dropout)
self.lins+=[self.lin5,self.lin6]
self.shift = torch.autograd.Variable(torch.Tensor([-.030, -.088, -.188]).view(1,3,1,1))
self.scale = torch.autograd.Variable(torch.Tensor([.458, .448, .450]).view(1,3,1,1))
if(use_gpu):
if(self.pnet_tune):
self.net.cuda()
else:
self.net[0].cuda()
self.shift = self.shift.cuda()
def forward(self, in0, in1):
assert(in0.size()[0]==1) # currently only supports batchSize 1
if(self.colorspace=='RGB'):
value = util.dssim(1.*util.tensor2im(in0.data), 1.*util.tensor2im(in1.data), range=255.).astype('float')
elif(self.colorspace=='Lab'):
value = util.dssim(util.tensor2np(util.tensor2tensorlab(in0.data,to_norm=False)),
util.tensor2np(util.tensor2tensorlab(in1.data,to_norm=False)), range=100.).astype('float')
ret_var = Variable( torch.Tensor((value,) ) )
if(self.use_gpu):
ret_var = ret_var.cuda()
return ret_var
def forward(self, in0, in1):
assert(in0.size()[0]==1) # currently only supports batchSize 1
if(self.colorspace=='RGB'):
value = util.dssim(1.*util.tensor2im(in0.data), 1.*util.tensor2im(in1.data), range=255.).astype('float')
elif(self.colorspace=='Lab'):
value = util.dssim(util.tensor2np(util.tensor2tensorlab(in0.data,to_norm=False)),
util.tensor2np(util.tensor2tensorlab(in1.data,to_norm=False)), range=100.).astype('float')
ret_var = Variable( torch.Tensor((value,) ) )
if(self.use_gpu):
ret_var = ret_var.cuda()
return ret_var