0

I am trying to train a model based on a number of txt. file with 2623 lines of numbers. The model is as follows:

input_img = Input(shape=(2623,1), name='input')

x = Conv1D(32, 3, activation='relu', padding='same', use_bias=False)(input_img)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling1D(2, padding='same')(x)
x = Conv1D(16, 3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling1D(2, padding='same')(x)
x = Conv1D(16,3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(x)
x = BatchNormalization(axis=-1)(x)
encoded = MaxPooling1D(2, padding='same')(x)


x = Conv1D(16,3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(encoded)
x = BatchNormalization(axis=-1)(x)
x = UpSampling1D(2)(x)
x = Conv1D(16,3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(x)
x = BatchNormalization(axis=-1)(x)
x = UpSampling1D(2)(x)
x = Conv1D(32, 3, activation='relu', padding='same', use_bias=False, input_shape=(2623,1))(x)  #input_shape=(30, 1))
x = BatchNormalization(axis=-1)(x)  
x = UpSampling1D(2)(x)
decoded = Conv1D(3, 3, activation='sigmoid', padding='same', use_bias=False,input_shape=(2623,1))(x)

autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='rmsprop', loss='binary_crossentropy')


x = Input(shape=(16, 300), name="input")
h = x
h = Conv1D(filters=300, kernel_size=16,
             activation="relu", padding='same', name='Conv1',input_shape=(2623,1))(h)
h = MaxPooling1D(pool_size=16, name='Maxpool1')(h)

Whenever i try to fit the model with the following code i get an error saying: Error when checking target: expected conv1d_283 to have shape (2624, 1) but got array with shape (2623, 1)

I tried different padding and setting the input space smaller but it does not seem to work. I do not get the error because whatever i do in the end i have an error for different dimensions. Any ideas?

history = autoencoder.fit(train, train,
                epochs=100,
                batch_size=256,
                shuffle=True,
                validation_data=(test, test))                   
7
  • Check your train dimensions.They must have shape (2624,1).Or, change input_shape according to your train shape Commented Oct 5, 2018 at 11:34
  • my train shape is (1020, 2623) which basically is 1020 txt files with 2623 lines each so it is the same i guess Commented Oct 5, 2018 at 11:35
  • Can you print and tell the shape of encoded? Also there are multiple Conv1Ds. Check which of them is giving the error. Commented Oct 5, 2018 at 11:36
  • Hmm running encoded.shape i get: TensorShape([Dimension(None), Dimension(328), Dimension(16)]) Commented Oct 5, 2018 at 11:38
  • Decoded.shape() gives: TensorShape([Dimension(None), Dimension(2624), Dimension(3)]) on the other hand. I think this is the problem Commented Oct 5, 2018 at 11:40

1 Answer 1

1

Thank you for the help. In the end adding a croplayer in the end did the trick, i.e:

x = Cropping1D(cropping=(0, 1))(x) # Crop nothing from input but crop 1 elemnt from the end 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.