# Issues using the Slicer 4.11 kernel with Pytorch

**URL:** <https://discourse.slicer.org/t/issues-using-the-slicer-4-11-kernel-with-pytorch/22308>\
**Category:** Support\
**Created:** [March 4, 2022, 12:42pm UTC](https://discourse.slicer.org/t/issues-using-the-slicer-4-11-kernel-with-pytorch/22308 "2022-03-04T12:42:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dariodo.fal](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@dariodo.fal](https://discourse.slicer.org/u/dariodo.fal)\
**Post date:** [March 4, 2022, 12:42pm UTC](https://discourse.slicer.org/t/issues-using-the-slicer-4-11-kernel-with-pytorch/22308/1 "2022-03-04T12:42:04Z")

</div>

Hello, I am trying to do the Transfer Learning tutorial that the Pytorch website offers using the Slicer 4.11 kernel with the TorchIO extension but I am finding a problem I don’t understand. The code looks like this so far

```auto
from __future__ import print_function, division

import torch
import torch.nn as nn
import torch.optim as optim
from torch.optim import lr_scheduler
import torch.backends.cudnn as cudnn
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import os
import copy

cudnn.benchmark = True
plt.ion() # interactive mode

import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'

data_transforms = {
    'train': transforms.Compose([
        transforms.RandomResizedCrop(299),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ]),
    'val': transforms.Compose([
        transforms.Resize(299),
        transforms.CenterCrop(299),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ]),
}

data_dir = r"c:\Users\dario\Letters"
image_datasets = {x: datasets.ImageFolder(os.path.join(data_dir, x),
                                          data_transforms[x])
                  for x in ['train', 'val']}
dataloaders = {x: torch.utils.data.DataLoader(image_datasets[x], batch_size=4,
                                             shuffle=True, num_workers=4)
              for x in ['train', 'val']}
dataset_sizes = {x: len(image_datasets[x]) for x in ['train', 'val']}
class_names = image_datasets['train'].classes

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

print(class_names)

def imshow(inp, title=None):
    """Imshow for Tensor."""
    inp = inp.numpy().transpose((1, 2, 0))
    mean = np.array([0.485, 0.456, 0.406])
    std = np.array([0.229, 0.224, 0.225])
    inp = std * inp + mean
    inp = np.clip(inp, 0, 1)
    plt.imshow(inp)
    if title is not None:
        plt.title(title)
    plt.pause(0.001) # pause a bit so that plots are updated

# Get a batch of training data
inputs, classes = next(iter(dataloaders['train']))
# Make a grid from batch
out = torchvision.utils.make_grid(inputs)
imshow(out, title=[class_names[x] for x in classes]) 

```

As you can see, I am using the InceptionV3 model with 5 possible classes because that’s what I am required to work with. The problem comes when it gets to the following line:

```auto
inputs, classes = next(iter(dataloaders['train'])) 

```

When it gets here, this window shows up on my screen

 ![slicerproblem](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/e/0e8f79ccefb3caa9b64ac7aba2a1d0401c18e222.png)  
I don’t know what I am supposed to put in here or if this is supposed to be happening as I haven’t worked with Slicer ever before. Does anyone know how I can solve it?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 4, 2022, 2:24pm UTC](https://discourse.slicer.org/t/issues-using-the-slicer-4-11-kernel-with-pytorch/22308/2 "2022-03-04T14:24:20Z")

</div>

Can you add a link to the tutorial you are trying to follow? Is it supposed to work in Slicer?

---

<div class="post-metadata">

**Author:** ![dariodo.fal](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@dariodo.fal](https://discourse.slicer.org/u/dariodo.fal)\
**Post date:** [March 6, 2022, 5:12pm UTC](https://discourse.slicer.org/t/issues-using-the-slicer-4-11-kernel-with-pytorch/22308/3 "2022-03-06T17:12:34Z")

</div>

Hello, this is the tutorial: [https://pytorch.org/tutorials/beginner/transfer\_learning\_tutorial.html](https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html)  
I it is not made for the Slicer kernel afaik, but I was trying to see if it would work for it since other models worked in it.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 6, 2022, 5:52pm UTC](https://discourse.slicer.org/t/issues-using-the-slicer-4-11-kernel-with-pytorch/22308/4 "2022-03-06T17:52:43Z")

</div>

You should try with the slicer preview build. It has a newer python and works with pytorch.
