I just put up a full example here (https://github.com/rasbt/deep-learning-book/blob/master/code/model_zoo/pytorch_ipynb/custom-data-loader-csv.ipynb 244) that might be handy as a template for your scenario