PyTorch is a convenient framwork which allows us to build deep learning network faster.
However, its tutorial does not provide example of loading datasets from raw data e.g. images. This tutorial uses cifar-10 datasets as an example to show how to load data without torchvision. SourceCode
First, we download train.7z and trainLabels.csv from kaggle. train.7z contains images from different classes and trainLabels.csv gives out the related labels. Unzip train.7z and put it into 'data' fold. Then we can use data_prepare.py to process data. Specially, function data_preprocessing normalize images to [-1, 1]. Please be aware that shape of training sample is [3,32,32] or PyTorch will report error.
Then we can use cifar-10.py to train the network. Network structure is
3*1->1*3->RELU->BN ->3*1->1*3->RELU->maxpool->BN ->3*1->1*3->RELU->BN ->3*1->1*3->RELU->avgpool->BN->3*1->1*3->RELU ->BN->3*1->1*3->RELU->BN->3*1->1*3->RELU->avgpool->BN->fc(256,256)->fc(256,10)
With 200 epochs the best validation error is 83%.
网友评论