How can I use a pre-trained neural network with grayscale images?

后端 未结 11 1297
无人及你
无人及你 2020-12-02 09:35

I have a dataset containing grayscale images and I want to train a state-of-the-art CNN on them. I\'d very much like to fine-tune a pre-trained model (like the ones here).

11条回答
  •  悲哀的现实
    2020-12-02 10:06

    A simple way to do this is to add a convolution layer before the base model and then feed the output to the base model. Like this:

    from keras.models import Model
    from keras.layers import Input 
    
    resnet = Resnet50(weights='imagenet',include_top= 'TRUE') 
    
    input_tensor = Input(shape=(IMG_SIZE,IMG_SIZE,1) )
    x = Conv2D(3,(3,3),padding='same')(input_tensor)    # x has a dimension of (IMG_SIZE,IMG_SIZE,3)
    out = resnet (x) 
    
    model = Model(inputs=input_tensor,outputs=out)
    
    
    

提交回复
热议问题