0

I want to use this code as an autoencoder:

# ENCODER
input_sig = Input(batch_shape=(None,1389,1))
x = Conv1D(64,3, activation='relu', padding='valid')(input_sig)
x1 = MaxPooling1D(2)(x)
x2 = Conv1D(32,3, activation='relu', padding='valid')(x1)
x3 = MaxPooling1D(2)(x2)
flat = Flatten()(x3)
encoded = Dense(32,activation = 'relu')(flat)
#encoded = Reshape((32,1))(encoded)

print("shape of encoded {}".format(K.int_shape(encoded)))

# DECODER 
x2_ = Conv1D(32, 3, activation='relu', padding='valid')(x3)
x1_ = UpSampling1D(2)(x2_)
x_ = Conv1D(64, 3, activation='relu', padding='valid')(x1_)
upsamp = UpSampling1D(2)(x_)
flat = Flatten()(upsamp)
decoded = Dense(1389,activation = 'relu')(flat)
decoded = Reshape((1389,))(decoded)

print("shape of decoded {}".format(K.int_shape(decoded)))

autoencoder = Model(input_sig, decoded)
autoencoder.compile(optimizer='adam', loss='mse', metrics=['accuracy'])    

As you can see, the shapes of encoded is (?, 32) and decoded (?, 1389).

The shape of my training_data is (141, 1389).

By execute the following code,

autoencoder.fit(X_train, X_train,
                epochs=150,
                batch_size=256,
                shuffle=True,
                validation_data=(X_test, X_test))

I got the error: ValueError: Error when checking input: expected input_15 to have 3 dimensions, but got array with shape (141, 1389)

Could you help me by solving this problem?

4
  • As you said your shape of your training_data is (141, 1389) and your Input layer has a shape (None,1389,1). So it is expecting 3 dimensions. Change either of the shapes according to your need. Commented Apr 12, 2019 at 8:52
  • Thanks for the answer, sadly that will result in the standart error: ValueError: Input 0 is incompatible with layer conv1d_56: expected ndim=3, found ndim=2 Commented Apr 12, 2019 at 8:56
  • Why don't you change the shape of your input tensor? Add an extra dimension at the end so that it matches your Input layer Commented Apr 12, 2019 at 9:02
  • after changing the input tensor to add an extra dimension the error disappears and a new error appears: train = K.reshape(X_train,(141,1389,1)) test = K.reshape(X_test,(36,1389,1)) autoencoder.fit(train, train, epochs=150, batch_size=256, shuffle=True, validation_data=(test, test)) ValueError: If your data is in the form of symbolic tensors, you should specify the "steps_per_epoch" argument (instead of the "batch_size" argument, because symbolic tensors are expected to produce batches of input data). Commented Apr 12, 2019 at 10:26

1 Answer 1

1

Use:

X_train = np.expand_dims(X_train, axis=2)

to expand your training data into a third dimension.

Hope it helps!

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks, its quiet funny, after changing the dimensions to three, he wants a 2 dimension shape ..ValueError: Error when checking target: expected reshape_1 to have 2 dimensions, but got array with shape (141, 1389, 1)
Well but now the problem is not your input anymore, now it is the output. Your decoded = Reshape((1389,))(decoded) expects a target (y_train) of shape (?, 1389) as you found out yourself. But you are trying to give it something of shape (141, 1389, 1) .
after changing decoded = Reshape((1389,))(decoded) to decoded = Reshape((1389,1))(decoded) the code is running =) thanks a lot @ga97dil

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.