Pytorch CPU AssertionError

msoulio: <p>Hello everyone, I am trying to follow the object recognition tutorial from pytorch<br>
<a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html" rel="nofollow noopener">https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html</a>. I use Windows 10 with CPU only and I have tried both the pip and the conda install for the torch and torchvision packages (CPU version), however, I keep getting the same error shown below. Any help is greatly appreciated. Cheers.</p>
<hr>
<p>AssertionError                            Traceback (most recent call last)<br>
 in ()<br>
4 for epoch in range(num_epochs):<br>
5     # train for one epoch, printing every 10 iterations<br>
----&gt; 6     train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)<br>
7     # update the learning rate<br>
8     lr_scheduler.step()</p>
<p>D:\Resources\Pytorch Learn\engine.py in train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq)<br>
24         lr_scheduler = utils.warmup_lr_scheduler(optimizer, warmup_iters, warmup_factor)<br>
25<br>
—&gt; 26     for images, targets in metric_logger.log_every(data_loader, print_freq, header):<br>
27         images = list(image.to(device) for image in images)<br>
28         targets = [{k: v.to(device) for k, v in t.items()} for t in targets]</p>
<p>D:\Resources\Pytorch Learn\utils.py in log_every(self, iterable, print_freq, header)<br>
210                     meters=str(self),<br>
211                     time=str(iter_time), data=str(data_time),<br>
–&gt; 212                     memory=torch.cuda.max_memory_allocated() / MB))<br>
213             i += 1<br>
214             end = time.time()</p>
<p>C:\Users\Marinos\Anaconda3\lib\site-packages\torch\cuda\memory.py in max_memory_allocated(device)<br>
298         management.<br>
299     “”"<br>
–&gt; 300     return memory_stats(device=device)[“allocated_bytes.all.peak”]<br>
301<br>
302</p>
<p>C:\Users\Marinos\Anaconda3\lib\site-packages\torch\cuda\memory.py in memory_stats(device)<br>
157             result.append((prefix, obj))<br>
158<br>
–&gt; 159     stats = memory_stats_as_nested_dict(device=device)<br>
160     _recurse_add_to_result("", stats)<br>
161     result.sort()</p>
<p>C:\Users\Marinos\Anaconda3\lib\site-packages\torch\cuda\memory.py in memory_stats_as_nested_dict(device)<br>
166 def memory_stats_as_nested_dict(device=None):<br>
167     r""“Returns the result of :func:<code>~torch.cuda.memory_stats</code> as a nested dictionary.”""<br>
–&gt; 168     device = _get_device_index(device, optional=True)<br>
169     return torch._C._cuda_memoryStats(device)<br>
170</p>
<p>C:\Users\Marinos\Anaconda3\lib\site-packages\torch\cuda_utils.py in _get_device_index(device, optional)<br>
29         if optional:<br>
30             # default cuda device index<br>
—&gt; 31             return torch.cuda.current_device()<br>
32         else:<br>
33             raise ValueError('Expected a cuda device with a specified index ’</p>
<p>C:\Users\Marinos\Anaconda3\lib\site-packages\torch\cuda_<em>init</em>_.py in current_device()<br>
328 def current_device():<br>
329     r""“Returns the index of a currently selected device.”""<br>
–&gt; 330     _lazy_init()<br>
331     return torch._C._cuda_getDevice()<br>
332</p>
<p>C:\Users\Marinos\Anaconda3\lib\site-packages\torch\cuda_<em>init</em>_.py in _lazy_init()<br>
147             raise RuntimeError(<br>
148                 "Cannot re-initialize CUDA in forked subprocess. " + msg)<br>
–&gt; 149         _check_driver()<br>
150         if _cudart is None:<br>
151             raise AssertionError(</p>
<p>C:\Users\Marinos\Anaconda3\lib\site-packages\torch\cuda_<em>init</em>_.py in _check_driver()<br>
45 def _check_driver():<br>
46     if not hasattr(torch._C, ‘_cuda_isDriverSufficient’):<br>
—&gt; 47         raise AssertionError(“Torch not compiled with CUDA enabled”)<br>
48     if not torch._C._cuda_isDriverSufficient():<br>
49         if torch._C._cuda_getDriverVersion() == 0:</p>
<p>AssertionError: Torch not compiled with CUDA enabled</p>

peterjc123: <aside class="quote no-group" data-username="msoulio" data-post="1" data-topic="84680">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/ecccb3/48.png" class="avatar"> msoulio:</div>
<blockquote>
<p>D:\Resources\Pytorch Learn\utils.py in log_every(self, iterable, print_freq, header)<br>
210 meters=str(self),<br>
211 time=str(iter_time), data=str(data_time),<br>
–&gt; 212 memory=torch.cuda.max_memory_allocated() / MB))<br>
213 i += 1<br>
214 end = time.time()</p>
</blockquote>
</aside>
<p>Why do you call <code>torch.cuda.max_memory_allocated()</code> here?</p>

msoulio: <p>Thanks peterjc123, indeed this was not required. The version of utils and engine scripts were not 100% compatible with CPU. I had to make some small fixes, but now it works.<br>
Unfortunately the problems did not stop. I get a silent error that restarts the kernel in the following bold line. By running the script in Powershell, also no error, just stops execution.</p>
<p>res = {target[“image_id”].item(): output for target, output in zip(targets, outputs)}<br>
evaluator_time = time.time()<br>
<strong>coco_evaluator.update(res)</strong></p>
<p>UPDATE: Actually the following line is giving silent error when run for the 2nd time in a loop, so I guess it is a memory problem.</p>
<p>coco_dt = loadRes(self.coco_gt, results) if results else COCO()</p>

peterjc123: <aside class="quote no-group" data-username="msoulio" data-post="3" data-topic="84680">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/ecccb3/48.png" class="avatar"> msoulio:</div>
<blockquote>
<p>COCO</p>
</blockquote>
</aside>
<p>Could you please elaborate a little bit? What is the implementation of <code>loadRes</code> and <code>COCO</code>?</p>