kaggle Cats & Dogs

kaggle Cats & Dogs
Cats & Dogs on kaggle, that is, classification and prediction for cats and dogs of the picture, there is no characteristic data, only pictures, so it can only use trained neural network forecasting. Open reading a lot of examples on kaggle, mostly using TensorFlow or Keras create neural networks, because a recent study Torch, therefore, want to create a neural network with Torch convolution modeling predictions. But the whole process encountered many pits, the following record sum up my first time in the pit at the time of picture identification.
First, the data pre-processing
for picture certainly have to be pretreated can not be directly input into the model, and training data sample sizes in the picture, just load the data torchvision.datasets.Imagefolder module, but loaded directly display the file without any image files, suddenly ignorant force, obviously full of pictures, why not show it? Check out a variety of blog, had to become separated from the picture folder, which is the re-classification of the training set, automatic classification standard number Torch will tag the data after the data is read. During the pre-processing of data takes a lot of time and effort, but it feels very worth it, because understanding something of data processing Torch of great help to identify the picture later. But considering how to use the library or cv2 PIL library of images are processed and then torchvision.datasets.Imagefolder read it? Follow-up to continue to study. . .
Second, the network set up
to create a CNN network, to create a network directly nn.Model convolution inherited class, intermediate convolution layer of the parameter data more difficult to count, not particularly clear, direct parameter settings online, or by transfer learning, with More well-known image recognition algorithms. Change the parameters fully connected layers, the final classification is set to 2, the effect is good.
After training the model parameters and then if you want to use GPU cuda network settings makes him a GPU parameters, as well as create a variable Variable plus .cuda () converts the data, or be wrong, to forecast results for the Tensor data into data if numpy CPU models directly trained plus .numpy (), if the GPU training model is first converted to CPU data that is then converted numpy plus .cpu (). numpy ().
The Cats & Dogs picture identification made for several days, and the practical application of theory or slightly out of line, the code written in relatively bad not posted code. . . . .

Released nine original articles · won praise 2 · Views 3082

Guess you like

Origin blog.csdn.net/xiaokan_001/article/details/89357497