Giter Site home page Giter Site logo

densenet-keras's Introduction

DenseNet-Keras with ImageNet Pretrained Models

This is an Keras implementation of DenseNet with ImageNet pretrained weights. The weights are converted from Caffe Models. The implementation supports both Theano and TensorFlow backends.

To know more about how DenseNet works, please refer to the original paper

Densely Connected Convolutional Networks
Gao Huang, Zhuang Liu, Kilian Q. Weinberger, Laurens van der Maaten
arXiv:1608.06993

Pretrained DenseNet Models on ImageNet

The top-1/5 accuracy rates by using single center crop (crop size: 224x224, image size: 256xN)

Network Top-1 Top-5 Theano Tensorflow
DenseNet 121 (k=32) 74.91 92.19 model (32 MB) model (32 MB)
DenseNet 169 (k=32) 76.09 93.14 model (56 MB) model (56 MB)
DenseNet 161 (k=48) 77.64 93.79 model (112 MB) model (112 MB)

Usage

First, download the above pretrained weights to the imagenet_models folder.

Run test_inference.py for an example of how to use the pretrained model to make inference.

python test_inference.py

Fine-tuning

Check this out to see example of fine-tuning DenseNet with your own dataset.

Requirements

  • Keras 1.2.2 2.0.5
  • Theano 0.8.2 or TensorFlow 0.12.0 1.2.1

Updates

  • Keras 2.0.5 and TensorFlow 1.2.1 are supported

densenet-keras's People

Contributors

flyyufelix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

densenet-keras's Issues

TypeError: 'module' object is not callable

Version

DenseNet-Keras git:(master) ipython
Python 2.7.12 (default, Dec  4 2017, 14:50:18)
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import cv2

In [2]: import tensorflow as tf

In [3]: cv2.__version__
Out[3]: '2.4.13.6'

In [4]: tf.__version__
Out[4]: '1.4.0'

In [5]: import keras
Using TensorFlow backend.

In [6]: keras.__version__
Out[6]: '2.2.2'

DenseNet-Keras git:(master) ls -hl imagenet_models
total 33M
drwxrwxr-x 2 epbox epbox 4.0K 8月  30 15:08 .
drwxrwxr-x 5 epbox epbox 4.0K 8月  30 15:09 ..
-rw-r--r-- 1 epbox epbox  32M 8月  30 15:07 densenet121_weights_tf.h5
-rw-rw-r-- 1 epbox epbox   55 8月  30 14:40 README.md

Error

DenseNet-Keras git:(master) python test_inference.py
Using TensorFlow backend.
/home/epbox/Github/DenseNet-Keras/densenet121.py:45: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (7, 7), strides=(2, 2), use_bias=False, name="conv1")`
  x = Convolution2D(nb_filter, 7, 7, subsample=(2, 2), name='conv1', bias=False)(x)
2018-09-10 14:25:19.720132: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-09-10 14:25:19.821988: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-09-10 14:25:19.822306: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties:
name: GeForce GTX TITAN X major: 5 minor: 2 memoryClockRate(GHz): 1.076
pciBusID: 0000:01:00.0
totalMemory: 11.92GiB freeMemory: 11.64GiB
2018-09-10 14:25:19.822322: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:01:00.0, compute capability: 5.2)
/home/epbox/Github/DenseNet-Keras/densenet121.py:99: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (1, 1), use_bias=False, name="conv2_1_x1")`
  x = Convolution2D(inter_channel, 1, 1, name=conv_name_base+'_x1', bias=False)(x)
