SegNet-Basic with Keras

Overview

SegNet-Basic:


What is Segnet?

  • Deep Convolutional Encoder-Decoder Architecture for Semantic Pixel-wise Image Segmentation

Segnet = (Encoder + Decoder) + Pixel-Wise Classification layer

SegNet: A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation (Vijay Badrinarayanan, Alex Kendall, Roberto Cipolla, Senior Member, IEEE) arXiv:1511.00561v3

What is SegNet-Basic?

  • "In order to analyse SegNet and compare its performance with FCN (decoder variants) we use a smaller version of SegNet, termed SegNet-Basic , which ha 4 encoders and 4 decoders. All the encoders in SegNet-Basic perform max-pooling and subsampling and the corresponding decoders upsample its input using the received max-pooling indices."

Basically it's a mini-segnet to experiment / test the architecure with convnets, such as FCN.


Steps To Run The Model:


  1. Run python model-basic.py to create segNet_basic_model for keras to use.

    • model-basic.py contains the architecure.

Dataset:


  1. In a different directory run this to download the dataset from original Implementation.

    • git clone [email protected]:alexgkendall/SegNet-Tutorial.git
    • copy the /CamVid to here, or change the DataPath in data_loader.py to the above directory
  2. The run python data_loader.py to generate these two files:

    • /data/train_data.npz/ and /data/train_label.npz
    • This will make it easy to process the model over and over, rather than waiting the data to be loaded into memory.

To Do:


[x] SegNet-Basic
[ ] SegNet
[x] Test Accuracy
[ ] Requirements

Segnet-Basic Road Scene Results:


  • Train / Test:
	Train on 367 samples, validate on 233 samples
	Epoch 101/102
	366/367 [============================>.] 
	- ETA: 0s - loss: 0.3835 - acc: 0.8737Epoch 00000: val_acc improved from -inf to 0.76367, saving model to weights.best.hdf5
	367/367 [==============================] 
	- 231s - loss: 0.3832 - acc: 0.8738 - val_loss: 0.7655 - val_acc: 0.7637
	Epoch 102/102
	366/367 [============================>.] 
	- ETA: 0s - loss: 0.3589 - acc: 0.8809Epoch 00001: val_acc did not improve
	367/367 [==============================] 
	- 231s - loss: 0.3586 - acc: 0.8810 - val_loss: 2.4447 - val_acc: 0.4478
  • Evaluation:

    acc: 85.47%

    img1

    img2

