Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer reshape issue #45

Open
paulprasanth536 opened this issue May 21, 2021 · 0 comments
Open

Layer reshape issue #45

paulprasanth536 opened this issue May 21, 2021 · 0 comments

Comments

@paulprasanth536
Copy link

This is the input code I've Given:

X_array=np.asarray(X_train).astype(np.int)

y_array=np.asarray(y_train).astype(np.int)
X_shaped = np.reshape(X_array, newshape=(-1,18727,3))
y_shaped = np.reshape(y_array,newshape=(-1,18727,2))

model = Sequential()
model.add(LSTM(units=1, input_shape=(10000,3), return_sequences=True))
model.add(LSTMt_shape=(1,18727,3),dropout=0.25,return_sequences=True, input_shape=(-1,18727,2)))

model.add(LSTM(132,batch_input_shape=(1,18727,2),dropout=0.25,return_sequences=True))
model.add(Dense(1,batch_input_shape=(1,18727,3),activation='softmax',batch_size=32))
model.add(Dense(1,batch_input_shape=(1,18727,2),activation='softmax',batch_size=32))

model.compile(loss="mean_absolute_error", optimizer="adam", metrics= ['accuracy'])
model.compile(loss='mse', optimizer='rmsprop',metrics=['accuracy'])## Binary cross entropy/ categorical cross
start = time.time()
print ('compilation time : ', time.time() - start) (units=1, input_shape=(4000,2), return_sequences=True))
model.add(LSTM(132,batch_input)

The Error im getting is this:

Epoch 1/100
WARNING:tensorflow:Model was constructed with shape (None, 10000, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, 10000, 3), dtype=tf.float32, name='lstm_16_input'), name='lstm_16_input', description="created by layer 'lstm_16_input'"), but it was called on an input with incompatible shape (None, 18727, 3).
WARNING:tensorflow:Model was constructed with shape (None, 10000, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, 10000, 3), dtype=tf.float32, name='lstm_16_input'), name='lstm_16_input', description="created by layer 'lstm_16_input'"), but it was called on an input with incompatible shape (None, 18727, 3).
1/1 [==============================] - ETA: 0s - loss: 9914.3594 - accuracy: 5.3399e-04

ValueError Traceback (most recent call last)
in ()
6 #y_scaled = scaler.fit_transform(y_shaped)
7 #print(X_scaled,y_scaled)
----> 8 history = model.fit(X_shaped,y_shaped,epochs=100, validation_data=(X_array,y_array))
9 print(model.summary())

10 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
975 except Exception as e: # pylint:disable=broad-except
976 if hasattr(e, "ag_error_metadata"):
--> 977 raise e.ag_error_metadata.to_exception(e)
978 else:
979 raise

ValueError: in user code:

/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:1233 test_function  *
    return step_function(self, iterator)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:1224 step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:1259 run
    return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica
    return self._call_for_each_replica(fn, args, kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica
    return fn(*args, **kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:1217 run_step  **
    outputs = model.test_step(data)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:1183 test_step
    y_pred = self(x, training=False)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py:998 __call__
    input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/input_spec.py:223 assert_input_compatibility
    str(tuple(shape)))

ValueError: Input 0 of layer sequential_3 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant