Python Tensorflow2.6 Failed precondition: Python interpreter state is not initialized. The process

tensorflow2.6报错

Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.
         [[{{node PyFunc}}]]

训练集分类模式为categorical

train_generator = train_datagen.flow_from_directory(
    train_dir,
    target_size=(pic_height,pic_width),
    batch_size=32,
    class_mode='categorical',
    subset='training',
    shuffle=True,
)

之后编译模型时损失函数是sparse_categorical_crossentropy,是分类模式sparse使用的

model.compile(optimizer='adam',
             loss='sparse_categorical_crossentropy',
             metrics=['accuracy'])

改成categorical_crossentropy

model.compile(optimizer='adam',
             loss='categorical_crossentropy',
             metrics=['accuracy'])

你可能感兴趣的:(python,python,tensorflow,人工智能)