简体   繁体   中英

Jupyter kernel dies while running this neural networks code


import numpy as np

import cv2

import os

import matplotlib.pyplot as plt

from tensorflow.keras.preprocessing.image import ImageDataGenerator

from tensorflow.keras.preprocessing import image

from tensorflow.keras.optimizers import RMSprop

img = image.load_img("image_location_here")

train = ImageDataGenerator(rescale=1/255)

validation = ImageDataGenerator(rescale=1/255)

train_dataset = train.flow_from_directory('image_location_here', target_size = (50,50),  batch_size = 3,
  class_mode = 'binary')

validation_dataset = train.flow_from_directory('image_location_here', target_size = (50,50),batch_size = 3,
class_mode = 'binary')     
                         
train_dataset.class_indices

train_dataset.classes

model = tf.keras.models.Sequential

tf.keras.layers.Conv2D(16,(3,3),activation = 'relu', input_shape = (50,50,3))` `tf.keras.layers.MaxPool2D(2,2)

tf.keras.layers.Conv2D(32,(3,3),activation = 'relu'),tf.keras.layers.MaxPool2D(2,2)

tf.keras.layers.Conv2D(64,(3,3),activation = 'relu')

tf.keras.layers.MaxPool2D(2,2)

tf.keras.layers.Flatten()

tf.keras.layers.Dense(128,activation = 'relu')

tf.keras.layers.Dense(1, activation = 'sigmoid')

The code above runs fine, but when I run the line given below the kernel dies.

model().compile(loss = 'binary_crossentropy', optimizer = 'adam', metrices = ['accuracy'])

I have updated anaconda to the latest version, restarted it few times still the kernel dies on this specific line.

sorry for the poor editing of the lines

I recently had a similar issue. The issue is being caused by CUDA/cudNN, probably because you are using an incompatible version with Tensorflow. There are two solutions for the same:

  1. Uninstall CUDA and reinstall Tensorflow library
  2. Uninstall CUDA and setup the compatible CUDA/cudNN version ( Check https://tensorflow.org/install/source_windows for the version you need for your tensorflow version)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM