By dhazra
from keras.preprocessing import image
from tqdm import tqdm
def path_to_tensor(img_path): # loads RGB image as PIL.Image.Image type img = image.load_img(img_path, target_size=(224, 224)) # convert PIL.Image.Image type to 3D tensor with shape (224, 224, 3) x = image.img_to_array(img) # convert 3D tensor to 4D tensor with shape (1, 224, 224, 3) and return 4D tensor return np.expand_dims(x, axis=0)
def paths_to_tensor(img_paths): list_of_tensors = [path_to_tensor(img_path) for img_path in tqdm(img_paths)] return np.vstack(list_of_tensors)```
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
train_tensors = paths_to_tensor(train_files).astype(‘float32’)/255 valid_tensors = paths_to_tensor(valid_files).astype(‘float32’)/255 test_tensors = paths_to_tensor(test_files).astype(‘float32’)/255
```The error mesg. - "Kernel Restarting
The kernel appears to have died. It will restart automatically."
From Jupyter notebook log please find below the snapshot and see how frequently the kernel is getting stopped in between -
**[I 06:53:09.792 NotebookApp] Kernel started: 1a6cc3fd-6f08-493e-9276-b6c79b186ec0**
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
[I 06:55:10.347 NotebookApp] Saving file at /dog_app.ipynb
**[I 06:55:42.814 NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel 1a6cc3fd-6f08-493e-9276-b6c79b186ec0 restarted**
[I 06:57:10.327 NotebookApp] Saving file at /dog_app.ipynb
[I 06:59:12.226 NotebookApp] Saving file at /dog_app.ipynb
**[I 06:59:57.833 NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel 1a6cc3fd-6f08-493e-9276-b6c79b186ec0 restarted**
[I 07:01:10.341 NotebookApp] Saving file at /dog_app.ipynb
**[I 07:02:33.857 NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel 1a6cc3fd-6f08-493e-9276-b6c79b186ec0 restarted**
[I 07:03:10.331 NotebookApp] Saving file at /dog_app.ipynb
[I 07:05:10.009 NotebookApp] Saving file at /dog_app.ipynb
**[I 07:06:03.874 NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel 1a6cc3fd-6f08-493e-9276-b6c79b186ec0 restarted**
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello there,
I will highly recommend examining the resource usage on the droplet. In case of a basic droplet it can simply run out of resources and causing the problems that you report.
Adding SWAP space on the droplet is a must in order to have better performance. Make sure to check the system logs as this can provide additional information on the kernel issues.
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04
You can check this article on how to monitor the droplet resource usage
https://www.digitalocean.com/community/tutorials/how-to-monitor-cpu-use-on-digitalocean-droplets
Regards
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.