title: Failed precondition: Python interpreter state is not initialized. The process may be terminated
body: <p>I am trying train my images. This data's size is 50.000 images.</p>
  <p>My images properities are:</p>
  <p><a href="https://i.stack.imgur.com/bkU75.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bkU75.png" alt="enter image description here" /></a></p>
  <p>If i should change my images properities, how can i do that?</p>
  <p>This is my first image classifier work so there can be a lot of mistake. Please understand.</p>
  <p>Can you help improve my code?</p>
  <p><strong>This is my code</strong></p>
  <pre><code>from tensorflow.keras.models import Sequential
  from tensorflow.keras.layers import Conv2D,MaxPooling2D,Activation,Dropout,Flatten,Dense
  from tensorflow.keras.preprocessing.image import ImageDataGenerator,img_to_array,load_img
  import matplotlib.pyplot as plt
  from glob import glob
  from PIL import Image
  import os
  
  
  import numpy as np
  
  train_path=&quot;Düzgün2/&quot;
  
  images = [train_path for train_path in os.listdir() if train_path.endswith(('jpeg', 'png', 'jpg'))]
  for x in images:
      img = Image.open(x)
      img.thumbnail((600,600))
      img.save(&quot;resized_&quot;+x, optimize=True, quality=40)
  test_path=&quot;Test/&quot;
  data=load_img(train_path + &quot;Basler_acA1440-220um__40052667__20201123_114618747_7932_result.jpg&quot;)
  x=np.asarray(data)
  
  plt.imshow(data)
  plt.axis(&quot;off&quot;)
  plt.show()
  
  
  print(x.shape)
  className=glob(train_path + &quot;/*&quot;)
  print(className)
  numberOfClass=len(className)
  print(&quot;NumberOfClass:&quot;,numberOfClass)
  
  #CNN model
  
  model=Sequential()
  model.add(Conv2D(32,(3,3),input_shape=(224,224,3)))#xshape burada gelen resimin pixseli 3 ise rgb yi tesmil ediyor so that senin çivi resimlerine göre ayarla
  model.add(Activation(&quot;relu&quot;))
  model.add(MaxPooling2D())
  model.add(Conv2D(32,(3,3)))#xshape burada gelen resimin pixseli 3 ise rgb yi tesmil ediyor so that senin çivi resimlerine göre ayarla&quot;&quot;&quot;
  model.add(Activation(&quot;relu&quot;))
  model.add(MaxPooling2D())
  
  model.add(Flatten())
  model.add(Dense(1024))#1024 nörondan oluşuyor
  model.add(Activation(&quot;relu&quot;))
  model.add(Dropout(0.5))
  model.add(Dense(numberOfClass))#output
  model.add(Activation(&quot;softmax&quot;))
  
  model.compile(loss=&quot;categorical_crossentropy&quot;,optimizer=&quot;rmsprop&quot;,metrics=[&quot;accuracy&quot;])
  
  batch_size=32# her iterasyonda 32 resmi kullan
  
  #data generator
  
  train_datagen=ImageDataGenerator(rescale=1./255,shear_range=0.3,
                     horizontal_flip=True,zoom_range=0.3)#rgb 0-255 0-1 ile bir arası değer alıyoruz,shear sağa sola yatırma
  test_datagen=(ImageDataGenerator(rescale=1./255))
  
  train_generator=train_datagen.flow_from_directory(train_path,
                                                   target_size=x.shape[:2],batch_size=batch_size,color_mode=&quot;rgb&quot;,
                                                   class_mode=&quot;categorical&quot;)
  test_generator=test_datagen.flow_from_directory(test_path,
                                                   target_size=x.shape[:2],batch_size=batch_size,color_mode=&quot;rgb&quot;,
                                                   class_mode=&quot;categorical&quot;)
  
  model.fit_generator(generator=train_generator,steps_per_epoch=1600 // batch_size,epochs=100,validation_data=test_generator,
                          validation_steps=800 // batch_size)
     
  </code></pre>
  <p><strong>This my output:</strong></p>
  <pre><code>NumberOfClass: 11376
  2020-12-15 14:10:26.449262: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
  2020-12-15 14:10:27.159243: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
  pciBusID: 0000:01:00.0 name: GeForce GTX 1660 Ti computeCapability: 7.5
  coreClock: 1.59GHz coreCount: 24 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 268.26GiB/s
  2020-12-15 14:10:27.159530: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
  2020-12-15 14:10:27.221768: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
  2020-12-15 14:10:27.269324: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
  2020-12-15 14:10:27.275602: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
  2020-12-15 14:10:27.301737: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
  2020-12-15 14:10:27.314461: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
  2020-12-15 14:10:27.407152: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
  2020-12-15 14:10:27.407410: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
  2020-12-15 14:10:27.407830: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
  2020-12-15 14:10:27.416924: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x193e2fdee00 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
  2020-12-15 14:10:27.417440: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
  2020-12-15 14:10:27.417880: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
  pciBusID: 0000:01:00.0 name: GeForce GTX 1660 Ti computeCapability: 7.5
  coreClock: 1.59GHz coreCount: 24 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 268.26GiB/s
  2020-12-15 14:10:27.418242: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
  2020-12-15 14:10:27.418413: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
  2020-12-15 14:10:27.418586: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
  2020-12-15 14:10:27.418754: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
  2020-12-15 14:10:27.418922: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
  2020-12-15 14:10:27.419095: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
  2020-12-15 14:10:27.419268: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
  2020-12-15 14:10:27.419477: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
  2020-12-15 14:10:28.461954: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
  2020-12-15 14:10:28.462106: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
  2020-12-15 14:10:28.462194: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
  2020-12-15 14:10:28.462442: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4750 MB memory) -&gt; physical GPU (device: 0, name: GeForce GTX 1660 Ti, pci bus id: 0000:01:00.0, compute capability: 7.5)
  2020-12-15 14:10:28.465422: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1942c7ee0b0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
  2020-12-15 14:10:28.465660: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1660 Ti, Compute Capability 7.5
  Found 0 images belonging to 0 classes.
  Found 0 images belonging to 0 classes.
  WARNING:tensorflow:From C:/Users/tatu/PycharmProjects/pythonProject4/main.py:70: Model.fit_generator (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
  Instructions for updating:
  Please use Model.fit, which supports generators.
  Epoch 1/100
  2020-12-15 14:10:30.182839: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
  Traceback (most recent call last):
    File &quot;C:/Users/tatu/PycharmProjects/pythonProject4/main.py&quot;, line 70, in &lt;module&gt;
      validation_steps=800 // batch_size)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\util\deprecation.py&quot;, line 324, in new_func
      return func(*args, **kwargs)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\keras\engine\training.py&quot;, line 1479, in fit_generator
      initial_epoch=initial_epoch)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\keras\engine\training.py&quot;, line 66, in _method_wrapper
      return method(self, *args, **kwargs)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\keras\engine\training.py&quot;, line 848, in fit
      tmp_logs = train_function(iterator)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\eager\def_function.py&quot;, line 580, in __call__
      result = self._call(*args, **kwds)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\eager\def_function.py&quot;, line 644, in _call
      return self._stateless_fn(*args, **kwds)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\eager\function.py&quot;, line 2420, in __call__
      return graph_function._filtered_call(args, kwargs)  # pylint: disable=protected-access
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\eager\function.py&quot;, line 1665, in _filtered_call
      self.captured_inputs)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\eager\function.py&quot;, line 1746, in _call_flat
      ctx, args, cancellation_manager=cancellation_manager))
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\eager\function.py&quot;, line 598, in call
      ctx=ctx)
    File &quot;C:\Users\tatu\miniconda3\envs\tensorfloww\lib\site-packages\tensorflow\python\eager\execute.py&quot;, line 60, in quick_execute
      inputs, attrs, num_outputs)
  tensorflow.python.framework.errors_impl.InvalidArgumentError:  Reduction axis -1 is empty in shape [0,0]
       [[node ArgMax (defined at /Users/tatu/PycharmProjects/pythonProject4/main.py:70) ]] [Op:__inference_train_function_921]
  
  Function call stack:
  train_function
  
  2020-12-15 14:10:30.637723: W tensorflow/core/kernels/data/generator_dataset_op.cc:103] Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.
       [[{{node PyFunc}}]]
  
  Process finished with exit code 1
  
  </code></pre>
  <p><strong>This is my error</strong></p>
  <pre><code>Function call stack:
  train_function
  
  2020-12-15 14:10:30.637723: W tensorflow/core/kernels/data/generator_dataset_op.cc:103] Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.
       [[{{node PyFunc}}]]
  </code></pre>