Semantic segmentation in code is performed as follows (The code file is available as Semantic_segmentation.ipynb in GitHub):
- 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'))
- 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] ...