![]() |
Kernel needs to restart - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Kernel needs to restart (/thread-26602.html) |
Kernel needs to restart - ErnestTBass - May-06-2020 import glob #wget http://vis-www.cs.umass.edu/lfw/lfw.tgz #tar -xvzf lfw.tgz face_images = glob.glob('lfw/**/*.jpg') # In[2]: import cv2 import numpy as np import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from tensorflow.keras import Model, Input, regularizers from tensorflow.keras.layers import Dense, Conv2D, MaxPool2D, UpSampling2D from tensorflow.keras.callbacks import EarlyStopping from keras.preprocessing import image import PIL from tqdm import tqdm import warnings; warnings.filterwarnings('ignore') # In[3]: all_images = [] for i in tqdm(face_images): img = image.load_img(i, target_size=(80,80,3)) img = image.img_to_array(img) img = img/255. all_images.append(img) # In[ ]: all_images = np.array(all_images) # split data into train and validation data train_x, val_x = train_test_split(all_images, random_state=32, test_size=0.1) # In[ ]: # function to reduce image resolution while keeping the image size constant def pixalate_image(image, scale_percent = 40): width = int(image.shape[1] * scale_percent / 100) height = int(image.shape[0] * scale_percent / 100) dim = (width, height) small_image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA) # scale back to original size width = int(small_image.shape[1] * 100 / scale_percent) height = int(small_image.shape[0] * 100 / scale_percent) dim = (width, height) low_res_image = cv2.resize(small_image, dim, interpolation = cv2.INTER_AREA) return low_res_image # In[ ]: # get low resolution images for the training set train_x_px = [] for i in range(train_x.shape[0]): temp = pixalate_image(train_x[i,:,:,:]) train_x_px.append(temp) train_x_px = np.array(train_x_px) # get low resolution images for the validation set val_x_px = [] for i in range(val_x.shape[0]): temp = pixalate_image(val_x[i,:,:,:]) val_x_px.append(temp) val_x_px = np.array(val_x_px) # In[ ]: # get low resolution images for the training set train_x_px = [] for i in range(train_x.shape[0]): temp = pixalate_image(train_x[i,:,:,:]) train_x_px.append(temp) train_x_px = np.array(train_x_px) # get low resolution images for the validation set val_x_px = [] for i in range(val_x.shape[0]): temp = pixalate_image(val_x[i,:,:,:]) val_x_px.append(temp) val_x_px = np.array(val_x_px) # In[ ]: Input_img = Input(shape=(80, 80, 3)) #encoding architecture x1 = Conv2D(256, (3, 3), activation='relu', padding='same')(Input_img) x2 = Conv2D(128, (3, 3), activation='relu', padding='same')(x1) x2 = MaxPool2D( (2, 2))(x2) encoded = Conv2D(64, (3, 3), activation='relu', padding='same')(x2) # decoding architecture x3 = Conv2D(64, (3, 3), activation='relu', padding='same')(encoded) x3 = UpSampling2D((2, 2))(x3) x2 = Conv2D(128, (3, 3), activation='relu', padding='same')(x3) x1 = Conv2D(256, (3, 3), activation='relu', padding='same')(x2) decoded = Conv2D(3, (3, 3), padding='same')(x1) autoencoder = Model(Input_img, decoded) autoencoder.compile(optimizer='adam', loss='mse')The code shown above when run in a jupyter notebook stops with a kernel needs to restart message a screenshot that I have attached. I am not sure why, it seems to run and and stall citing certain tensorflow libraries libraries are missing when i run in the command line of jupyter notebook. I installed tensorflow even though my laptop only has a Radeon processor. I know that current tensorflow defaults to the cpu version if the software does not detect an NVIDA GPU. Again, why does this software not run to the end. It is not my coding it is from a exercise shown here in this link: https://www.analyticsvidhya.com/blog/2020/02/what-is-autoencoder-enhance-image-resolution/ Any help appreciated. Thanks in advance. Respectfully, ErnestTBass |