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):
        vrn.zero_grad()
        #vrn.cleargrads()
        image, label = load_sample(
            train_df,
            args.n_batch,
            args.input_shape,
            args.output_shape
        )
        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)

Hi,

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?

Hi,
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?