/home/epbox/Github/DenseNet-Keras/densenet121.py:109: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(32, (3, 3), use_bias=False, name="conv2_1_x2")`
  x = Convolution2D(nb_filter, 3, 3, name=conv_name_base+'_x2', bias=False)(x)
Traceback (most recent call last):
  File "test_inference.py", line 34, in <module>
    model = DenseNet(reduction=0.5, classes=1000, weights_path=weights_path)
  File "/home/epbox/Github/DenseNet-Keras/densenet121.py", line 55, in DenseNet
    x, nb_filter = dense_block(x, stage, nb_layers[block_idx], nb_filter, growth_rate, dropout_rate=dropout_rate, weight_decay=weight_decay)
  File "/home/epbox/Github/DenseNet-Keras/densenet121.py", line 165, in dense_block
    concat_feat = merge([concat_feat, x], mode='concat', concat_axis=concat_axis, name='concat_'+str(stage)+'_'+str(branch))
TypeError: 'module' object is not callable

DocUNet

Hi, I notice your project at shahsohil/sunets#8. Have you reproduced the paper<DocUNet: Document Image Unwarping via A Stacked U-Net>? I trained the S-UNet for this paper some times,but it doesn't work. Can you give me some suggestions?

Regarding scale

Can you explain why you're using a separate scale function when batch norm scales the output anyway?

AssertionError: AbstractConv shape mismatch: shape of filters does not match given kshp.

AssertionError: AbstractConv shape mismatch: shape of filters does not match given kshp.
Apply node that caused the error: Assert{msg='AbstractConv shape mismatch: shape of filters does not match given kshp.'}(InplaceDimShuffle{3,2,0,1}.0, Elemwise{eq,no_inplace}.0, Elemwise{eq,no_inplace}.0, Elemwise{eq,no_inplace}.0, Elemwise{eq,no_inplace}.0)
Toposort index: 2069
Inputs types: [TensorType(float32, 4D), TensorType(bool, scalar), TensorType(bool, scalar), TensorType(bool, scalar), TensorType(bool, scalar)]
Inputs shapes: [(3L, 64L, 7L, 7L), (), (), (), ()]
Inputs strides: [(196L, 588L, 4L, 28L), (), (), (), ()]
Inputs values: ['not shown', array(False, dtype=bool), array(False, dtype=bool), array(True, dtype=bool), array(True, dtype=bool)]
Outputs clients: [[Subtensor{::, ::, ::int64, ::int64}(Assert{msg='AbstractConv shape mismatch: shape of filters does not match given kshp.'}.0, Constant{-1}, Constant{-1})]]

Pretrained DenseNet Models

Hello, thanks for your great work. I am researching some related issues and need your pretrained model for my own experiment. I'll appreciate it if you can give me the access. My google mail address: [email protected]

Pretrained model

Hello, thanks for your great work. I need your pretrained model for my own experiment. I'll appreciate it if you can give me the access. My google mail address: [email protected]

AttributeError: 'Tensor' object has no attribute 'assign'

Hi,

Thanks a lot for the repo, but I hit the following error when trying the python test_inference.py with the densenet169:

Traceback (most recent call last):
  File "test_inference.py", line 27, in <module>
    model = DenseNet(reduction=0.5, classes=1000, weights_path=weights_path)
  File "densenet169.py", line 78, in DenseNet
    model.load_weights(weights_path, by_name=True)
  File "/home/petteri/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 2498, in load_weights
    load_weights_from_hdf5_group_by_name(f, self.layers)
  File "/home/petteri/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 2976, in load_weights_from_hdf5_group_by_name
    K.batch_set_value(weight_value_tuples)
  File "/home/petteri/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2025, in batch_set_value
    assign_op = x.assign(assign_placeholder)
AttributeError: 'Tensor' object has no attribute 'assign'

So when printing the types of the variables in the saved weights I got the following:

<tf.Variable 'conv1/kernel:0' shape=(7, 7, 3, 64) dtype=float32_ref>
<tf.Variable 'conv1_bn/gamma:0' shape=(64,) dtype=float32_ref>
<tf.Variable 'conv1_bn/beta:0' shape=(64,) dtype=float32_ref>
<tf.Variable 'conv1_bn/moving_mean:0' shape=(64,) dtype=float32_ref>
<tf.Variable 'conv1_bn/moving_variance:0' shape=(64,) dtype=float32_ref>
Tensor("conv1_scale/Const:0", shape=(64,), dtype=float32)

And the batch_set_value(tuples) from the backend hit the Tensor problem with "conv1_scale", is there a fix for this to allow the assigning or are the weights somewhat weirdly saved?:

            if hasattr(x, '_assign_placeholder'):
                assign_placeholder = x._assign_placeholder
                assign_op = x._assign_op
            else:
                assign_placeholder = tf.placeholder(tf_dtype, shape=value.shape)
                assign_op = x.assign(assign_placeholder)
                x._assign_placeholder = assign_placeholder
                x._assign_op = assign_op
            assign_ops.append(assign_op)
            feed_dict[assign_placeholder] = value

about the pre-train weight

Hi,
Did you test the pre-train model on tensorflow backend?
I got an error when use it while the theano backend works.
I need a tensorflow pre-train model.

Thanks

Scale layer vs BatchNormalization in Keras v2

Hi,

At first, thanks for this repo with DenseNet for Keras. As I understand you ported the architecture and weights from Caffe. I've just a question on actual purpose of your custom layer Scale after BatchNormalization in Keras v2 in the sense don't they perform the same work ?

face recognition

By leveraging on this denseNet-Keras framework can we undergo face recognition.
if so, what is the accuracy we can achieve ?

conversion tool

I'm curious, what did you use to actually convert the weights from caffe to keras?

RGB or BGR?

Hi, this is a nice work. And I have some questions about how to use the model.

What tool is used convert the caffe model? And what order should be used for testing, RGB or BGR. Thanks.

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.