简体   繁体   English

为什么内核在训练开始后很快就死了?

[英]Why the kernel quickly dies right after the training begins?

I'm trying to build a generative model for a dataset that I have.我正在尝试为我拥有的数据集构建一个生成模型。 I have used a stack of Conv2DTranspose layers, using tensorflow.我使用 tensorflow 使用了一堆 Conv2DTranspose 层。 here is my code:这是我的代码:

model = Sequential()

model.add(Conv2DTranspose(filters=2, kernel_size=3, input_shape = (2,2,1)))

for i in range(37):
    
    model.add(Conv2DTranspose(filters = 2*i, kernel_size = 3))
        

model.add(Conv2DTranspose(filters = 3, kernel_size=3))


model.compile(optimizer = 'Adam', loss='mean_squared_error')

model.fit(labels, ims, batch_size=32, epochs = 100) 

the input is of size (2,2,1) and the output is a (80,80,3) array which is supposed to be an image.输入的大小为 (2,2,1),输出是一个 (80,80,3) 数组,它应该是一个图像。 When I run the code, when it comes to train the model, meaning the line containing:当我运行代码时,当涉及到训练模型时,这意味着包含以下内容的行:

model.fit()

everything stopes and the running is ceased without showing any error or warning.一切停止,运行停止,没有显示任何错误或警告。 I have tried running this code using both Jupyter notebook and a simple .py file.我尝试使用 Jupyter notebook 和简单的 .py 文件运行此代码。 The result was same in both case.两种情况的结果都是一样的。 By the way, the system which I tried to use for running the code is a normal desktop machine exploiting only CPU and RAM (no GPU is included, RAM capacity = 32 GB).顺便说一下,我试图用来运行代码的系统是一台普通的台式机,只使用 CPU 和 RAM(不包括 GPU,RAM 容量 = 32 GB)。 How can I fix this?我怎样才能解决这个问题?

This is because a mistake in this line:这是因为这一行中的一个错误:

for i in range(37):  
    model.add(tf.keras.layers.Conv2DTranspose(filters = 2*i, kernel_size = 3))

As you set each layer filters by 2*i , the first layer filters will be 0 because i is 0 .当您将每层过滤器设置为2*i ,第一层过滤器将为0因为i0 So, your second layer output shape will be something like (None,6,6,0) , which does not make sense, and since tf libraries con not handle this, the kernel dies.因此,您的第二层输出形状将类似于(None,6,6,0) ,这是没有意义的,并且由于 tf 库无法处理此问题,因此内核会死亡。 So, I think you can change this line to something like this to avoid the mistake:因此,我认为您可以将此行更改为这样的内容以避免错误:

for i in range(37):  
    model.add(tf.keras.layers.Conv2DTranspose(filters = 2*(i+1), kernel_size = 3))

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

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