Given a trained object detection network the goal of my program is to prune the network, deleting the least contributing filters and their dependent feature maps and biases. After a network is pruned the network is retrained to regain the accuracy it has lost. Retraining this network a second time after pruning and retraining it a first time results in the following error:
Traceback (most recent call last):
  File "Pruning.py", line 212, in <module>
    prune()
  File "Pruning.py", line 52, in __call__
    self.pruneLoop(prune)
  File "Pruning.py", line 80, in pruneLoop
    traineng()
  File "/home/bullseye/.local/lib/python3.6/site-packages/lightnet/engine/_engine.py", line 124, in __call__
    self.process_batch(data)
  File "/home/bullseye/Documents/git/Master-Thesis-Pruning-for-Object-Detection/docker-omgeving/Code/trainengine.py", line 34, in process_batch
    loss.backward()
  File "/home/bullseye/.local/lib/python3.6/site-packages/torch/tensor.py", line 166, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/home/bullseye/.local/lib/python3.6/site-packages/torch/autograd/__init__.py", line 99, in backward
    allow_unreachable=True)  # allow_unreachable flag
RuntimeError: The size of tensor a (1010) must match the size of tensor b (798) at non-singleton dimension 1

Since the error is occurring in the backwards function it hints that the problem is created when retraining a first time. My first thought was that the grad created by training a first time was the issue but the problem remained even after deleting the gradients after pruning.
What is causing this error?