├── README.md ├── results ├── 0000007.png ├── 0000008.png ├── 0000012.png ├── 0000023.png ├── 0000026.png ├── 0000033.png ├── 0000044.png ├── 0000047.png ├── 0000059.png ├── 0000063.png ├── 0000068.png ├── 0000071.png ├── 0000075.png ├── 0000079.png ├── 0000082.png ├── 0000086.png ├── 0000087.png ├── 0000089.png ├── 0000107.png ├── 0000116.png ├── 0000126.png ├── 0000138.png ├── 0000147.png ├── 0000149.png ├── 0000150.png ├── 0000156.png ├── 0000157.png ├── 0000160.png ├── 0000163.png ├── 0000166.png ├── 0000172.png ├── 0000176.png ├── 0000180.png ├── 0000183.png ├── 0000186.png ├── 0000190.png ├── 0000193.png ├── 0000199.png ├── 0000201.png ├── 0000202.png ├── 0000212.png ├── 0000226.png ├── 0000235.png ├── 0000250.png ├── 0000251.png ├── 0000254.png ├── 0000259.png ├── 0000261.png ├── 0000282.png ├── 0000289.png ├── 0000301.png ├── 0000302.png ├── 0000307.png ├── 0000335.png ├── 0000355.png ├── 0000363.png ├── 0000370.png ├── 0000377.png ├── 0000387.png ├── 0000392.png ├── 0000401.png ├── 0000407.png ├── 0000415.png └── 0000421.png ├── test.py ├── train.py └── unet.py /README.md: -------------------------------------------------------------------------------- 1 | # Multiclass Segmentation on Crowd Instance-level Human Parsing (CHIP) Dataset using UNET 2 | This repository contains the code for the Multiclass Segmentation using the UNET architecture on the Crowd Instance-level Human Parsing (CHIP) Dataset. The complete code is written using the TensorFlow frameowork. 3 | 4 | ## Dataset 5 | Download the dataset: [Crowd Instance-level Human Parsing (CHIP)](https://drive.google.com/uc?id=1B9A9UCJYMwTL4oBEo4RZfbMZMaZhKJaz) 6 | 7 | ## Results 8 | The sequence of the images are: 1) Input Image 2) Ground Truth Mask and 3) Prediction Mask 9 | ![](results/0000026.png) 10 | ![](results/0000044.png) 11 | ![](results/0000047.png) 12 | ![](results/0000415.png) 13 | 14 | ## Contact: 15 | For more follow me on: 16 | 17 | - YouTube 18 | - Facebook 19 | - Twitter 20 | - Instagram 21 | - Telegram 22 | -------------------------------------------------------------------------------- /results/0000007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000007.png -------------------------------------------------------------------------------- /results/0000008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000008.png -------------------------------------------------------------------------------- /results/0000012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000012.png -------------------------------------------------------------------------------- /results/0000023.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000023.png -------------------------------------------------------------------------------- /results/0000026.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000026.png -------------------------------------------------------------------------------- /results/0000033.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000033.png -------------------------------------------------------------------------------- /results/0000044.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000044.png -------------------------------------------------------------------------------- /results/0000047.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000047.png -------------------------------------------------------------------------------- /results/0000059.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000059.png -------------------------------------------------------------------------------- /results/0000063.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000063.png -------------------------------------------------------------------------------- /results/0000068.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000068.png -------------------------------------------------------------------------------- /results/0000071.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000071.png -------------------------------------------------------------------------------- /results/0000075.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000075.png -------------------------------------------------------------------------------- /results/0000079.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000079.png -------------------------------------------------------------------------------- /results/0000082.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000082.png -------------------------------------------------------------------------------- /results/0000086.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000086.png -------------------------------------------------------------------------------- /results/0000087.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000087.png -------------------------------------------------------------------------------- /results/0000089.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000089.png -------------------------------------------------------------------------------- /results/0000107.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000107.png -------------------------------------------------------------------------------- /results/0000116.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000116.png -------------------------------------------------------------------------------- /results/0000126.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000126.png -------------------------------------------------------------------------------- /results/0000138.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000138.png -------------------------------------------------------------------------------- /results/0000147.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000147.png -------------------------------------------------------------------------------- /results/0000149.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000149.png -------------------------------------------------------------------------------- /results/0000150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000150.png -------------------------------------------------------------------------------- /results/0000156.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000156.png -------------------------------------------------------------------------------- /results/0000157.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000157.png -------------------------------------------------------------------------------- /results/0000160.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000160.png -------------------------------------------------------------------------------- /results/0000163.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000163.png -------------------------------------------------------------------------------- /results/0000166.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000166.png -------------------------------------------------------------------------------- /results/0000172.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000172.png -------------------------------------------------------------------------------- /results/0000176.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000176.png -------------------------------------------------------------------------------- /results/0000180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000180.png -------------------------------------------------------------------------------- /results/0000183.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000183.png -------------------------------------------------------------------------------- /results/0000186.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000186.png -------------------------------------------------------------------------------- /results/0000190.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000190.png -------------------------------------------------------------------------------- /results/0000193.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000193.png -------------------------------------------------------------------------------- /results/0000199.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000199.png -------------------------------------------------------------------------------- /results/0000201.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000201.png -------------------------------------------------------------------------------- /results/0000202.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000202.png -------------------------------------------------------------------------------- /results/0000212.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000212.png -------------------------------------------------------------------------------- /results/0000226.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000226.png -------------------------------------------------------------------------------- /results/0000235.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000235.png -------------------------------------------------------------------------------- /results/0000250.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000250.png -------------------------------------------------------------------------------- /results/0000251.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000251.png -------------------------------------------------------------------------------- /results/0000254.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000254.png -------------------------------------------------------------------------------- /results/0000259.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000259.png -------------------------------------------------------------------------------- /results/0000261.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000261.png -------------------------------------------------------------------------------- /results/0000282.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000282.png -------------------------------------------------------------------------------- /results/0000289.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000289.png -------------------------------------------------------------------------------- /results/0000301.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000301.png -------------------------------------------------------------------------------- /results/0000302.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000302.png -------------------------------------------------------------------------------- /results/0000307.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000307.png -------------------------------------------------------------------------------- /results/0000335.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000335.png -------------------------------------------------------------------------------- /results/0000355.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000355.png -------------------------------------------------------------------------------- /results/0000363.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000363.png -------------------------------------------------------------------------------- /results/0000370.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000370.png -------------------------------------------------------------------------------- /results/0000377.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000377.png -------------------------------------------------------------------------------- /results/0000387.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000387.png -------------------------------------------------------------------------------- /results/0000392.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000392.png -------------------------------------------------------------------------------- /results/0000401.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000401.png -------------------------------------------------------------------------------- /results/0000407.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000407.png -------------------------------------------------------------------------------- /results/0000415.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000415.png -------------------------------------------------------------------------------- /results/0000421.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilroxtomar/Multiclass-Segmentation-on-Crowd-Instance-level-Human-Parsing-CHIP-Dataset-using-UNET/253b44a89073592cd0cbe6970603786f5646ea5c/results/0000421.png -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 3 | 4 | import numpy as np 5 | import cv2 6 | import pandas as pd 7 | from glob import glob 8 | from tqdm import tqdm 9 | import tensorflow as tf 10 | from sklearn.metrics import accuracy_score, f1_score, jaccard_score, precision_score, recall_score 11 | from train import load_dataset, create_dir, get_colormap 12 | 13 | """ Global parameters """ 14 | global IMG_H 15 | global IMG_W 16 | global NUM_CLASSES 17 | global CLASSES 18 | global COLORMAP 19 | 20 | def grayscale_to_rgb(mask, classes, colormap): 21 | h, w, _ = mask.shape 22 | mask = mask.astype(np.int32) 23 | output = [] 24 | 25 | for i, pixel in enumerate(mask.flatten()): 26 | output.append(colormap[pixel]) 27 | 28 | output = np.reshape(output, (h, w, 3)) 29 | return output 30 | 31 | def save_results(image, mask, pred, save_image_path): 32 | h, w, _ = image.shape 33 | line = np.ones((h, 10, 3)) * 255 34 | 35 | pred = np.expand_dims(pred, axis=-1) 36 | pred = grayscale_to_rgb(pred, CLASSES, COLORMAP) 37 | 38 | cat_images = np.concatenate([image, line, mask, line, pred], axis=1) 39 | cv2.imwrite(save_image_path, cat_images) 40 | 41 | if __name__ == "__main__": 42 | """ Seeding """ 43 | np.random.seed(42) 44 | tf.random.set_seed(42) 45 | 46 | """ Directory for storing files """ 47 | create_dir("results") 48 | 49 | """ Hyperparameters """ 50 | IMG_H = 320 51 | IMG_W = 416 52 | NUM_CLASSES = 20 53 | dataset_path = "/media/nikhil/Seagate Backup Plus Drive/ML_DATASET/instance-level-human-parsing/instance-level_human_parsing/instance-level_human_parsing" 54 | model_path = os.path.join("files", "model.h5") 55 | 56 | """ Colormap """ 57 | CLASSES, COLORMAP = get_colormap(dataset_path) 58 | 59 | """ Model """ 60 | model = tf.keras.models.load_model(model_path) 61 | 62 | """ Load the dataset """ 63 | (train_x, train_y), (valid_x, valid_y), (test_x, test_y) = load_dataset(dataset_path) 64 | print(f"Train: {len(train_x)}/{len(train_y)} - Valid: {len(valid_x)}/{len(valid_y)} - Test: {len(test_x)}/{len(test_y)}") 65 | print("") 66 | 67 | """ Evaluation and Prediction """ 68 | SCORE = [] 69 | for x, y in tqdm(zip(test_x, test_y), total=len(test_x)): 70 | """ Extract the name """ 71 | name = x.split("/")[-1].split(".")[0] 72 | 73 | """ Reading the image """ 74 | image = cv2.imread(x, cv2.IMREAD_COLOR) 75 | image = cv2.resize(image, (IMG_W, IMG_H)) 76 | image_x = image 77 | image = image/255.0 78 | image = np.expand_dims(image, axis=0) 79 | 80 | """ Reading the mask """ 81 | mask = cv2.imread(y, cv2.IMREAD_COLOR) 82 | mask = cv2.resize(mask, (IMG_W, IMG_H)) 83 | mask_x = mask 84 | onehot_mask = [] 85 | for color in COLORMAP: 86 | cmap = np.all(np.equal(mask, color), axis=-1) 87 | onehot_mask.append(cmap) 88 | onehot_mask = np.stack(onehot_mask, axis=-1) 89 | onehot_mask = np.argmax(onehot_mask, axis=-1) 90 | onehot_mask = onehot_mask.astype(np.int32) 91 | 92 | """ Prediction """ 93 | pred = model.predict(image, verbose=0)[0] 94 | pred = np.argmax(pred, axis=-1) 95 | pred = pred.astype(np.float32) 96 | 97 | """ Saving the prediction """ 98 | save_image_path = f"results/{name}.png" 99 | save_results(image_x, mask_x, pred, save_image_path) 100 | 101 | """ Flatten the array """ 102 | onehot_mask = onehot_mask.flatten() 103 | pred = pred.flatten() 104 | 105 | labels = [i for i in range(NUM_CLASSES)] 106 | 107 | """ Calculating the metrics values """ 108 | f1_value = f1_score(onehot_mask, pred, labels=labels, average=None, zero_division=0) 109 | jac_value = jaccard_score(onehot_mask, pred, labels=labels, average=None, zero_division=0) 110 | 111 | SCORE.append([f1_value, jac_value]) 112 | 113 | """ Metrics values """ 114 | score = np.array(SCORE) 115 | score = np.mean(score, axis=0) 116 | 117 | f = open("files/score.csv", "w") 118 | f.write("Class,F1,Jaccard\n") 119 | 120 | l = ["Class", "F1", "Jaccard"] 121 | print(f"{l[0]:15s} {l[1]:10s} {l[2]:10s}") 122 | print("-"*35) 123 | 124 | for i in range(score.shape[1]): 125 | class_name = CLASSES[i] 126 | f1 = score[0, i] 127 | jac = score[1, i] 128 | dstr = f"{class_name:15s}: {f1:1.5f} - {jac:1.5f}" 129 | print(dstr) 130 | f.write(f"{class_name:15s},{f1:1.5f},{jac:1.5f}\n") 131 | 132 | print("-"*35) 133 | class_mean = np.mean(score, axis=-1) 134 | class_name = "Mean" 135 | f1 = class_mean[0] 136 | jac = class_mean[1] 137 | dstr = f"{class_name:15s}: {f1:1.5f} - {jac:1.5f}" 138 | print(dstr) 139 | f.write(f"{class_name:15s},{f1:1.5f},{jac:1.5f}\n") 140 | 141 | f.close() 142 | -------------------------------------------------------------------------------- /train.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 4 | import numpy as np 5 | import pandas as pd 6 | import cv2 7 | from glob import glob 8 | import scipy.io 9 | from sklearn.model_selection import train_test_split 10 | import tensorflow as tf 11 | from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, EarlyStopping, CSVLogger 12 | from unet import build_unet 13 | 14 | """ Global parameters """ 15 | global IMG_H 16 | global IMG_W 17 | global NUM_CLASSES 18 | global CLASSES 19 | global COLORMAP 20 | 21 | """ Creating a directory """ 22 | def create_dir(path): 23 | if not os.path.exists(path): 24 | os.makedirs(path) 25 | 26 | """ Load and split the dataset """ 27 | def load_dataset(path, split=0.2): 28 | train_x = sorted(glob(os.path.join(path, "Training", "Images", "*")))[:10000] 29 | train_y = sorted(glob(os.path.join(path, "Training", "Categories", "*")))[:10000] 30 | 31 | split_size = int(split * len(train_x)) 32 | 33 | train_x, valid_x = train_test_split(train_x, test_size=split_size, random_state=42) 34 | train_y, valid_y = train_test_split(train_y, test_size=split_size, random_state=42) 35 | 36 | train_x, test_x = train_test_split(train_x, test_size=split_size, random_state=42) 37 | train_y, test_y = train_test_split(train_y, test_size=split_size, random_state=42) 38 | 39 | return (train_x, train_y), (valid_x, valid_y), (test_x, test_y) 40 | 41 | def get_colormap(path): 42 | mat_path = os.path.join(path, "human_colormap.mat") 43 | colormap = scipy.io.loadmat(mat_path)["colormap"] 44 | colormap = colormap * 256 45 | colormap = colormap.astype(np.uint8) 46 | colormap = [[c[2], c[1], c[0]] for c in colormap] 47 | 48 | classes = [ 49 | "Background", 50 | "Hat", 51 | "Hair", 52 | "Glove", 53 | "Sunglasses", 54 | "UpperClothes", 55 | "Dress", 56 | "Coat", 57 | "Socks", 58 | "Pants", 59 | "Torso-skin", 60 | "Scarf", 61 | "Skirt", 62 | "Face", 63 | "Left-arm", 64 | "Right-arm", 65 | "Left-leg", 66 | "Right-leg", 67 | "Left-shoe", 68 | "Right-shoe" 69 | ] 70 | 71 | return classes, colormap 72 | 73 | def read_image_mask(x, y): 74 | """ Reading """ 75 | x = cv2.imread(x, cv2.IMREAD_COLOR) 76 | y = cv2.imread(y, cv2.IMREAD_COLOR) 77 | assert x.shape == y.shape 78 | 79 | """ Resizing """ 80 | x = cv2.resize(x, (IMG_W, IMG_H)) 81 | y = cv2.resize(y, (IMG_W, IMG_H)) 82 | 83 | """ Image processing """ 84 | x = x / 255.0 85 | x = x.astype(np.float32) 86 | 87 | """ Mask processing """ 88 | output = [] 89 | for color in COLORMAP: 90 | cmap = np.all(np.equal(y, color), axis=-1) 91 | output.append(cmap) 92 | output = np.stack(output, axis=-1) 93 | output = output.astype(np.uint8) 94 | 95 | return x, output 96 | 97 | def preprocess(x, y): 98 | def f(x, y): 99 | x = x.decode() 100 | y = y.decode() 101 | image, mask = read_image_mask(x, y) 102 | return image, mask 103 | 104 | image, mask = tf.numpy_function(f, [x, y], [tf.float32, tf.uint8]) 105 | image.set_shape([IMG_H, IMG_W, 3]) 106 | mask.set_shape([IMG_H, IMG_W, NUM_CLASSES]) 107 | 108 | return image, mask 109 | 110 | def tf_dataset(x, y, batch=8): 111 | dataset = tf.data.Dataset.from_tensor_slices((x, y)) 112 | dataset = dataset.shuffle(buffer_size=5000) 113 | dataset = dataset.map(preprocess) 114 | dataset = dataset.batch(batch) 115 | dataset = dataset.prefetch(2) 116 | return dataset 117 | 118 | 119 | if __name__ == "__main__": 120 | """ Seeding """ 121 | np.random.seed(42) 122 | tf.random.set_seed(42) 123 | 124 | """ Directory for storing files """ 125 | create_dir("files") 126 | 127 | """ Hyperparameters """ 128 | IMG_H = 320 129 | IMG_W = 416 130 | NUM_CLASSES = 20 131 | input_shape = (IMG_H, IMG_W, 3) 132 | 133 | batch_size = 16 134 | lr = 1e-4 135 | num_epochs = 100 136 | dataset_path = "/media/nikhil/Seagate Backup Plus Drive/ML_DATASET/instance-level-human-parsing/instance-level_human_parsing/instance-level_human_parsing" 137 | 138 | model_path = os.path.join("files", "model.h5") 139 | csv_path = os.path.join("files", "data.csv") 140 | 141 | """ Loading the dataset """ 142 | (train_x, train_y), (valid_x, valid_y), (test_x, test_y) = load_dataset(dataset_path) 143 | print(f"Train: {len(train_x)}/{len(train_y)} - Valid: {len(valid_x)}/{len(valid_y)} - Test: {len(test_x)}/{len(test_x)}") 144 | print("") 145 | 146 | """ Process the colormap """ 147 | CLASSES, COLORMAP = get_colormap(dataset_path) 148 | 149 | """ Dataset Pipeline """ 150 | train_dataset = tf_dataset(train_x, train_y, batch=batch_size) 151 | valid_dataset = tf_dataset(valid_x, valid_y, batch=batch_size) 152 | 153 | """ Model """ 154 | model = build_unet(input_shape, NUM_CLASSES) 155 | # model.load_weights(model_path) 156 | model.compile( 157 | loss="categorical_crossentropy", 158 | optimizer=tf.keras.optimizers.Adam(lr) 159 | ) 160 | # model.summary() 161 | 162 | """ Training """ 163 | callbacks = [ 164 | ModelCheckpoint(model_path, verbose=1, save_best_only=True), 165 | ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=5, min_lr=1e-7, verbose=1), 166 | CSVLogger(csv_path, append=True), 167 | EarlyStopping(monitor='val_loss', patience=20, restore_best_weights=False) 168 | ] 169 | 170 | model.fit(train_dataset, 171 | validation_data=valid_dataset, 172 | epochs=num_epochs, 173 | callbacks=callbacks 174 | ) 175 | -------------------------------------------------------------------------------- /unet.py: -------------------------------------------------------------------------------- 1 | from tensorflow.keras.layers import Conv2D, BatchNormalization, Activation, MaxPool2D, Conv2DTranspose, Concatenate, Input 2 | from tensorflow.keras.models import Model 3 | 4 | def conv_block(input, num_filters): 5 | x = Conv2D(num_filters, 3, padding="same")(input) 6 | x = BatchNormalization()(x) 7 | x = Activation("relu")(x) 8 | 9 | x = Conv2D(num_filters, 3, padding="same")(x) 10 | x = BatchNormalization()(x) 11 | x = Activation("relu")(x) 12 | 13 | return x 14 | 15 | def encoder_block(input, num_filters): 16 | x = conv_block(input, num_filters) 17 | p = MaxPool2D((2, 2))(x) 18 | return x, p 19 | 20 | def decoder_block(input, skip_features, num_filters): 21 | x = Conv2DTranspose(num_filters, (2, 2), strides=2, padding="same")(input) 22 | x = Concatenate()([x, skip_features]) 23 | x = conv_block(x, num_filters) 24 | return x 25 | 26 | def build_unet(input_shape, num_classes): 27 | inputs = Input(input_shape) 28 | 29 | s1, p1 = encoder_block(inputs, 64) 30 | s2, p2 = encoder_block(p1, 128) 31 | s3, p3 = encoder_block(p2, 256) 32 | s4, p4 = encoder_block(p3, 512) 33 | 34 | b1 = conv_block(p4, 1024) 35 | 36 | d1 = decoder_block(b1, s4, 512) 37 | d2 = decoder_block(d1, s3, 256) 38 | d3 = decoder_block(d2, s2, 128) 39 | d4 = decoder_block(d3, s1, 64) 40 | 41 | outputs = Conv2D(num_classes, 1, padding="same", activation="softmax")(d4) 42 | 43 | model = Model(inputs, outputs, name="U-Net") 44 | return model 45 | 46 | if __name__ == "__main__": 47 | input_shape = (512, 512, 3) 48 | model = build_unet(input_shape) 49 | model.summary() 50 | --------------------------------------------------------------------------------