Access parameter names in torch

3.5k views Asked by At

I need to convert a torch model to pytorch. Since the torch model has layers that pytorch doesn't support(such as inception and LRN), it is not possible to use the build-in APIs. In order to convert such models from torch to pytorch, it is necessary to implement such layers in pytorch and save all the parameters from torch model as hdf5 file, and reload them to python as a dictionary. I'm new to lua and I would like to ask how to access the 'nickname' of all the parameters in torch.

btw, this can be easily done in pytorch, for example:

import torch.nn as nn
model = nn.Sequential(
                nn.Conv2d(in_channels=3,out_channels=32,kernel_size=7,stride=1,bias=False),
                nn.ReLU(inplace=True),
                nn.BatchNorm2d(num_features=32,affine=True),
                nn.MaxPool2d(kernel_size=2,stride=2)
                )
for key in model.state_dict():
    value = model.state_dict().get(key)
    print(key, value.size())

if all the parameters are accessible in a dictionary format, reconstructing a model in pytorch can be done in the following code:

model = MyNewInceptionModel()
model.load_state_dict(param_dict)
0

There are 0 answers