Giter Club home page Giter Club logo

Comments (8)

martin-danelljan avatar martin-danelljan commented on September 7, 2024

Hi. If I remember correctly (was a while ago) I used this model and then I made a script that re-normalizes the weights to fit the torchvision resnet input, and reorders the weights from BGR to RGB. I could probably find the script if you would have any use for it.

I ended up comparing the network with the output from MatConvNet VGG-m, and they were very similar.

from pytracking.

happyflyhot avatar happyflyhot commented on September 7, 2024

Thanks a lot~
The script would be useful for me. I really appreciate your help~

from pytracking.

happyflyhot avatar happyflyhot commented on September 7, 2024

@martin-danelljan Hi, may you share that transform script with me? I failed to re-normalizes the weights myself...

from pytracking.

martin-danelljan avatar martin-danelljan commented on September 7, 2024

Hey. Sorry for the delay. Here is the code that I used. You need to have this repo in your python path.

import os
import sys
import torch
import torchvision
import pretrainedmodels

env_path = os.path.join(os.path.dirname(__file__), '..')
if env_path not in sys.path:
    sys.path.append(env_path)


def main():
    resnet18 = torchvision.models.__dict__['resnet18'](pretrained=True)
    vggm = pretrainedmodels.models.vggm()

    resnet18.vggmconv1 = vggm.features[0]

    # Convert to RGB
    weight = resnet18.vggmconv1.weight.clone()
    resnet18.vggmconv1.weight[:,0,:,:] = weight[:,2,:,:]
    resnet18.vggmconv1.weight[:,2,:,:] = weight[:,0,:,:]

    # Normalize
    vgg_mean = torch.Tensor(vggm.mean[::-1])
    torch_std = torch.Tensor([0.229, 0.224, 0.225]).view(1,-1,1,1)
    resnet18.vggmconv1.weight[...] = resnet18.vggmconv1.weight * (torch_std*255)


    torch.save(resnet18.state_dict(), '../features/pretrained/resnet18_vggmconv1.pth')


if __name__ == '__main__':
    main()

from pytracking.

noobgrow avatar noobgrow commented on September 7, 2024

the model vggm is no longer aviable,could please send me one?
'vggm': {
'imagenet':
'url': 'http://data.lip6.fr/cadene/pretrainedmodels/vggm-786f2434.pth',

from pytracking.

noobgrow avatar noobgrow commented on September 7, 2024

should be
https://data.lip6.fr/cadene/pretrainedmodels/vggm-786f2434.pth

from pytracking.

noobgrow avatar noobgrow commented on September 7, 2024
    model = VGGM(num_classes=1000)
    checkpoint = torch.load('vggm-786f2434.pth')
    for key in list(checkpoint.keys()):
        if 'classifier.' in key:
            checkpoint[key.replace('classifier.', 'classif.')] = checkpoint[key]
            del checkpoint[key]
    model.load_state_dict(checkpoint)

from pytracking.

noobgrow avatar noobgrow commented on September 7, 2024
    model = VGGM(num_classes=1000)
    checkpoint = torch.load('vggm-786f2434.pth')
    for key in list(checkpoint.keys()):
        if 'classifier.' in key:
            checkpoint[key.replace('classifier.', 'classif.')] = checkpoint[key]
            del checkpoint[key]
    model.load_state_dict(checkpoint)

from pytracking.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.