import tensorflow as tf
import numpy as np
import tensorflow.keras.layers as layers
import tensorflow.keras as keras
from tensorflow.keras.optimizers import Adam
def get_model():
inputs = layers.Input(batch_shape=(1, 200, 12)) #input
x = layers.LSTM(12, return_sequences=True, stateful=True)(inputs)
outputs = layers.TimeDistributed(layers.Dense(2, activation="softmax"))(x)
model = keras.Model(inputs=inputs, outputs=outputs)
model.compile(loss='categorical_crossentropy', optimizer=Adam(), metrics=['accuracy'])
print(model.summary())
return model
model = get_model()
x_train = np.ones((10,200,12))
x_val = np.ones((10,200,12))
y_train = np.ones((10,200,2))
y_val = np.ones((10,200,2))
history = model.fit(x_train, y_train,
epochs=40,
validation_data=(x_val, y_val),
verbose=2)
이 출력을 제공합니다
InvalidArgumentError: [_Derived_] Specified a list with shape [1,12] from a tensor with shape [10,12]
[[{{node TensorArrayUnstack/TensorListFromTensor}}]]
[[model_19/lstm_47/StatefulPartitionedCall]] [Op:__inference_train_function_78329]
x_train과 x_val 모양 (1,200,12)을 만들면 잘 작동합니다. 입력 개체가 여러 배치를 받아들이도록하려면 어떻게해야합니까?
이렇게 batch_size를 지정해야했던 것으로 밝혀졌습니다.
history = model.fit(x_train, y_train,
epochs=40,
validation_data=(x_val, y_val),
verbose=2,
batch_size=1
)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다