How to give variable size images as input in keras

后端 未结 3 712
我寻月下人不归
我寻月下人不归 2020-12-19 07:44

I am writing a code for image classification for two classes using keras with tensorflow backend. My images are stored in folder in computer and i want to give these images

3条回答
  •  一生所求
    2020-12-19 08:24

    See the answer in https://github.com/keras-team/keras/issues/1920 Yo you should change the input to be:

    input = Input(shape=(None, None,3))
    

    The in the end add GlobalAveragePooling2D():

    Try something like that ...

    input = Input(shape=(None, None,3))
    
    model = Sequential()
    model.add(Conv2D(8, kernel_size=(3, 3),
                     activation='relu',
                     input_shape=(None, None,3)))  #Look on the shape
    model.add(Conv2D(16, (3, 3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))
    # IMPORTANT !
    model add(GlobalAveragePooling2D())
    # IMPORTANT !
    model.add(Flatten())
    model.add(Dense(32, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(2, activation='softmax'))
    
    model.compile(loss='binary_crossentropy',optimizer='rmsprop',metrics=['accuracy'])
    

提交回复
热议问题