How to do it...

Semantic segmentation in code is performed as follows (The code file is available as Semantic_segmentation.ipynb in GitHub):

  1. Download the dataset, as follows:
!wget https://www.dropbox.com/s/0pigmmmynbf9xwq/dataset1.zip!unzip dataset1.zipdir_data = "/content/dataset1"dir_seg = dir_data + "/annotations_prepped_train/"dir_img = dir_data + "/images_prepped_train/"import glob, osall_img_paths = glob.glob(os.path.join(dir_img, '*.png'))all_mask_paths = glob.glob(os.path.join(dir_seg, '*.png'))
  1. Read the images and their corresponding labels into separate lists, as follows:
import cv2from scipy import ndimagefor i in range(len(all_img_paths)):     img = cv2.imread(all_img_paths[i])     img = cv2.resize(img,(224,224)) mask_path = dir_seg+all_img_paths[i].split('/')[4] ...

Get Neural Networks with Keras Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.