简体   繁体   English

Tensorflow Keras:在 model.fit() 上进行训练

[英]Tensorflow Keras: Training Holting on model.fit()

I am new to tensorflow and python, so I'm sure its just something stupid.我是 tensorflow 和 python 的新手,所以我确信这只是一些愚蠢的事情。 But when I try to train my model with model.fit(), after a random number of training iterations it freezes.但是,当我尝试使用 model.fit() 训练我的 model 时,经过随机数量的训练迭代后,它会冻结。 GPU usage goes to zero, and no error message is shown to indicate where the error is. GPU 使用量归零,并且没有显示错误消息来指示错误所在。 The model I am trying to train is as follows:我正在尝试训练的 model 如下:

SizeOfInput = 50
VocabSize = 8000
EmbeddingSize = 200

model = Sequential()
model.add(Embedding(input_dim=VocabSize, output_dim=EmbeddingSize, input_length=SizeOfInput))
model.add(LSTM(256, input_shape=(SizeOfInput, EmbeddingSize), return_sequences=True))
model.add(Dropout(0.1))
model.add(LSTM(256))
model.add(Dropout(0.1))
model.add(Dense(VocabSize, activation='softmax'))

optimizer = tf.keras.optimizers.RMSprop(lr=1e-3, decay=1e-5)
model.compile(loss='categorical_crossentropy', optimizer=optimizer)

Tensorflow: 2.2.0 Tensorflow:2.2.0

Python: 3.8 Python:3.8

GPU: RTX2080Ti GPU:RTX2080Ti

I am training on 10000 randomly sampled sequences of 50 integers each epoch, from a larger dataset:我正在从一个更大的数据集中训练 10000 个随机采样的每个时期 50 个整数的序列:

model.fit(x, y, batch_size=100, epochs=1)

I really don't know what the issue is, let me know if you need more information我真的不知道问题是什么,如果您需要更多信息,请告诉我

1.Firstly please try your code in Google Colab 1.首先请在Google Colab中尝试您的代码

2.Try to use another optimizer: 2.尝试使用另一个优化器:

keras.layers.BatchNormalization._USE_V2_BEHAVIOR = False

3.Maybe some ops running in cpu and some Ops are running in GPU. 3.也许一些操作在 cpu 中运行,一些操作在 GPU 中运行。 In order to prevent it:为了防止它:

with tf.device("/device:GPU:0"):
    model.fit(x, y, batch_size=100, epochs=1)

3.Update the latest version of 3.更新最新版本

tf-nightly-gpu 
tf-gpu 2.1 cudn 10.2

4.Test this: 4.测试这个:

print(tf.version.VERSION, tf.executing_eagerly(), keras.layers.BatchNormalization._USE_V2_BEHAVIOR)

keras.layers.BatchNormalization._USE_V2_BEHAVIOR = False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM