When using tensorflow.keras, this error is often reported during model training:
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}}]]
According to my own experience, there are several reasons for this errory:
1. The input image_size and input_shape does not match or is not defined when the model is built. Note that the input_shape must be defined when defining the first layer of the convolutional layer, e.g.
model = keras.models.Sequential([
# Input image [None,224,224,3]
# Convolution layer 1: 32 5*5*3 filters, step size set to 1, fill set to same
# Output [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. There is also train_generator and validate_generator related parameters must be consistent, such as batch_size, target_size, class_mode, etc.
3. The configuration limit itself, try to change the batch_size to a smaller size, or even to 1
4. The last program did not finish completely, finish all python programs to see.
Read More:
- [Solved] Error: Please select a valid Python interpreter
- [Solved] TensorFlow Error: GetNext() failed because the iterator has not been initialized
- Python environment error, bad interpreter: there is no file or directory
- [Solved] VScode Configurate Python Interpreter Error: D:\Pros\virtuals\venvs\Scripts\Activate.ps1 cannot be loaded
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- [Solved] opencv-python: recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all‘ failed
- Python Error: pip install mysql-connector-python failed
- [Solved] Python Keras Error: AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘
- [Solved] NPM install Error: check python checking for Python executable python2 in the PATH
- The lenet model trained by Python failed to predict its own handwritten pictures
- [Solved] Python Error: tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.
- [Solved] R Error: Python module tensorflow.keras was not found.
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- Importerror: DLL load failed: unable to find the specified module in Python
- How to Solve Python Importerror: DLL load failed: unable to find the specified program using tensorflow
- Jupyter notebook Failed to Switch to the Virual Environment: DLL load failed python.exe could not find the entry
- [Solved] PySide2 Failed to Create a Graphical Python Program
- [Solved] Jupyter Notebook Error: SparkException: Python worker failed to connect back
- Python: Panda scramble data
- [Solved] Failed to obtain/convert traceback after Python Tkinter packages exe