Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter st

Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter st,第1张

使用tensorflow.keras模型训练时这个错误经常报:

tensorflow/core/kernels/data/generator_dataset_op.cc:107] Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.
	 [[{{node PyFunc}}]]

tensorflow/core/kernels/data/generator_dataset_op.cc:107] Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.

       [[{{node PyFunc}}]]

根据自己经验,很大概率是下面几个原因:

1 模型建立时输入的image_size  input_shape不符或未定义造成。注意,定义卷积层第一层时,一定要定义input_shape, 例如:

    model = keras.models.Sequential([
        # 输入图片[None,224,224,3]
        # 卷积层1: 32个 5*5*3的filter, 步长设置1,填充设same
        # 输出[None,32,32,3]
        keras.layers.Conv2D(32, kernel_size=5, strides=1, padding='same', data_format='channels_last',
                            activation='relu', input_shape=(224, 224, 3)),

2 还有就是train_generator validate_generator相关参数必须保持一致,比如batch_size, target_size, class_mode

3 本身配置限制,batch_size改小试试,甚至改到1试试

4 上一次程式运行没有彻底结束,把所有python程式结束看看。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/718644.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存