Comments
  • SegNet_Basic.py

    SegNet_Basic.py

    Hi,

    I have few clarifications in SegNet_Basic.py at line 28.

    class_weighting= [0.2595, 0.1826, 4.5640, 0.1417, 0.5051, 0.3826, 9.6446, 1.8418, 6.6823, 6.2478, 3.0, 7.3614]

    I would like to know how this values are assigned to class weighting.

    Regards Mohan

    opened by mohanrajmit 3
  • ValueError: GpuDnnConv images and kernel must have the same stack size

    ValueError: GpuDnnConv images and kernel must have the same stack size

    Hello,

    I'm facing this error, I also followed your steps, any ideas ?

    ValueError: GpuDnnConv images and kernel must have the same stack size
    
    Apply node that caused the error: GpuDnnConv{algo='small', inplace=True}(GpuContiguous.0, GpuContiguous.0, GpuAllocEmpty.0, GpuDnnConvDesc{border_mode='valid', subsample=(1, 1), conv_mode='conv', precision='float32'}.0, Constant{1.0}, Constant{0.0})
    Toposort index: 688
    Inputs types: [CudaNdarrayType(float32, 4D), CudaNdarrayType(float32, 4D), CudaNdarrayType(float32, 4D), <theano.gof.type.CDataType object at 0x7f0094d97c50>, Scalar(float32), Scalar(float32)]
    Inputs shapes: [(6, 480, 182, 34), (128, 64, 3, 3), (6, 128, 180, 32), 'No shapes', (), ()]
    Inputs strides: [(2970240, 6188, 34, 1), (576, 9, 3, 1), (737280, 5760, 32, 1), 'No strides', (), ()]
    Inputs values: ['not shown', 'not shown', 'not shown', <PyCObject object at 0x7f0081578c88>, 1.0, 0.0]
    Inputs name: ('image', 'kernel', 'output', 'descriptor', 'alpha', 'beta')
    
    Outputs clients: [[GpuElemwise{add,no_inplace}(GpuDnnConv{algo='small', inplace=True}.0, GpuReshape{4}.0)]]
    
    HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
    HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.
    
    
    opened by abduallahmohamed 2
  • model-full.py has array reshaping errors .

    model-full.py has array reshaping errors .

    Hello .the Normal Model compiles well but the model_full.py has error on the lower part : because of the reshaping problem . Line 140 segnet_basic.add(Reshape((n_labels, img_h * img_w), input_shape=(12,img_h, img_w)))

    They seem to be fine mathematically too . The simplemodel definition(model-basic.py ) is similar like this yet it works .But teh Model-full.py has error in this part .

    Any help diagnosing this would be great .

    opened by codepujan 1
  • Segnet basic model

    Segnet basic model

    Hello, thank you for your work. I have issues on segnet-basic model. It is confirmed that the paper says that the 7x7 kernel size was used, but I want to know if I am mistaken.

    opened by penpaperkeycode 0
  • Class weight does not work. Accuracy and loss remain same

    Class weight does not work. Accuracy and loss remain same

    i use the code and train on dataset from https://github.com/yhlleo/DeepCrack. The images changed to binary images. For the code I just changed the path and the label from 12 to 2 which are crack and background for all the py file. But it seems the class weight is not working.The changes i made are all the value 12 to 2 and the path to my dataset. Full code and dataset can be found at https://drive.google.com/open?id=1wK-non5bMkpApMshtCHXIqLXZOJ9jUxU. I have been working on this problem for a long time and didn't found any workable solution online. I am desperate for help. So can you help me find the problem or at least give some possible causes that cause the problem of the class weighting not working on the fit generator. I changed the value for the class weight but still the accuracy the same. Changing the optimizer or learning rate also gives the same accuracy. The accuracy is the same for the first epoch which is 95.67%, changing the class weight did not affect it

    opened by vzhencheng97 1
  • Version of Keras???

    Version of Keras???

    I have my Keras version as 2.1.2...

    When i tried to run this program i got the below error:

    Using TensorFlow backend. model-basic.py:31: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(64, (3, 3), padding="valid") Convolution2D(filter_size, kernel, kernel, border_mode='valid'), model-basic.py:37: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(128, (3, 3), padding="valid") Convolution2D(128, kernel, kernel, border_mode='valid'), model-basic.py:43: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(256, (3, 3), padding="valid") Convolution2D(256, kernel, kernel, border_mode='valid'), model-basic.py:49: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(512, (3, 3), padding="valid") Convolution2D(512, kernel, kernel, border_mode='valid'), Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1628, in _create_c_op c_op = c_api.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_2/MaxPool' (op: 'MaxPool') with input shapes: [?,1,180,128].

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "model-basic.py", line 91, in segnet_basic.add(l) File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 489, in add output_tensor = layer(self.outputs[0]) File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 603, in call output = self.call(inputs, **kwargs) File "/usr/local/lib/python3.5/dist-packages/keras/layers/pooling.py", line 154, in call data_format=self.data_format) File "/usr/local/lib/python3.5/dist-packages/keras/layers/pooling.py", line 217, in _pooling_function pool_mode='max') File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 3466, in pool2d data_format=tf_data_format) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/nn_ops.py", line 2140, in max_pool name=name) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 4641, in max_pool data_format=data_format, name=name) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/util/deprecation.py", line 488, in new_func return func(*args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 3274, in create_op op_def=op_def) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1792, in init control_input_ops) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1631, in _create_c_op raise ValueError(str(e)) ValueError: Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_2/MaxPool' (op: 'MaxPool') with input shapes: [?,1,180,128]. *** Error in `python3': free(): invalid pointer: 0x00000000012b2760 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fa4d1bde7e5] /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fa4d1be737a] /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fa4d1beb53c] /usr/lib/x86_64-linux-gnu/libprotobuf.so.9(_ZN6google8protobuf8internal28DestroyDefaultRepeatedFieldsEv+0x1f)[0x7fa47b2388af] /usr/lib/x86_64-linux-gnu/libprotobuf.so.9(_ZN6google8protobuf23ShutdownProtobufLibraryEv+0x8b)[0x7fa47b237b3b] /usr/lib/x86_64-linux-gnu/libmirprotobuf.so.3(+0x233b9)[0x7fa42fdce3b9] /lib64/ld-linux-x86-64.so.2(+0x10de7)[0x7fa4d215ede7] /lib/x86_64-linux-gnu/libc.so.6(+0x39ff8)[0x7fa4d1ba0ff8] /lib/x86_64-linux-gnu/libc.so.6(+0x3a045)[0x7fa4d1ba1045] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf7)[0x7fa4d1b87837] python3(_start+0x29)[0x5d6049]

    Please can you specify which version of the Keras this program requires to run???

    Also please help me to resolve the issue?

    Thanks, Arun

    opened by ArunJ1 2
Owner
Yad Konrad
indie researcher in areas of Machine Learning, Linguistics & Program Synthesis.
Yad Konrad
Keras udrl - Keras implementation of Upside Down Reinforcement Learning

