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

PS model #6

Closed
bhack opened this issue Jan 10, 2018 · 11 comments
Closed

PS model #6

bhack opened this issue Jan 10, 2018 · 11 comments

Comments

@bhack
Copy link

bhack commented Jan 10, 2018

Have you tried to convert it with https://github.com/clcarwin/convert_torch_to_pytorch?

@ducha-aiki
Copy link
Collaborator

@bhack

Traceback (most recent call last):
File "convert_torch.py", line 314, in
torch_to_pytorch(args.model,args.output)
File "convert_torch.py", line 259, in torch_to_pytorch
model = load_lua(t7_filename,unknown_classes=True)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 608, in load_lua
return reader.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 593, in read
return self.read_object()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 546, in read_object
return reader_registry[cls_name](self, version)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 243, in read_nn_class
attributes = reader.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 595, in read
return self.read_table()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 572, in read_table
v = self.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 595, in read
return self.read_table()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 572, in read_table
v = self.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 593, in read
return self.read_object()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 546, in read_object
return reader_registry[cls_name](self, version)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 243, in read_nn_class
attributes = reader.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 595, in read
return self.read_table()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 572, in read_table
v = self.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 595, in read
return self.read_table()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 572, in read_table
v = self.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 593, in read
return self.read_object()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 546, in read_object
return reader_registry[cls_name](self, version)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 318, in wrapper
obj = build_fn(reader, version)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 318, in wrapper
obj = build_fn(reader, version)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 243, in read_nn_class
attributes = reader.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 595, in read
return self.read_table()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 572, in read_table
v = self.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 593, in read
return self.read_object()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 546, in read_object
return reader_registry[cls_name](self, version)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 147, in read_tensor
storage = reader.read()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 593, in read
return self.read_object()
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 523, in wrapper
result = fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 546, in read_object
return reader_registry[cls_name](self, version)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/serialization/read_lua_file.py", line 166, in read_storage
return python_class.from_buffer(reader.f.read(size), 'native')
AttributeError: type object 'torch.cuda.FloatStorage' has no attribute 'from_buffer'

@bhack
Copy link
Author

bhack commented Jan 10, 2018

Probably is this clcarwin/convert_torch_to_pytorch#8

@ducha-aiki
Copy link
Collaborator

I don`t want to install lua now :( I had it on previous Ubuntu and remember some clashed after installation lua and torch... May be @rmitra can help?

@bhack
Copy link
Author

bhack commented Jan 11, 2018

I think that nvidia-docker run -it kaixhin/cuda-torch is enough to have a torch env without messing the host OS. But probably @rmitra could help in the conversion.

@ducha-aiki
Copy link
Collaborator

neither have a docker. I am medieval person, I know :(

@rmitra
Copy link

rmitra commented Jan 11, 2018

Hi, the link for downloading the network for PyTorch is https://www.dropbox.com/s/1p9e8vtf57gl9jc/PyTorch-hardnet-PS-CPU.pth?dl=1

Please inform me of further issues in https://github.com/rmitra/PS-Dataset.

Thanks,

@ducha-aiki
Copy link
Collaborator

ducha-aiki commented Jan 12, 2018

@bhack @rmitra
I have converted it manually. It has a bit changes in structure, than HardNet: lacking last BN layer. Also, BN layers in HardNetPS are WITH learned scale and bias, while in plain HardNet, they are without (affine = False) The structure of HardNetPS is like this:

class HardNetPS(nn.Module):
    def __init__(self):
        super(HardNetPS, self).__init__()
        self.features = nn.Sequential(
        nn.Conv2d(1, 32, kernel_size=3, padding=1, bias = True),
        nn.BatchNorm2d(32, affine=True),
        nn.ReLU(),
        nn.Conv2d(32, 32, kernel_size=3, padding=1, bias = True),
        nn.BatchNorm2d(32, affine=True),
        nn.ReLU(),
        nn.Conv2d(32, 64, kernel_size=3, stride=2, padding=1, bias = True),
        nn.BatchNorm2d(64, affine=True),
        nn.ReLU(),
        nn.Conv2d(64, 64, kernel_size=3, padding=1, bias = True),
        nn.BatchNorm2d(64, affine=True),
        nn.ReLU(),
        nn.Conv2d(64, 128, kernel_size=3, stride=2,padding=1, bias = True),
        nn.BatchNorm2d(128, affine=True),
        nn.ReLU(),
        nn.Conv2d(128, 128, kernel_size=3, padding=1, bias = True),
        nn.BatchNorm2d(128, affine=True),
        nn.ReLU(),
        nn.Conv2d(128, 128, kernel_size=8, bias = True)
    )

def input_norm(self,x):
    flat = x.view(x.size(0), -1)
    mp = torch.mean(flat, dim=1)
    sp = torch.std(flat, dim=1) + 1e-7
    return (x - mp.unsqueeze(-1).unsqueeze(-1).unsqueeze(-1).expand_as(x)) / sp.unsqueeze(-1).unsqueeze(-1).unsqueeze(1).expand_as(x)

def forward(self, input):
    x_features = self.features(self.input_norm(input))
    x = x_features.view(x_features.size(0), -1)
    return L2Norm()(x)`

And the converted to true PyTorch weights are here:
http://cmp.felk.cvut.cz/~mishkdmy/HardNet-PS.pth

Converted weights + code above give following performance on HPatches matching task:
HardNet-PS
Easy Hard Tough mean


0.691107 0.593172 0.460405 0.581561

vs HardNetLib+
Easy Hard Tough mean


0.696852 0.533411 0.35355 0.527938

@ducha-aiki
Copy link
Collaborator

I will update README.md in couple of hours with benchmark results

@ducha-aiki
Copy link
Collaborator

I have also asked @rmitra to compare HardNet++ (trained on Brown + HPatches) vs HardNet-PS on Fountain dataset. I think, they should be pretty close in performance

@ducha-aiki
Copy link
Collaborator

Readme updated, results of HardNet-PS are in :)

@rmitra
Copy link

rmitra commented Jan 13, 2018

@ducha-aiki Thank you so much for updating the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants