From chainer to pytorch

how can i change these two instructions in pytorch ?
these instructions used in chainer code
(knowing that vrn is a resnet+unet model )

x_train = vrn.xp.asarray(image)
y_train = vrn.xp.asarray(label)
for i in range(args.iteration):
        image, label = load_sample(
        x_train = vrn.xp.asarray(image)
        y_train = vrn.xp.asarray(label)
        logits = vrn(x_train, train=True)
        logits = [logit[slices_in] for logit in logits]
        loss = F.softmax_cross_entropy(logits[-1], y_train)


Do you always load the same batch during training? Why does load_sample is not a function of i? You might want to check pytorch’s Dataset and Dataloader.

To replace vrn.xp.asarray, it depends what image and label are. And what this function was doing originally?

image and label are 3d data of niftii type

I guess the simplest would to do x_train = torch.from_numpy(vrn.xp.asarray(image)).
But you could consider reimplementing this function directly using pytorch.

thank you i’ll try it

i got the same problem even i tried x_train = torch.from_numpy(vrn.xp.asarray(image))

What is the error you’re seeing?
Can you share the full stack trace?