What is mean by (AttributeError: 'NoneType' object has no attribute '__array_interface__') error?
I am trying to build a ML model to detect landmarks on a cartoon image face. When I split the image dataset in to training and validation sets I got the following error. Here I am using pytorch to build the model. So what is mean by this error?
This is how I split the dataset.
# split the dataset into validation and test sets
len_valid_set = int(0.2*len(dataset))
len_train_set = len(dataset) - len_valid_set

print(&quot;The length of Train set is {}&quot;.format(len_train_set))
print(&quot;The length of Valid set is {}&quot;.format(len_valid_set))

train_dataset , valid_dataset,  = torch.utils.data.random_split(dataset , [len_train_set, len_valid_set])

# shuffle and batch the datasets
train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=32, shuffle=True, num_workers=4)
valid_loader = torch.utils.data.DataLoader(valid_dataset, batch_size=8, shuffle=True, num_workers=4)

images, landmarks = next(iter(train_loader))

This is the error I got.
The length of Train set is 105
The length of Valid set is 26

AttributeError                            Traceback (most recent call last)
&lt;ipython-input-61-ffb86a628e37&gt; in &lt;module&gt;()
----&gt; 1 images, landmarks = next(iter(train_loader))
      2 
      3 print(images.shape)
      4 print(landmarks.shape)

3 frames
/usr/local/lib/python3.6/dist-packages/torch/_utils.py in reraise(self)
    426             # have message field
    427             raise self.exc_type(message=msg)
--&gt; 428         raise self.exc_type(msg)
    429 
    430 

AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File &quot;/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py&quot;, line 198, in _worker_loop
    data = fetcher.fetch(index)
  File &quot;/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py&quot;, line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File &quot;/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py&quot;, line 44, in &lt;listcomp&gt;
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File &quot;/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataset.py&quot;, line 272, in __getitem__
    return self.dataset[self.indices[idx]]
  File &quot;&lt;ipython-input-12-5595ac89d75d&gt;&quot;, line 38, in __getitem__
    image, landmarks = self.transform(image, landmarks, self.crops[index])
  File &quot;&lt;ipython-input-9-e38df55ee0d4&gt;&quot;, line 46, in __call__
    image = Image.fromarray(image)
  File &quot;/usr/local/lib/python3.6/dist-packages/PIL/Image.py&quot;, line 2670, in fromarray
    arr = obj.__array_interface__
AttributeError: 'NoneType' object has no attribute '__array_interface__'


Basically it says when executing the line image = Image.fromarray(image), the Image.fromarray function is expecting image to be an array and that image implements a function called __array_interface__ that will turn itself into an image. However, during execution image is actually None (a python object type for nothing). Surely you can't turn None into an image.
There could be something wrong with your data. I'd suggest not doing the random split first and check if the each item in the dataset is not None.
