Hi,
Thanks for your response!
--Which OS version and version of the MacBook Air (Intel or M1) are you running on?
MacBook Air - 13" (M1)
--Which versions of the Jupyter packages and Tensorflow packages are you using?
I've downloaded Anaconda from link available online https://www.anaconda.com/products/individual
It has Jupyter 6.4.5 in it.
It was working fine until Deep - ANN. The moment I started coding for CNN it returned error kernel died. I did not change anything. So it quite strange what happened. Hopeful of getting it fixed thrpugh this thread :-)
Same for Tensorflow as well https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/
--Did you follow the instructions at https://developer.apple.com/metal/tensorflow-plugin/%C2%A0when installing?
No, sorry. I wasn't familiar with this resource. I m not able to follow this resource. could you explain & if this is necessary after having above steps doen and they been working fine earlier
--Can you provide an example script that causes the crash for you so we can try to reproduce this issue?
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sb
#import os
#os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
#os.environ["CUDA_VISIBLE_DEVICES"]="0"
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D,MaxPooling2D,Flatten,Dense
from tensorflow.keras.preprocessing import image
flower_classifier=Sequential()
flower_classifier.add(Conv2D(16,(3,3),input_shape=(128,128,3),activation='relu'))
flower_classifier.add(MaxPooling2D(pool_size=(2,2)))
flower_classifier.add(Conv2D(32,(3,3),activation='relu'))
flower_classifier.add(MaxPooling2D(pool_size=(2,2)))
flower_classifier.add(Flatten())
flower_classifier.add(Dense(units=128,activation='relu'))
flower_classifier.add(Dense(units=5,activation='softmax'))
flower_classifier.summary()
Model: "sequential"
conv2d (Conv2D) (None, 126, 126, 16) 448
max_pooling2d (MaxPooling2D (None, 63, 63, 16) 0
)
conv2d_1 (Conv2D) (None, 61, 61, 32) 4640
max_pooling2d_1 (MaxPooling (None, 30, 30, 32) 0
2D)
flatten (Flatten) (None, 28800) 0
dense (Dense) (None, 128) 3686528
dense_1 (Dense) (None, 5) 645
=================================================================
Total params: 3,692,261
Trainable params: 3,692,261
Non-trainable params: 0
from tensorflow.keras.preprocessing.image import ImageDataGenerator
train_datagen=ImageDataGenerator(rescale=1/255.,
rotation_range=45,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='reflect')
test_datagen=ImageDataGenerator(rescale=1/255.)
train_datagen
<keras.preprocessing.image.ImageDataGenerator at 0x1b013414c18>
train_set=train_datagen.flow_from_directory('C:\Users\tksen\Desktop\DL\Datasets\flower_photos\Training',
target_size=(128,128),
batch_size=128,
class_mode='categorical')
test_set=test_datagen.flow_from_directory('C:\Users\tksen\Desktop\DL\Datasets\flower_photos\Testing',
target_size=(128,128),
batch_size=128,
class_mode='categorical')
flower_classifier.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])
flower_classifier.fit(train_set,
steps_per_epoch=2736//128,
epochs=5,
validation_data=test_set,
validation_steps=934//128)
type(test_img)
test_img1=test_img1/255.
test_img1.shape
test_img2=np.expand_dims(test_img1,axis=0)
test_img2.shape
ypred=flower_classifier.predict(test_img2)
ypred.round(2)
print(train_set.class_indices)
test_img=image.load_img('C:\Users\tksen\Desktop\DL\Datasets\flower_photos\example\1.jpg',target_size=(128,128))
test_img1=image.img_to_array(test_img)
test_img1=test_img1/255.
test_img2=np.expand_dims(test_img1,axis=0)
ypred=flower_classifier.predict(test_img2)
print(train_set.class_indices)
print('The test image class is :',ypred.argmax())
class_name=train_set.class_indices
pos=np.array(list(class_name.values()))==ypred.argmax()
name=np.array(list(class_name.keys()))
print('The Predicted class name is:')
print(name[pos][0])
test_img
flower_classifier.save('flower_classifier.h5')
Please let me know if I can give you any other details