Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution'

后端 未结 6 1707
情书的邮戳
情书的邮戳 2020-12-14 02:33

I got this error message when declaring the input layer in Keras.

ValueError: Negative dimension size caused by subtracting 3 from 1 for \'conv2d_2/

6条回答
  •  天命终不由人
    2020-12-14 03:31

        # define the model as a class
    class LeNet:
    
      '''
          In a sequential model, we stack layers sequentially. 
          So, each layer has unique input and output, and those inputs and outputs 
          then also come with a unique input shape and output shape.
    
      '''
    
      @staticmethod                ## class can instantiated only once 
      def init(numChannels, imgRows, imgCols , numClasses, weightsPath=None):
    
        # if we are using channel first we have update the input size
        if backend.image_data_format() == "channels_first":
          inputShape = (numChannels , imgRows , imgCols)
        else: 
          inputShape = (imgRows , imgCols , numChannels)
    
        # initilize the model
        model = models.Sequential()
    
        # Define the first set of CONV => ACTIVATION => POOL LAYERS
    
        model.add(layers.Conv2D(  filters=6,kernel_size=(5,5),strides=(1,1), 
                                  padding="valid",activation='relu',kernel_initializer='he_uniform',input_shape=inputShape))
        model.add(layers.AveragePooling2D(pool_size=(2,2),strides=(2,2)))
    

    I hope it would help :)

    See code : Fashion_Mnist_Using_LeNet_CNN

提交回复
热议问题