keras_udrl Keras implementation of Upside Down Reinforcement Learning This is me

Eder Santana 7 Jan 24, 2022
Example-custom-ml-block-keras - Custom Keras ML block example for Edge Impulse

Custom Keras ML block example for Edge Impulse This repository is an example on

Edge Impulse 8 Nov 2, 2022
Classification models 1D Zoo - Keras and TF.Keras

Classification models 1D Zoo - Keras and TF.Keras This repository contains 1D variants of popular CNN models for classification like ResNets, DenseNet

Roman Solovyev 12 Jan 6, 2023
a basic code repository for basic task in CV(classification,detection,segmentation)

basic_cv a basic code repository for basic task in CV(classification,detection,segmentation,tracking) classification generate dataset train predict de

null 1 Oct 15, 2021
Image-to-Image Translation with Conditional Adversarial Networks (Pix2pix) implementation in keras

pix2pix-keras Pix2pix implementation in keras. Original paper: Image-to-Image Translation with Conditional Adversarial Networks (pix2pix) Paper Author

William Falcon 141 Dec 30, 2022
An end-to-end machine learning web app to predict rugby scores (Pandas, SQLite, Keras, Flask, Docker)

Rugby score prediction An end-to-end machine learning web app to predict rugby scores Overview An demo project to provide a high-level overview of the

null 34 May 24, 2022
The fastest way to visualize GradCAM with your Keras models.

VizGradCAM VizGradCam is the fastest way to visualize GradCAM in Keras models. GradCAM helps with providing visual explainability of trained models an

null 58 Nov 19, 2022
Age and Gender prediction using Keras

cnn_age_gender Age and Gender prediction using Keras Dataset example : Description : UTKFace dataset is a large-scale face dataset with long age span

XN3UR0N 58 May 3, 2022
Keras implementation of Normalizer-Free Networks and SGD - Adaptive Gradient Clipping

Keras implementation of Normalizer-Free Networks and SGD - Adaptive Gradient Clipping

Yam Peleg 63 Sep 21, 2022
kapre: Keras Audio Preprocessors

Kapre Keras Audio Preprocessors - compute STFT, ISTFT, Melspectrogram, and others on GPU real-time. Tested on Python 3.6 and 3.7 Why Kapre? vs. Pre-co

Keunwoo Choi 867 Dec 29, 2022
Human head pose estimation using Keras over TensorFlow.

RealHePoNet: a robust single-stage ConvNet for head pose estimation in the wild.

Rafael Berral Soler 71 Jan 5, 2023
Keras community contributions

keras-contrib : Keras community contributions Keras-contrib is deprecated. Use TensorFlow Addons. The future of Keras-contrib: We're migrating to tens

Keras 1.6k Dec 21, 2022
Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization

This project is now archived. It's been fun working on it, but it's time for me to move on. Thank you for all the support and feedback over the last c

Max Pumperla 2.1k Jan 3, 2023
Distributed Deep learning with Keras & Spark

Elephas: Distributed Deep Learning with Keras & Spark Elephas is an extension of Keras, which allows you to run distributed deep learning models at sc

Max Pumperla 1.6k Jan 5, 2023
Train/evaluate a Keras model, get metrics streamed to a dashboard in your browser.

Hera Train/evaluate a Keras model, get metrics streamed to a dashboard in your browser. Setting up Step 1. Plant the spy Install the package pip

Keplr 495 Dec 10, 2022
Graph Neural Networks with Keras and Tensorflow 2.

Welcome to Spektral Spektral is a Python library for graph deep learning, based on the Keras API and TensorFlow 2. The main goal of this project is to

Daniele Grattarola 2.2k Jan 8, 2023
QKeras: a quantization deep learning library for Tensorflow Keras

QKeras github.com/google/qkeras QKeras 0.8 highlights: Automatic quantization using QKeras; Stochastic behavior (including stochastic rouding) is disa

Google 437 Jan 3, 2023
Hyperparameter Optimization for TensorFlow, Keras and PyTorch

Hyperparameter Optimization for Keras Talos • Key Features • Examples • Install • Support • Docs • Issues • License • Download Talos radically changes

Autonomio 1.6k Dec 15, 2022
MMdnn is a set of tools to help users inter-operate among different deep learning frameworks. E.g. model conversion and visualization. Convert models between Caffe, Keras, MXNet, Tensorflow, CNTK, PyTorch Onnx and CoreML.

MMdnn MMdnn is a comprehensive and cross-framework tool to convert, visualize and diagnose deep learning (DL) models. The "MM" stands for model manage

Microsoft 5.7k Jan 9, 2023