My code is already quite long (more than 50 lines for the custom dataset alone) so I guess the forum is not the right place to post and look at hundreds of lines of code. And I did not yet locate the problem close enough to produce a minimal example to reproduce the error.
Thanks anyway. I will keep you updated.