How to do it...

In the following code, we will perform instance segmentation to detect a car within an image:

  1. Download and import files from https://github.com/divamgupta/image-segmentation-keras, 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 masks into arrays, as follows:
import cv2from scipy import ndimagex = []y = []for i in range(len(all_img_paths)):  img = cv2.imread(all_img_paths[i]) img = cv2.resize(img,(224,224)) ...

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.