Home > other >  Excuse me pytorch CNN how to train a large number of categories, such as 10000 classification
Excuse me pytorch CNN how to train a large number of categories, such as 10000 classification

Time:09-15

I am using a python program training before the corresponding model, but less categories, most are about 300 categories
Now demand is:
There are about more than 30000 images, each for a class of images, then training model, input in the course of applying a new image, find the most similar images

The CNN before the code below
 
Class CNN (nn Module) : # convolution neural network (CNN) --
Def __init__ (self) :
The self, super (CNN) __init__ ()
The self. The conv1=nn. Sequential REAIZE under a layer of convolution layer (#=(50, 25)
Nn. Conv2d (# convolution layer, the input dimension (3, REAIZE)
In_channels=3, # layer height, gray scale figure 1 layer, RGB image is three layer
Out_channels=32, by scanning a section for # 32 characteristics (extracting the characteristics of the training effect is good, more speed slow)
# kernel_size=5, the scanning area wide high pixel
Stride=1, # each pixel distance convolution
# padding=(kernel_size - 1)/2 if stride=1
Padding=2, # for scanning the area less than the location of the added 2 pixels
#), the output dimensions (32, REAIZE)
Nn. ReLU (), # excitation function, dimension (32, REAIZE)
# pooling layer, take numerical largest wide high to 5 (5, 5) area for the feature points, the output dimensions (32, 10, 5)
# calculation method: when REAIZE=(50, 25), the output of (5, 25, 32, 50//5), the output (32,10,5)
Nn. MaxPool2d (kernel_size=(5)),
)
Self. Conv2=nn. Sequential layer (# 2 convolution
Nn. Conv2d (32, 64, 5, 1, 2), the thickness of 32 # the input output for 64 layer thickness (64,10,5)
Nn. ReLU (),
# calculation method,10,5: (64), the output for (64, 10/1/2 and 5), the output (64,5,5)
Nn. MaxPool2d ((2, 1)),
)
Self. Out=nn. Linear (64 * 5 * 5, 2) 64 * 5 * 5 # input, output, 2 (2 for training data on the number of categories)

Def forward (self, x) :
X=self. Conv1 (x)
X=self. Conv2 (x)
X=x.v iew (x.s considering (0), 1) # of multidimensional exhibition of tensor pp.47-53 one-dimensional, x.s considering (0) refers to the value of batchsize
The output=self. Out (x)
Return the output, x

CodePudding user response:

I now the classification of the initial setup output 100000, trained 300 images for the first time, generation model, after training, add 300 images, will continue training model, but the training to 10000 images meet the bottleneck, training not bottom go to
  • Related