• Stars
    star
    507
  • Rank 83,798 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple Tensorflow implementation of Densenet using Cifar10, MNIST

Densenet-Tensorflow

Tensorflow implementation of Densenet using Cifar10, MNIST

  • The code that implements this paper is Densenet.py
  • There is a slight difference, I used AdamOptimizer

If you want to see the original author's code or other implementations, please refer to this link

Requirements

  • Tensorflow 1.x
  • Python 3.x
  • tflearn (If you are easy to use global average pooling, you should install tflearn
However, I implemented it using tf.layers, so don't worry

Issue

  • I used tf.contrib.layers.batch_norm
    def Batch_Normalization(x, training, scope):
        with arg_scope([batch_norm],
                       scope=scope,
                       updates_collections=None,
                       decay=0.9,
                       center=True,
                       scale=True,
                       zero_debias_moving_mean=True) :
            return tf.cond(training,
                           lambda : batch_norm(inputs=x, is_training=training, reuse=None),
                           lambda : batch_norm(inputs=x, is_training=training, reuse=True))
  • If not enough GPU memory, Please edit the code
with tf.Session() as sess : NO
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess : OK

Idea

What is the "Global Average Pooling" ?

    def Global_Average_Pooling(x, stride=1) :
        width = np.shape(x)[1]
        height = np.shape(x)[2]
        pool_size = [width, height]
        return tf.layers.average_pooling2d(inputs=x, pool_size=pool_size, strides=stride) 
        # The stride value does not matter
  • If you use tflearn, please refer to this link
    def Global_Average_Pooling(x):
        return tflearn.layers.conv.global_avg_pool(x, name='Global_avg_pooling')

What is the "Dense Connectivity" ?

Dense_connectivity

What is the "Densenet Architecture" ?

Dense_Architecture

    def Dense_net(self, input_x):
        x = conv_layer(input_x, filter=2 * self.filters, kernel=[7,7], stride=2, layer_name='conv0')
        x = Max_Pooling(x, pool_size=[3,3], stride=2)

        x = self.dense_block(input_x=x, nb_layers=6, layer_name='dense_1')
        x = self.transition_layer(x, scope='trans_1')

        x = self.dense_block(input_x=x, nb_layers=12, layer_name='dense_2')
        x = self.transition_layer(x, scope='trans_2')

        x = self.dense_block(input_x=x, nb_layers=48, layer_name='dense_3')
        x = self.transition_layer(x, scope='trans_3')

        x = self.dense_block(input_x=x, nb_layers=32, layer_name='dense_final') 
        
        x = Batch_Normalization(x, training=self.training, scope='linear_batch')
        x = Relu(x)
        x = Global_Average_Pooling(x)
        x = Linear(x)

        return x

What is the "Dense Block" ?

Dense_block

    def dense_block(self, input_x, nb_layers, layer_name):
        with tf.name_scope(layer_name):
            layers_concat = list()
            layers_concat.append(input_x)

            x = self.bottleneck_layer(input_x, scope=layer_name + '_bottleN_' + str(0))

            layers_concat.append(x)

            for i in range(nb_layers - 1):
                x = Concatenation(layers_concat)
                x = self.bottleneck_layer(x, scope=layer_name + '_bottleN_' + str(i + 1))
                layers_concat.append(x)

            x = Concatenation(layers_concat)
            
            return x

What is the "Bottleneck Layer" ?

    def bottleneck_layer(self, x, scope):
        with tf.name_scope(scope):
            x = Batch_Normalization(x, training=self.training, scope=scope+'_batch1')
            x = Relu(x)
            x = conv_layer(x, filter=4 * self.filters, kernel=[1,1], layer_name=scope+'_conv1')
            x = Drop_out(x, rate=dropout_rate, training=self.training)

            x = Batch_Normalization(x, training=self.training, scope=scope+'_batch2')
            x = Relu(x)
            x = conv_layer(x, filter=self.filters, kernel=[3,3], layer_name=scope+'_conv2')
            x = Drop_out(x, rate=dropout_rate, training=self.training)
            
            return x

What is the "Transition Layer" ?

    def transition_layer(self, x, scope):
        with tf.name_scope(scope):
            x = Batch_Normalization(x, training=self.training, scope=scope+'_batch1')
            x = Relu(x)
            x = conv_layer(x, filter=self.filters, kernel=[1,1], layer_name=scope+'_conv1')
            x = Drop_out(x, rate=dropout_rate, training=self.training)
            x = Average_pooling(x, pool_size=[2,2], stride=2)

            return x

Compare Structure (CNN, ResNet, DenseNet)

compare

Results

  • (MNIST) The highest test accuracy is 99.2% (This result does not use dropout)
  • The number of dense block layers is fixed to 4
    for i in range(self.nb_blocks) :
        # original : 6 -> 12 -> 48

        x = self.dense_block(input_x=x, nb_layers=4, layer_name='dense_'+str(i))
        x = self.transition_layer(x, scope='trans_'+str(i))

CIFAR-10

cifar_10

CIFAR-100

cifar_100

Image Net

image_net

Related works

References

Author

Junho Kim

More Repositories

1

UGATIT

Official Tensorflow implementation of U-GAT-IT: Unsupervised Generative Attentional Networks with Adaptive Layer-Instance Normalization for Image-to-Image Translation (ICLR 2020)
Python
6,182
star
2

Tensorflow-Cookbook

Simple Tensorflow Cookbook for easy-to-use
Python
2,798
star
3

SENet-Tensorflow

Simple Tensorflow implementation of "Squeeze and Excitation Networks" using Cifar10 (ResNeXt, Inception-v4, Inception-resnet-v2)
Python
750
star
4

StarGAN-Tensorflow

Simple Tensorflow implementation of StarGAN (CVPR 2018 Oral)
Python
715
star
5

Self-Attention-GAN-Tensorflow

Simple Tensorflow implementation of "Self-Attention Generative Adversarial Networks" (SAGAN)
Python
540
star
6

SPADE-Tensorflow

Simple Tensorflow implementation of "Semantic Image Synthesis with Spatially-Adaptive Normalization" a.k.a. GauGAN, SPADE (CVPR 2019 Oral)
Python
359
star
7

MUNIT-Tensorflow

Simple Tensorflow implementation of "Multimodal Unsupervised Image-to-Image Translation" (ECCV 2018)
Python
299
star
8

Vector_Similarity

Python, Java implementation of TS-SS called from "A Hybrid Geometric Approach for Measuring Similarity Level Among Documents and Document Clustering"
Python
285
star
9

Tensorflow2-Cookbook

Simple Tensorflow 2.x Cookbook for easy-to-use
Python
266
star
10

BigGAN-Tensorflow

Simple Tensorflow implementation of "Large Scale GAN Training for High Fidelity Natural Image Synthesis" (BigGAN)
Python
261
star
11

vit-tensorflow

Vision Transformer Cookbook with Tensorflow
Python
236
star
12

CartoonGAN-Tensorflow

Simple Tensorflow implementation of CartoonGAN (CVPR 2018)
Python
217
star
13

StyleGAN-Tensorflow

Simple & Intuitive Tensorflow implementation of StyleGAN (CVPR 2019 Oral)
Python
211
star
14

GAN_Metrics-Tensorflow

Simple Tensorflow implementation of metrics for GAN evaluation (Inception score, Frechet-Inception distance, Kernel-Inception distance)
Python
205
star
15

ResNet-Tensorflow

Simple Tensorflow implementation of pre-activation ResNet18, 34, 50, 101, 152
Python
179
star
16

ResNeXt-Tensorflow

Simple Tensorflow implementation of ResNeXt using Cifar10
Python
159
star
17

AdaBound-Tensorflow

Simple Tensorflow implementation of "Adaptive Gradient Methods with Dynamic Bound of Learning Rate" (ICLR 2019)
Python
150
star
18

Spectral_Normalization-Tensorflow

Simple Tensorflow Implementation of "Spectral Normalization for Generative Adversarial Networks" (ICLR 2018)
Python
140
star
19

DRIT-Tensorflow

Simple Tensorflow implementation of "Diverse Image-to-Image Translation via Disentangled Representations" (ECCV 2018 Oral)
Python
117
star
20

StarGAN_v2-Tensorflow

Simple Tensorflow implementation of StarGAN_v2
Python
112
star
21

AMSGrad-Tensorflow

Simple Tensorflow implementation of "On the Convergence of Adam and Beyond" (ICLR 2018)
Python
103
star
22

RAdam-Tensorflow

Simple Tensorflow implementation of "On The Variance Of The Adaptive Learning Rate And Beyond"
Python
97
star
23

UNIT-Tensorflow

Simple Tensorflow implementation of "Unsupervised Image to Image Translation Networks" (NIPS 2017 Spotlight)
Python
96
star
24

Awesome-DeepLearning-Study

Summary of DeepLearning (Korean and English are included)
Python
93
star
25

partial_conv-Tensorflow

Simple Tensorflow implementation of "Partial Convolution based Padding" (partialconv)
Python
90
star
26

FusionGAN-Tensorflow

Simple Tensorflow implementation of FusionGAN (CVPR 2018)
Python
79
star
27

Tensorflow-DatasetAPI

Simple Tensorflow DatasetAPI Tutorial for reading image
Python
73
star
28

TripleGAN-Tensorflow

Simple Tensorflow implementation of Triple Generative Adversarial Nets (NIPS 2017)
Python
68
star
29

FUNIT-Tensorflow

Simple Tensorflow implementation of "Few-Shot Unsupervised Image-to-Image Translation" (ICCV 2019)
Python
65
star
30

SphereGAN-Tensorflow

Simple Tensorflow implementation of SphereGAN (CVPR 2019 Oral)
Python
57
star
31

GDWCT-Tensorflow

Simple Tensorflow implementation of "Image-to-Image Translation via Group-wise Deep Whitening-and-Coloring Transformation" (CVPR 2019 Oral)
Python
57
star
32

RelativisticGAN-Tensorflow

Simple Tensorflow implementation of RelativisticGAN
Python
51
star
33

AdamP-Tensorflow

Tensorflow Implementation of "Slowing Down the Weight Norm Increase in Momentum-based Optimizers"
Python
47
star
34

Batch_Instance_Normalization-Tensorflow

Simple Tensorflow implementation of Batch-Instance Normalization (NIPS 2018)
Python
40
star
35

GCNet-Tensorflow

Simple Tensorflow implementation of "GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond"
Python
39
star
36

Diffusion-Tensorflow

Tensorflow implementations of Diffusion models (DDPM, DDIM)
Python
37
star
37

CNN-Architecture-Summary

Simple Summary of CNN Architecture
34
star
38

tf-torch-template

Deep learning project template with tensorflow & pytorch (multi-gpu version)
Python
32
star
39

Switchable_Normalization-Tensorflow

Simple Tensorflow implementation of "Switchable Normalization"
Python
29
star
40

AdaConv-Tensorflow

Simple Tensorflow implementation of "Adaptive Convolutions for Structure-Aware Style Transfer" (CVPR 2021)
Python
26
star
41

AttnGAN-Tensorflow

Simple Tensorflow implementation of "AttnGAN: Fine-Grained Text to Image Generation with Attentional Generative Adversarial Networks" (CVPR 2018)
Python
26
star
42

CLIP-Tensorflow

Simple Tensorflow implementation of CLIP
Python
24
star
43

Image_similarity_with_elastic_search

Find the original image of the converted image with elastic search
Python
22
star
44

RealnessGAN-Tensorflow

Simple Tensorflow implementation of "RealnessGAN: Real or Not Real, that is the Question" (ICLR 2020 Spotlight)
Python
22
star
45

ControlGAN-Tensorflow

Simple Tensorflow implementation of "ControlGAN: Controllable Text-to-Image Generation" (NeurIPS 2019)
Python
19
star
46

CycleGAN-Tensorflow

Simple Tensorflow implementation of CycleGAN
Python
18
star
47

diffusion-pytorch

μ΄ν™”μ—¬λŒ€ κ°•μ˜μžλ£Œ
Python
18
star
48

SRM-Tensorflow

Simple Tensorflow implementation of "SRM : A Style-based Recalibration Module for Convolutional Neural Networks"
Python
18
star
49

GAN-Tensorflow

An implementation of GAN using TensorFlow
Python
17
star
50

SDIT-Tensorflow

Simple Tensorflow implementation of "SDIT: Scalable and Diverse Cross-domain Image Translation" (ACM-MM 2019)
Python
16
star
51

StableGAN-Tensorflow

Simple Tensorflow implementation of "Stabilizing Adversarial Nets With Prediction Methods" (ICLR 2018)
Python
16
star
52

Toward_spatial_unbiased-Tensorflow

Simple Tensorflow implementation of "Toward Spatially Unbiased Generative Models" (ICCV 2021)
Python
16
star
53

denoising-diffusion-gan-Tensorflow

Tensorflow implementation of "Tackling the Generative Learning Trilemma with Denoising Diffusion GANs" (ICLR 2022 Spotlight)
Python
15
star
54

MirrorGAN-Tensorflow

Simple Tensorflow implementation of "MirrorGAN: Learning Text-to-image Generation by Redescription" (CVPR 2019)
Python
15
star
55

Word2VecJava

Word2Vec In Java (2013 google word2vec opensource)
Java
14
star
56

StackGAN-Tensorflow

Simple Tensorflow implementation of "StackGAN: Text to Photo-realistic Image Synthesis with Stacked Generative Adversarial Networks" (ICCV 2017 Oral)
Python
13
star
57

MDGAN-Tensorflow

Simple Tensorflow implementation of "MDGAN: Mixture Density Generative Adversarial Networks" (CVPR 2019)
Python
11
star
58

DiscoGAN-Tensorflow

Simple Tensorflow implementation of DiscoGAN
Python
11
star
59

stylegan2-pytorch

Pytorch implementation of StyleGAN2 in my style
Python
11
star
60

pix2pix-Tensorflow

SImple Tensorflow implementations of " Image-to-Image Translation with Conditional Adversarial Networks" (CVPR 2017)
Python
11
star
61

DCGAN-Tensorflow

SImple Tensorflow implementation of "Deep Convolutional Generative Adversarial Networks"
Python
10
star
62

taki0112

8
star
63

coding_interview

Programmers coding interview in Korean
Python
8
star
64

CIPS-Tensorflow

Simple Tensorflow implementation of "Image Generators with Conditionally-Independent Pixel Synthesis" (CVPR 2021 Oral)
Python
7
star
65

Image_classification_CNN-Tensorflow

Classify dog and cat images of kaggle data
Python
7
star
66

TFIDF_Java

Get TF-IDF of Words
Java
4
star
67

CNN_Tensorflow

Convolutional Neural Network with Tensorflow, MNIST data
Python
4
star
68

grid_sample-Tensorflow

Tensorflow implementation of the grid_sample of pytorch.
Python
3
star
69

NiN-Tensorflow

Simple Tensorflow implementation of Network in Network
Python
2
star
70

Naver-Keyword_Analysis

Keyword Analysis from Naver Hack Day
Java
2
star
71

Deep-Q-network

Reinforcement study
Python
1
star
72

mnist_embedding

Python
1
star
73

Bamboo

1
star