Giter Club home page Giter Club logo

semantic-segmentation-with-unets's Introduction

Semantic segmentation with UNET

Original Image Predicted Segmentation Image Image with segmentation mask

This project focuses on implementing semantic segmentation on pascal VOC dataset using UNET. Implementation of UNET is achieved with fastai library. Accuracy achieved is 78.75% with output image size 224x224. GPU used for this project: NVIDIA GeForce GTX 1050

DATASET


Pascal VOC 2012 challenge dataset is popular for object detection and segmentation task. This dataset consists of images which belong to 20 different types of objects. Therefore, 21 classes for predictions including background(class index=0):

Person: person
Animal: bird, cat, cow, dog, horse, sheep
Vehicle: aeroplane, bicycle, boat, bus, car, motorbike, train
Indoor: bottle, chair, dining table, potted plant, sofa, tv/monitor

Class indices for semantic segmentation task:

0=background, 1=aeroplane, 2=bicycle, 3=bird, 4=boat, 5=bottle, 6=bus, 7=car , 8=cat, 9=chair, 10=cow, 11=diningtable, 12=dog, 13=horse, 14=motorbike, 15=person, 16=potted plant, 17=sheep, 18=sofa, 19=train, 20=tv/monitor

more example on semnatic segmentation on pascal voc dataset = http://host.robots.ox.ac.uk/pascal/VOC/voc2012/segexamples/index.html

Downloading dataset:

Download the development kit for training/validation data. More information

http://host.robots.ox.ac.uk/pascal/VOC/voc2012/#data

Alternative resource of downloading the dataset is using:

https://s3.amazonaws.com/fast-ai-imagelocal/pascal-voc.tgz

Directory structure:

After downloading the development kit following will be it's folder structure:

VOCdevkit/VOC2012
VOCdevkit/VOC2012/Annotations
VOCdevkit/VOC2012/ImageSets
VOCdevkit/VOC2012/JPEGImages
VOCdevkit/VOC2012/SegmentationClass
VOCdevkit/VOC2012/SegmentationObject

Libraries

fastai
numpy
jupyter notebook

Outputs:

input and out images

Input Images Predicted Segmentation mask Image with segmentation mask

semantic-segmentation-with-unets's People

Contributors

keyurparalkar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

semantic-segmentation-with-unets's Issues

Trying to use my costum dataset issues

Hello I am trying to train a dataset I made from labelme and converted it to Pascal Voc. I didn't get the format structure like yours but I got the JPEGImages, SegmentationClassPNG. Your datasets is familiar and i am using fastai in google colab to train. I keep getting errors with the function to get labels and transfer to the images. I would really appreciate it if you helped with this project

%reload_ext autoreload
%autoreload 2
%matplotlib inline

import fastai
from fastai import *
from fastai.vision import*
path = '/content/drive/My Drive/Umes2020'
image_ip = path + '/JPEGImages'
images_lbl = path + '/SegmentationClassPNG'
codes = np.array(["background","Sidewalk"])
keep_train_val = path + '/val.txt'
class SegmentationProcessor(PreProcessor):
    "`PreProcessor` that stores the classes for segmentation."
    def __init__(self, ds:ItemList): self.classes = ds.classes
    def process(self, ds:ItemList):  ds.classes,ds.c = self.classes,len(self.classes)
class SegmentationLabelList(ImageList):
    "`ItemList` for segmentation masks."
    _processor=SegmentationProcessor
    def __init__(self, items:Iterator, classes:Collection=None, **kwargs):
        super().__init__(items, **kwargs)
        self.classes,self.loss_func = classes,CrossEntropyFlat(axis=1)

    def new(self, items, classes=None, **kwargs):
        return self.new(items, ifnone(classes, self.classes), **kwargs)

    def open(self, fn): return open_mask(fn,convert_mode='P')   #HERE
    def analyze_pred(self, pred, thresh:float=0.5): return pred.argmax(dim=0)[None]
    def reconstruct(self, t:Tensor): return ImageSegment(t)
class SegmentationItemList(ImageList):
    "`ItemList` suitable for segmentation tasks."
    _label_cls,_square_show_res = SegmentationLabelList,False
get_y_fn = lambda x: images_lbl/f'{x.stem}.png'
data = (SegmentationItemList.from_folder(image_ip)
        .split_by_rand_pct()
        .label_from_func(get_y_fn,classes=codes)
        .transform(get_transforms(),size=128,tfm_y=True)
        .databunch(bs=4))
#          .normalize(imagenet_stats))

Error:

TypeError                                 Traceback (most recent call last)
<ipython-input-11-e9a537d7b20e> in <module>()
      1 data = (SegmentationItemList.from_folder(image_ip)
      2         .split_by_rand_pct()
----> 3         .label_from_func(get_y_fn,classes=codes)
      4         .transform(get_transforms(),size=128,tfm_y=True)
      5         .databunch(bs=4))

3 frames
<ipython-input-10-2728937c21a8> in <lambda>(x)
----> 1 get_y_fn = lambda x: images_lbl/f'{x.stem}.png'

TypeError: unsupported operand type(s) for /: 'str' and 'str'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.