title: TypeError: Cannot handle this data type
body: <p>Trying to put the saliency map to the image and make a new data set <br/></p>
  
  <pre><code>trainloader = utilsxai.load_data_cifar10(batch_size=1,test=False)
  testloader =  utilsxai.load_data_cifar10(batch_size=128, test=True)
  </code></pre>
  
  <p>this load_cifar10 is torchvision</p>
  
  <pre><code>data = trainloader.dataset.data 
  
  trainloader.dataset.data = (data * sal_maps_hf).reshape(data.shape)
  </code></pre>
  
  <blockquote>
    <p>sal_maps_hf shape with (50000,32,32,3) <br/> and trainloader shape
    with (50000,32,32,3)</p>
  </blockquote>
  
  <p>but when I run this </p>
  
  <pre><code>for idx,img in enumerate(trainloader):
  </code></pre>
  
  <blockquote>
    <p>--------------------------------------------------------------------------- KeyError                                  Traceback (most recent call
    last) ~/venv/lib/python3.7/site-packages/PIL/Image.py in
    fromarray(obj, mode)    2644             typekey = (1, 1) + shape[2:],
    arr["typestr"]
    -> 2645             mode, rawmode = _fromarray_typemap[typekey]    2646         except KeyError:</p>
    
    <p>KeyError: ((1, 1, 3), '
    
    <p>During handling of the above exception, another exception occurred:</p>
    
    <p>TypeError                                 Traceback (most recent call
    last)  in 
    ----> 1 show_images(trainloader)</p>
    
    <p> in show_images(trainloader)
          1 def show_images(trainloader):
    ----> 2     for idx,(img,target) in enumerate(trainloader):
          3         img = img.squeeze()
          4         #pritn(img)
          5         img = torch.tensor(img)</p>
    
    <p>~/venv/lib/python3.7/site-packages/torch/utils/data/dataloader.py in
    <strong>next</strong>(self)
        344     def <strong>next</strong>(self):
        345         index = self._next_index()  # may raise StopIteration
    --> 346         data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
        347         if self._pin_memory:
        348             data = _utils.pin_memory.pin_memory(data)</p>
    
    <p>~/venv/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in
    fetch(self, possibly_batched_index)
         42     def fetch(self, possibly_batched_index):
         43         if self.auto_collation:
    ---> 44             data = [self.dataset[idx] for idx in possibly_batched_index]
         45         else:
         46             data = self.dataset[possibly_batched_index]</p>
    
    <p>~/venv/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in
    (.0)
         42     def fetch(self, possibly_batched_index):
         43         if self.auto_collation:
    ---> 44             data = [self.dataset[idx] for idx in possibly_batched_index]
         45         else:
         46             data = self.dataset[possibly_batched_index]</p>
    
    <p>~/venv/lib/python3.7/site-packages/torchvision/datasets/cifar.py in
    <strong>getitem</strong>(self, index)
        120         # doing this so that it is consistent with all other datasets
        121         # to return a PIL Image
    --> 122         img = Image.fromarray(img)
        123 
        124         if self.transform is not None:</p>
    
    <p>~/venv/lib/python3.7/site-packages/PIL/Image.py in fromarray(obj,
    mode)    2645             mode, rawmode = _fromarray_typemap[typekey] 
    2646         except KeyError:
    -> 2647             raise TypeError("Cannot handle this data type")    2648     else:    2649         rawmode = mode</p>
    
    <p>TypeError: Cannot handle this data type</p>
  </blockquote>
  
  <pre><code>trainloader.dataset.__getitem__
  </code></pre>
  
  <blockquote>
    <p>getitem of Dataset CIFAR10
        Number of datapoints: 50000
        Root location: /mnt/3CE35B99003D727B/input/pytorch/data
        Split: Train
        StandardTransform Transform: Compose(
                   Resize(size=32, interpolation=PIL.Image.BILINEAR)
                   ToTensor()
               )</p>
  </blockquote>