After making the dataset ready and using ‘tf.keras.models.Sequential’ to create a model, the kernel dies and message appears ‘The kernel appears to have died. It will restart automatically.’
Can someone help me with this.
Hi @Dhanashri_Parate, Welcome to TensorFlow Forum!
Could you provide details about your OS and version of Tensorflow you are using? If possible please provide the standalone code to reproduce the issue. Thank You.
OS details : 1) Edition: Windows 11 Pro 2) OS build: 22621.1848
Version of Tensorflow: 2.10.0
As soon as visualization of image is done the kernel dies
Code :
DNN
from keras.models import Sequential
from keras.layers import Activation, Dense
from keras import optimizers
from keras.layers import Flatten
import tensorflow as tf
from keras.layers import Convolution2D, Dropout, Dense, Flatten, BatchNormalization, MaxPooling2D, RandomFlip, RandomRotation, RandomZoom, Rescaling, Conv2D, AveragePooling2D, GlobalAveragePooling2D
from tensorflow.keras.optimizers import Adam
num_classes = 2
model = tf.keras.models.Sequential([
RandomFlip(“horizontal_and_vertical”, input_shape=(224, 224, 3)),
RandomRotation(0.3),
RandomZoom(0.2),
tf.keras.layers.RandomContrast(0.3),
tf.keras.layers.RandomBrightness(0.3),
Conv2D(16, 3, activation=‘relu’,input_shape=(224, 224, 3)),
AveragePooling2D(),
BatchNormalization(),
Conv2D(32, 3, activation=‘relu’),
MaxPooling2D(),
BatchNormalization(),
Dropout(0.1),
Conv2D(64, 3, activation=‘relu’),
BatchNormalization(),
Flatten(),
Dense(128, activation=‘relu’),
BatchNormalization(),
Dropout(0.1),
Dense(64, activation=‘relu’),
BatchNormalization(),
Dense(64, activation=‘relu’),
Dense(num_classes, name=“outputs”, activation = ‘sigmoid’)
])
Libraries to display graphs
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
Libraries for file operations
import os
import cv2
import numpy as np
img = cv2.imread(‘C:/DSC_0068.jpg’)
resized_image = cv2.resize(img, (224, 224))
resized_image = resized_image.astype(‘float32’)
resized_image = resized_image / 255.
X_train = np.array(resized_image)
Visualize resized training data
image = X_train
plt.imshow(image)
Hi @Dhanashri_Parate, I have Visualized the image in windows 11 with Tensorflow 2.10 in jupyter notebook and did not face any error. Thank You.
Hello @Kiran_Sai_Ramineni , can you please suggest if I could check anything else from my end to solve this issue.
Hi @Dhanashri_Parate, Could you please try to create a new environment and install cv2 using the below commands
- conda create --name tf python=3.9
- pip install --upgrade pip
- pip install tensorflow==2.10
- pip install opencv-python
and let us know if you are facing the error or not. Thank You
This is what worked for me:
conda create –n tf python==3.11
conda activate tf
pip install tensorflow==2.15
conda install ipykernel
python -m ipykernel install --user --name tf --display-name "Python 3.11 TF“
jupyter notebook
If error when opening jupyter notebook **pip install --force-reinstall charset-normalizer==3.1.0
Now it works and I can perfectly run CNN.
It could be a resource issue. Try restarting the kernel and reducing batch size or image dimensions.