我正在Google Colab中运行代码,当模型开始训练时,它卡在了第1阶段而没有显示任何错误消息
WINDOW_SIZE=30
SHUFFLE_BUFFER=141
BATCH_SIZE=32
def windowed_dataset(SERIES,WINDOW_SIZE,BATCH_SIZE,SHUFFLE_BUFFER):
dataset=tf.data.Dataset.from_tensor_slices(SERIES)
dataset=dataset.window(WINDOW_SIZE+1,shift=1,drop_remainder=True)
dataset=dataset.flat_map(lambda x: x.batch(WINDOW_SIZE+1))
dataset=dataset.shuffle(SHUFFLE_BUFFER)
dataset=dataset.map(lambda x:(x[:-1],x[-1]))
dataset=dataset.batch(BATCH_SIZE).prefetch(1)
return dataset
model=tf.keras.Sequential([
tf.keras.layers.Lambda(lambda x: tf.expand_dims(x,axis=-1),input_shape=[None]),
tf.keras.layers.Conv1D(100,5,activation='softmax'),
tf.keras.layers.LSTM(64,return_sequences=True),
tf.keras.layers.LSTM(64),
tf.keras.layers.Dense(128,activation='relu'),
tf.keras.layers.Dense(64,activation='relu'),
tf.keras.layers.Dense(1),
tf.keras.layers.Lambda(lambda x: x*100)
])
lrs=tf.keras.callbacks.LearningRateScheduler(lambda epoch: 1e-6 * 10**(epoch / 20))
print(model.summary())
tf.keras.backend.clear_session()
tf.random.set_seed(51)
np.random.seed(51)
model.compile(optimizer=tf.keras.optimizers.SGD(learning_rate=1e-6,momentum=0.9),loss=tf.keras.losses.Huber(),metrics=["mae"])
dataset=windowed_dataset(series[50],WINDOW_SIZE,BATCH_SIZE,SHUFFLE_BUFFER)
history=model.fit(dataset,epochs=10,callbacks=[lrs],verbose=1)