This error is raised, if the variable trainloader is undefined. Often this could happen, if you have a typo in the name or the code logic is wrong, e.g. the trainloader is defined after its first usage.