OSError: [Errno 22] Invalid argument | _pickle.UnpicklingError: pickle data was truncated
When trying to train a ResNet I get this error. Any help as to why this happens would be appreciated.
This happens when I try to iterate through the Dataloader:
File &quot;C:\Users\JCout\AppData\Local\Temp/ipykernel_2540/2174299330.py&quot;, line 1, in &lt;module&gt;
    runfile('C:/Users/JCout/Documents/GitHub/Hybrid_resnet/transfer_learning.py', wdir='C:/Users/JCout/Documents/GitHub/Hybrid_resnet')

  File &quot;C:\Users\JCout\anaconda3\lib\site-packages\debugpy\_vendored\pydevd\_pydev_bundle\pydev_umd.py&quot;, line 167, in runfile
    execfile(filename, namespace)

  File &quot;C:\Users\JCout\anaconda3\lib\site-packages\debugpy\_vendored\pydevd\_pydev_imps\_pydev_execfile.py&quot;, line 25, in execfile
    exec(compile(contents + &quot;\n&quot;, file, 'exec'), glob, loc)

  File &quot;C:/Users/JCout/Documents/GitHub/Hybrid_resnet/transfer_learning.py&quot;, line 24, in &lt;module&gt;
    model, train_loss, test_loss = train.train_model(training, testing,

  File &quot;C:\Users\JCout\Documents\GitHub\Hybrid_resnet\train.py&quot;, line 70, in train_model
    train_stats = train.train_step(model, criterion, optimizer, train_loader)

  File &quot;C:\Users\JCout\Documents\GitHub\Hybrid_resnet\train.py&quot;, line 121, in train_step
    for i, (x_imgs, labels) in enumerate(train_loader):

  File &quot;C:\Users\JCout\anaconda3\lib\site-packages\torch\utils\data\dataloader.py&quot;, line 359, in __iter__
    return self._get_iterator()

  File &quot;C:\Users\JCout\anaconda3\lib\site-packages\torch\utils\data\dataloader.py&quot;, line 305, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)

  File &quot;C:\Users\JCout\anaconda3\lib\site-packages\torch\utils\data\dataloader.py&quot;, line 918, in __init__
    w.start()

  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\process.py&quot;, line 121, in start
    self._popen = self._Popen(self)

  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\context.py&quot;, line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)

  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\context.py&quot;, line 327, in _Popen
    return Popen(process_obj)

  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\popen_spawn_win32.py&quot;, line 93, in __init__
    reduction.dump(process_obj, to_child)

  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\reduction.py&quot;, line 60, in dump
    ForkingPickler(file, protocol).dump(obj)

OSError: [Errno 22] Invalid argument

I'm also getting this traceback after the error which I find a bit weird since I'm not using pickle at all. The data consists of 2 .tif files and 2 .mat files for the data/targets.
Traceback (most recent call last):
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\spawn.py&quot;, line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\spawn.py&quot;, line 126, in _main
    self = reduction.pickle.load(from_parent)
_pickle.UnpicklingError: pickle data was truncated
Traceback (most recent call last):
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\spawn.py&quot;, line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File &quot;C:\Users\JCout\anaconda3\lib\multiprocessing\spawn.py&quot;, line 126, in _main
    self = reduction.pickle.load(from_parent)
_pickle.UnpicklingError: pickle data was truncated


Not entirely sure what was happening, but I had
pin_memory = True
num_workers = 4

within the DataLoader. Removing these removed the error.
