yandex
loader

please wait

  • Harsh Vashishth Feb-12-2019 06:34:17 AM ( 3 months ago )

    I am feeding 1080x1616 color photos into a convolutional neural network in Keras. The data is fed through the network just fine, until it gets to the last convolutional layer, throwing an error saying that it expects a 4D tensor, but instead gets a (32,1) tensor. I don't understand where this number is being generated.

    This is my model architecture:

    model = keras.Sequential([
            Conv2D(32, (3,3), padding='same', activation='relu', data_format="channels_last", input_shape=(self.x_res,self.y_res,self.n_channels), kernel_initializer=keras.initializers.he_normal()),
            MaxPooling2D((2,2)),
            Conv2D(64, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            MaxPooling2D((2, 2)),
            Conv2D(128, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            MaxPooling2D((2, 2)),
            Conv2D(256, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            UpSampling2D((2, 2)),
            Conv2D(128, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            UpSampling2D((2, 2)),   
            Conv2D(64, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            UpSampling2D((2, 2)),
            Conv2D(self.n_channels, (1, 1), padding='same', activation='sigmoid', kernel_initializer=keras
  • Raman Tripathi Feb-12-2019 06:35:39 AM ( 3 months ago )

    The input to your model should be of shape (batch_size, x_res, y_res, n_channels), please check it.

    Following is a simple test:

    import keras
    from keras.layers import Conv2D, MaxPooling2D, UpSampling2D
    import numpy as np
    
    x_res = 1080
    y_res = 1616
    n_channels = 3
    
    model = keras.Sequential([
            Conv2D(32, (3,3), padding='same', activation='relu', data_format="channels_last", input_shape=(x_res,y_res,n_channels), kernel_initializer=keras.initializers.he_normal()),
            MaxPooling2D((2,2)),
            Conv2D(64, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            MaxPooling2D((2, 2)),
            Conv2D(128, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            MaxPooling2D((2, 2)),
            Conv2D(256, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            UpSampling2D((2, 2)),
            Conv2D(128, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            UpSampling2D((2, 2)),   
            Conv2D(64, (3, 3), padding='same', activation='relu', kernel_initializer=keras.initializers.he_normal()),
            UpSampling2D((2, 2)),
            Conv2D(n_channels, 

Please login

Similar Discussion

Recommended For You