SegNet model implemented using keras framework

Overview

keras-segnet

Implementation of SegNet-like architecture using keras.
Current version doesn't support index transferring proposed in SegNet article, so it's basically a general Encoder-Decoder network. In index-based-upsampling folder you can find some code used for index transferring implemented for older version of theano.

SegNet architecture

Comments
  • IOError: Unable to open file (File signature not found)

    IOError: Unable to open file (File signature not found)

    Got the following error when I run the following command: python SegNet.py

    Using Theano backend.
    Using gpu device 0: GeForce GTX 1070 (CNMeM is disabled, cuDNN 5105)
    /usr/local/lib/python2.7/dist-packages/theano/sandbox/cuda/__init__.py:600: UserWarning: Your cuDNN version is more recent than the one Theano officially supports. If you see any problems, try updating Theano or downgrading cuDNN to version 5.
      warnings.warn(warn)
    Compiled: OK
    Traceback (most recent call last):
      File "SegNet.py", line 118, in <module>
        autoencoder.load_weights('model_5l_weight_ep50.hdf5')
      File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2695, in load_weights
        f = h5py.File(filepath, mode='r')
      File "/usr/lib/python2.7/dist-packages/h5py/_hl/files.py", line 272, in __init__
        fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
      File "/usr/lib/python2.7/dist-packages/h5py/_hl/files.py", line 92, in make_fid
        fid = h5f.open(name, flags, fapl=fapl)
      File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/build/h5py-nQFNYZ/h5py-2.6.0/h5py/_objects.c:2577)
      File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/build/h5py-nQFNYZ/h5py-2.6.0/h5py/_objects.c:2536)
      File "h5py/h5f.pyx", line 76, in h5py.h5f.open (/build/h5py-nQFNYZ/h5py-2.6.0/h5py/h5f.c:1811)
    IOError: Unable to open file (File signature not found)
    
    opened by y22ma 9
  • Could you please give an example of your training and testing dataset?

    Could you please give an example of your training and testing dataset?

    Hi, Your code is of great value for people who are new to DL in Keras and Segnet, and I really appreciate your work. I found you use function prep_data(mode) to make label for the training and testing dataset, but there's not any example illustrating what's the .CSV file should look like, could you just kindly give an example of your training dataset and the CSV file corresponding to it?

    Thank you, Tony

    opened by ghost 2
  • Index-based upsampling?

    Index-based upsampling?

    Hi, as far as i understand, this implementation does not use the index-based upsampling, but uses the Upsample2D Keras layer. Do you have any ideas on how to implement the index passing and how much of the impact this should have?

    Thanks! Kind regards, Tanja

    opened by tivanovska 2
  • unable to load model

    unable to load model

    Hello. I trained my dataset with your segnet implementation. I used DePool2D custom layer when I trained my model. Training was done smoothly, and it shows nice results.

    However when I tried to reload the model it shows this error and I can't figure out what the problem is. Do you have any tips?

    Traceback (most recent call last):
      File "infer_test.py", line 188, in <module>
        main()
      File "infer_test.py", line 183, in main
        join(model_root, "infer_results", splitext(snapshot)[0]))
      File "infer_test.py", line 91, in infer_data
        model = load_model(snapshot_path, custom_objects = {'DePool2D' : DePool2D(MaxPooling2D)})
      File "/usr/lib/python3.6/site-packages/keras/models.py", line 239, in load_model
        model = model_from_config(model_config, custom_objects=custom_objects)
      File "/usr/lib/python3.6/site-packages/keras/models.py", line 313, in model_from_config
        return layer_module.deserialize(config, custom_objects=custom_objects)
      File "/usr/lib/python3.6/site-packages/keras/layers/__init__.py", line 54, in deserialize
        printable_module_name='layer')
      File "/usr/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 139, in deserialize_keras_object
        list(custom_objects.items())))
      File "/usr/lib/python3.6/site-packages/keras/engine/topology.py", line 2487, in from_config
        process_layer(layer_data)
      File "/usr/lib/python3.6/site-packages/keras/engine/topology.py", line 2473, in process_layer
        custom_objects=custom_objects)
      File "/usr/lib/python3.6/site-packages/keras/layers/__init__.py", line 54, in deserialize
        printable_module_name='layer')
      File "/usr/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 141, in deserialize_keras_object
        return cls.from_config(config['config'])
      File "/usr/lib/python3.6/site-packages/keras/engine/topology.py", line 1252, in from_config
        return cls(**config)
    TypeError: __init__() missing 1 required positional argument: 'pool2d_layer'
    

    I load model with this codes

    from build_segnet import DePool2D
    ...
    model = load_model(snapshot_path, custom_objects = {'DePool2D' : DePool2D()})
    
    opened by lazysquid 1
  • Generating error when converting script to python 3

    Generating error when converting script to python 3

    I am trying to run this in windows python 3 with tensor`flow backend(somehow my theano backend fail to utilize gpu). i converted print syntax in the ipython notebook and tried to run the script, it went well, but when i reached to "Loading and compiling model built with 'build_model.py'", received the following error. May I know what needs to be changed, based on this error. Also, what would be your suggestion if I would like to run the ipython using tensorflow backend with python 3

    error

    `thank you in advance for looking into this issue.

    opened by ishiry 1
  • ValueError: total size of new array must be unchanged

    ValueError: total size of new array must be unchanged

    Ran into this issue when the following command is run: python SegNet.py

    /usr/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
      warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
    Using Theano backend.
    Using gpu device 0: GeForce GTX 1070 (CNMeM is disabled, cuDNN 5105)
    /usr/local/lib/python2.7/dist-packages/theano/sandbox/cuda/__init__.py:600: UserWarning: Your cuDNN version is more recent than the one Theano officially supports. If you see any problems, try updating Theano or downgrading cuDNN to version 5.
      warnings.warn(warn)
    Traceback (most recent call last):
      File "SegNet.py", line 105, in <module>
        autoencoder = models.model_from_json(model_file.read())
      File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 210, in model_from_json
        return layer_from_config(config, custom_objects=custom_objects)
      File "/usr/local/lib/python2.7/dist-packages/keras/utils/layer_utils.py", line 40, in layer_from_config
        return layer_class.from_config(config['config'])
      File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 1080, in from_config
        model.add(layer)
      File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 327, in add
        output_tensor = layer(self.outputs[0])
      File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 569, in __call__
        self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
      File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 632, in add_inbound_node
        Node.create_node(self, inbound_layers, node_indices, tensor_indices)
      File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 168, in create_node
        output_shapes = to_list(outbound_layer.get_output_shape_for(input_shapes[0]))
      File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 336, in get_output_shape_for
        self.target_shape)
      File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 330, in _fix_unknown_dimension
        raise ValueError(msg)
    ValueError: total size of new array must be unchanged
    
    opened by y22ma 1
  • regarding two sequentially placed convolutional layers

    regarding two sequentially placed convolutional layers

    Hi, with respect to this segnet model, we can see that in each building block of encoder part, there are always two convolutional layers following each other before a maxpooling layer. For instance,

    Convolution2D(64, kernel, kernel, border_mode='same', input_shape=(1, img_h, img_w)),
        BatchNormalization(),
        Activation('relu'),
        Convolution2D(64, kernel, kernel, border_mode='same'),
        BatchNormalization(),
        Activation('relu'),
        MaxPooling2D(),
    
    

    I am not very clear about the real logic of having two convolutional layers following each other. Why not just having a combined convolutional layer. What's the strength of having this kind of design shown in Segnet architecture.

    opened by surfreta 1
  • ValueError: Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_2/MaxPool' (op: 'MaxPool') with input s

    ValueError: Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_2/MaxPool' (op: 'MaxPool') with input s

    hi,i am running build_model.py,it raises ValueError: Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_2/MaxPool' (op: 'MaxPool') with input shapes: [?,1,1,256].i have tried to set data format as "channels_last",but it is not work,can you tell me what's wrong?

    opened by xu-2019 0
  • ValueError: Error when checking input: expected conv2d_1_input to have shape (256, 256, 1) but got array with shape (1, 256, 256)

    ValueError: Error when checking input: expected conv2d_1_input to have shape (256, 256, 1) but got array with shape (1, 256, 256)

    Thank you for sharing the code. I have been trying to apply your code a data set. However, running the code gives the following error message: exception_prefix='input') File "D:\Program Files\Python\Python35\lib\site-packages\keras\engine\training_utils.py", line 138, in standardize_input_data str(data_shape)) ValueError: Error when checking input: expected conv2d_1_input to have shape (256, 256, 1) but got array with shape (1, 256, 256)

    opened by xyh-qz 3
  • How can I train it on my own data set ?

    How can I train it on my own data set ?

    Hi, I have generated the training data with corresponding ground truths and the required ".csv" file. How can I train it from scratch using my data ? Can you please elaborate the steps ? Thanks !

    opened by vismayaps 1
  • How to initialize weights using Camvid dataset?

    How to initialize weights using Camvid dataset?

    Dear all,

    I wish to apply Segnet Model for image segmentation task. These are medical images. I want to initialize the weights for Segnet model using Camvid dataset. What changes can I do to the current model to initialize the weights? I saw some thread https://github.com/legokichi/keras-segnet/blob/master/model_segnet.py, where they initialize weights using VGG16 pre-trained on Camvid dataset. But I couldn't really run that script (some error).

    Any help would be appreciated.

    Thank you

    opened by pranitapradhan91 0
  • This repository is over its data quota. Purchase more data packs to restore access.

    This repository is over its data quota. Purchase more data packs to restore access.

    I tried pulling the .hdf5 file using git lfs, but I am getting this error.

    batch response: This repository is over its data quota. Purchase more data packs to restore access.

    Is there any other way to download the file?

    opened by george-adaimi 1
  • ValueError after converting to python 3, keras vesion 2.1.4

    ValueError after converting to python 3, keras vesion 2.1.4

    I am trying to convert the build.py to python 3 and keras version 2.1.4. I came a long way but I have some trouble with (hopefully) the last step. Below I posted the code I have now but what I need to do yet is the final reshaping. I receive the error ValueError: total size of new array must be unchanged which according to this answer I got this error because the shape of my output is not corresponding to what I want to reshape it to. However my height and width are both factors of 32 so I do not understand the problem. The final layer of the network (a batch normalization) returns a shape of (Bat (None, 0, 256, 2). According to the code I found I have to reshape this using

    autoencoder.add(Reshape((n_labels, img_h*img_w))
    

    which would be (2, (256 * 256)). This sounds incorrect the 256 * 256 part is very large, but I don't fully understand the reshape function.

    I saw similair questions in other threads but there the problem seems to be that tensorflow was used instead of theano. I am using Theano as backend.

    Can somebody shed some light on what this reshaping does and maybe suggest to what dimensions I need to reshape?


    This is the entire model I'm using:

    from keras import models
    from keras.layers.core import Activation, Reshape, Permute
    from keras.layers.convolutional import Conv2D, MaxPooling2D, UpSampling2D
    from keras.layers.normalization import BatchNormalization
    import json
    
    img_w = 256
    img_h = 256
    n_labels = 2
    
    kernel = 3
    
    encoding_layers = [
        Conv2D(64, (kernel,kernel), padding='same', input_shape=(1, img_h, img_w)),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(64, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        MaxPooling2D(),
    
        Conv2D(128, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(128, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        MaxPooling2D(),
    
        Conv2D(256, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(256, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(256, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        MaxPooling2D(),
    
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        MaxPooling2D(),
    
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        MaxPooling2D(),
    ]
    
    autoencoder = models.Sequential()
    autoencoder.encoding_layers = encoding_layers
    
    for l in autoencoder.encoding_layers:
        autoencoder.add(l)
    
    decoding_layers = [
        UpSampling2D(),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
    
        UpSampling2D(),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(512, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(256, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
    
        UpSampling2D(),
        Conv2D(256, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(256, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(128, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
    
        UpSampling2D(),
        Conv2D(128, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(64, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
    
        UpSampling2D(),
        Conv2D(64, (kernel,kernel), padding='same'),
        BatchNormalization(),
        Activation('relu'),
        Conv2D(n_labels, (1, 1), padding='valid'),
        BatchNormalization(),
    ]
    autoencoder.decoding_layers = decoding_layers
    for l in autoencoder.decoding_layers:
        autoencoder.add(l)
    
    autoencoder.add(Reshape((n_labels, img_h * img_w)))
    autoencoder.add(Permute((2, 1)))
    autoencoder.add(Activation('softmax'))
    
    with open('model_5l.json', 'w') as outfile:
        outfile.write(json.dumps(json.loads(autoencoder.to_json()), indent=2))
    

    opened by Timmarh 0
Owner
null
Implementation of U-Net and SegNet for building segmentation

Specialized project Created by Katrine Nguyen and Martin Wangen-Eriksen as a part of our specialized project at Norwegian University of Science and Te

Martin.w-e 3 Dec 7, 2022
This is an implementation of Googles Yogi-Optimizer in Keras (tf.keras)

Yogi-Optimizer_Keras This is an implementation of Googles Yogi-Optimizer in Keras (tf.keras) The NeurIPS-Paper can be found here: http://papers.nips.c

null 14 Sep 13, 2022
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
Implemented fully documented Particle Swarm Optimization algorithm (basic model with few advanced features) using Python programming language

Implemented fully documented Particle Swarm Optimization (PSO) algorithm in Python which includes a basic model along with few advanced features such as updating inertia weight, cognitive, social learning coefficients and maximum velocity of the particle.

null 9 Nov 29, 2022
A solution to the 2D Ising model of ferromagnetism, implemented using the Metropolis algorithm

Solving the Ising model on a 2D lattice using the Metropolis Algorithm Introduction The Ising model is a simplified model of ferromagnetism, the pheno

Rohit Prabhu 5 Nov 13, 2022
A state of the art of new lightweight YOLO model implemented by TensorFlow 2.

CSL-YOLO: A New Lightweight Object Detection System for Edge Computing This project provides a SOTA level lightweight YOLO called "Cross-Stage Lightwe

Miles Zhang 54 Dec 21, 2022
Transformer model implemented with Pytorch

transformer-pytorch Transformer model implemented with Pytorch Attention is all you need-[Paper] Architecture Self-Attention self_attention.py class

Mingu Kang 12 Sep 3, 2022
This is the official source code for SLATE. We provide the code for the model, the training code, and a dataset loader for the 3D Shapes dataset. This code is implemented in Pytorch.

SLATE This is the official source code for SLATE. We provide the code for the model, the training code and a dataset loader for the 3D Shapes dataset.

Gautam Singh 66 Dec 26, 2022
SimDeblur is a simple framework for image and video deblurring, implemented by PyTorch

SimDeblur (Simple Deblurring) is an open source framework for image and video deblurring toolbox based on PyTorch, which contains most deep-learning based state-of-the-art deblurring algorithms. It is easy to implement your own image or video deblurring or other restoration algorithms.

null 220 Jan 7, 2023
Reinforcement learning framework and algorithms implemented in PyTorch.

Reinforcement learning framework and algorithms implemented in PyTorch.

Robotic AI & Learning Lab Berkeley 2.1k Jan 4, 2023
Step by Step on how to create an vision recognition model using LOBE.ai, export the model and run the model in an Azure Function

Step by Step on how to create an vision recognition model using LOBE.ai, export the model and run the model in an Azure Function

El Bruno 3 Mar 30, 2022
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
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
Build tensorflow keras model pipelines in a single line of code. Created by Ram Seshadri. Collaborators welcome. Permission granted upon request.

deep_autoviml Build keras pipelines and models in a single line of code! Table of Contents Motivation How it works Technology Install Usage API Image

AutoViz and Auto_ViML 102 Dec 17, 2022
A keras-based real-time model for medical image segmentation (CFPNet-M)

CFPNet-M: A Light-Weight Encoder-Decoder Based Network for Multimodal Biomedical Image Real-Time Segmentation This repository contains the implementat

null 268 Nov 27, 2022
Pytorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The original code is written in keras.

CasRel-pytorch-reimplement Pytorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The o

longlongman 170 Dec 1, 2022