How can I use legacy torch module?

Because I need to employ nn.Replicate from torch, I tried the below

import torch
import torch.nn.functional as F
from torch.legacy import nn as nn
from torch.autograd import Variable

input = Variable(torch.rand(32,128,1,1))
replicate = nn.Replicate(nf = 32, dim = 3)
output = replicate(input)

But, I got the error message TypeError: ‘Replicate’ object is not callable

Can you tell me how I can use nn.Replicate ?

1 Like

torch.expand can do the same thing, however the arguments are a little different from nn.Replicate.

Thanks for your reply.

You can’t mix legacy.nn with autograd or new nn. It’s only for loading legacy models.