Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kernel needs to restart
#1
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/202...esolution/

Any help appreciated. Thanks in advance.

Respectfully,

ErnestTBass
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Setting up new Python kernel for JupyterLab Desktop on M1 Mac daler6 0 1,263 Jun-20-2022, 03:45 AM
Last Post: daler6
  Jupyter kernel restarts russellm10 0 1,488 Sep-14-2021, 04:24 AM
Last Post: russellm10
  Problem: Restart kernel onPydev console when trying to install a python package poppy2020 1 7,707 Nov-25-2020, 06:13 PM
Last Post: Larz60+
  How a Mac OS software can restart itself with admin permission in Python 3.7? Formationgrowthhacking 0 1,779 Sep-03-2020, 05:29 PM
Last Post: Formationgrowthhacking
  Using a button to kill and restart a script duckredbeard 3 3,316 Sep-01-2020, 12:53 AM
Last Post: duckredbeard
  Hotkey to restart code? DannyB 1 2,755 May-20-2020, 02:52 AM
Last Post: michael1789
  Cannot install R kernel or R essentials ErnestTBass 4 4,453 May-01-2020, 12:28 AM
Last Post: Larz60+
  How to restart Python after input change ozstar 3 2,384 Apr-29-2020, 03:16 AM
Last Post: ozstar
  Restart Error when using code from lesson book Kathleen57 2 2,282 Mar-13-2020, 09:18 PM
Last Post: Kathleen57
  Iterating kernel through image for filtering davlovsky 0 3,505 Sep-29-2019, 02:45 PM
Last Post: davlovsky

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020