In the following code, we will perform instance segmentation to detect a car within an image:
- 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'))
- 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)) ...