{"id":21515829,"url":"https://github.com/taki0112/densenet-tensorflow","last_synced_at":"2025-10-24T19:41:11.589Z","repository":{"id":98365638,"uuid":"99529800","full_name":"taki0112/Densenet-Tensorflow","owner":"taki0112","description":"Simple Tensorflow implementation of Densenet using Cifar10, MNIST","archived":false,"fork":false,"pushed_at":"2019-03-04T09:04:40.000Z","size":1015,"stargazers_count":507,"open_issues_count":16,"forks_count":195,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-25T12:05:15.902Z","etag":null,"topics":["densenet","densenet-tensorflow","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/taki0112.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-08-07T02:44:26.000Z","updated_at":"2025-03-19T20:37:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"c2d47a5d-4a29-4777-ad1e-af79f1202af5","html_url":"https://github.com/taki0112/Densenet-Tensorflow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/taki0112/Densenet-Tensorflow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taki0112%2FDensenet-Tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taki0112%2FDensenet-Tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taki0112%2FDensenet-Tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taki0112%2FDensenet-Tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taki0112","download_url":"https://codeload.github.com/taki0112/Densenet-Tensorflow/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taki0112%2FDensenet-Tensorflow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280857754,"owners_count":26403192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["densenet","densenet-tensorflow","tensorflow"],"created_at":"2024-11-23T23:57:03.759Z","updated_at":"2025-10-24T19:41:11.584Z","avatar_url":"https://github.com/taki0112.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Densenet-Tensorflow\nTensorflow implementation of [Densenet](https://arxiv.org/abs/1608.06993) using **Cifar10, MNIST**\n* The code that implements *this paper* is ***Densenet.py***\n* There is a *slight difference*, I used ***AdamOptimizer***\n\nIf you want to see the ***original author's code*** or ***other implementations***, please refer to this [link](https://github.com/liuzhuang13/DenseNet)\n\n## Requirements\n* Tensorflow 1.x\n* Python 3.x\n* tflearn (If you are easy to use ***global average pooling***, you should install ***tflearn***\n```bash\nHowever, I implemented it using tf.layers, so don't worry\n```\n## Issue\n* I used ***tf.contrib.layers.batch_norm***\n```python\n    def Batch_Normalization(x, training, scope):\n        with arg_scope([batch_norm],\n                       scope=scope,\n                       updates_collections=None,\n                       decay=0.9,\n                       center=True,\n                       scale=True,\n                       zero_debias_moving_mean=True) :\n            return tf.cond(training,\n                           lambda : batch_norm(inputs=x, is_training=training, reuse=None),\n                           lambda : batch_norm(inputs=x, is_training=training, reuse=True))\n```\n\n* If not enough GPU memory, Please edit the code\n```python\nwith tf.Session() as sess : NO\nwith tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess : OK\n```\n\n* https://github.com/taki0112/Densenet-Tensorflow/issues/10\n\n## Idea\n### What is the \"Global Average Pooling\" ? \n```python\n    def Global_Average_Pooling(x, stride=1) :\n        width = np.shape(x)[1]\n        height = np.shape(x)[2]\n        pool_size = [width, height]\n        return tf.layers.average_pooling2d(inputs=x, pool_size=pool_size, strides=stride) \n        # The stride value does not matter\n````\n* If you use tflearn, please refer to this [link](http://tflearn.org/layers/conv/#global-average-pooling)\n```python\n    def Global_Average_Pooling(x):\n        return tflearn.layers.conv.global_avg_pool(x, name='Global_avg_pooling')\n```\n\n### What is the \"Dense Connectivity\" ?\n![Dense_connectivity](./assests/densenet.JPG)\n\n### What is the \"Densenet Architecture\" ?\n![Dense_Architecture](./assests/densenet_Archi.JPG)\n```python\n    def Dense_net(self, input_x):\n        x = conv_layer(input_x, filter=2 * self.filters, kernel=[7,7], stride=2, layer_name='conv0')\n        x = Max_Pooling(x, pool_size=[3,3], stride=2)\n\n        x = self.dense_block(input_x=x, nb_layers=6, layer_name='dense_1')\n        x = self.transition_layer(x, scope='trans_1')\n\n        x = self.dense_block(input_x=x, nb_layers=12, layer_name='dense_2')\n        x = self.transition_layer(x, scope='trans_2')\n\n        x = self.dense_block(input_x=x, nb_layers=48, layer_name='dense_3')\n        x = self.transition_layer(x, scope='trans_3')\n\n        x = self.dense_block(input_x=x, nb_layers=32, layer_name='dense_final') \n        \n        x = Batch_Normalization(x, training=self.training, scope='linear_batch')\n        x = Relu(x)\n        x = Global_Average_Pooling(x)\n        x = Linear(x)\n\n        return x\n```\n\n### What is the \"Dense Block\" ?\n![Dense_block](./assests/Denseblock.JPG)\n```python\n    def dense_block(self, input_x, nb_layers, layer_name):\n        with tf.name_scope(layer_name):\n            layers_concat = list()\n            layers_concat.append(input_x)\n\n            x = self.bottleneck_layer(input_x, scope=layer_name + '_bottleN_' + str(0))\n\n            layers_concat.append(x)\n\n            for i in range(nb_layers - 1):\n                x = Concatenation(layers_concat)\n                x = self.bottleneck_layer(x, scope=layer_name + '_bottleN_' + str(i + 1))\n                layers_concat.append(x)\n\n            x = Concatenation(layers_concat)\n            \n            return x\n```\n\n### What is the \"Bottleneck Layer\" ?\n```python\n    def bottleneck_layer(self, x, scope):\n        with tf.name_scope(scope):\n            x = Batch_Normalization(x, training=self.training, scope=scope+'_batch1')\n            x = Relu(x)\n            x = conv_layer(x, filter=4 * self.filters, kernel=[1,1], layer_name=scope+'_conv1')\n            x = Drop_out(x, rate=dropout_rate, training=self.training)\n\n            x = Batch_Normalization(x, training=self.training, scope=scope+'_batch2')\n            x = Relu(x)\n            x = conv_layer(x, filter=self.filters, kernel=[3,3], layer_name=scope+'_conv2')\n            x = Drop_out(x, rate=dropout_rate, training=self.training)\n            \n            return x\n```\n\n### What is the \"Transition Layer\" ?\n```python\n    def transition_layer(self, x, scope):\n        with tf.name_scope(scope):\n            x = Batch_Normalization(x, training=self.training, scope=scope+'_batch1')\n            x = Relu(x)\n            x = conv_layer(x, filter=self.filters, kernel=[1,1], layer_name=scope+'_conv1')\n            x = Drop_out(x, rate=dropout_rate, training=self.training)\n            x = Average_pooling(x, pool_size=[2,2], stride=2)\n\n            return x\n```\n\n## Compare Structure (CNN, ResNet, DenseNet)\n![compare](./assests/compare.JPG)\n\n## Results\n* (***MNIST***) The highest test accuracy is ***99.2%*** (This result does ***not use dropout***)\n* The number of dense block layers is fixed to ***4***\n```python\n    for i in range(self.nb_blocks) :\n        # original : 6 -\u003e 12 -\u003e 48\n\n        x = self.dense_block(input_x=x, nb_layers=4, layer_name='dense_'+str(i))\n        x = self.transition_layer(x, scope='trans_'+str(i))\n```\n\n### CIFAR-10\n![cifar_10](./assests/cifar_10_.JPG)\n\n### CIFAR-100\n![cifar_100](./assests/cifar_100_.JPG)\n\n### Image Net\n![image_net](./assests/Image_net_.JPG)\n\n## Related works\n* [ResNeXt-Tensorflow](https://github.com/taki0112/ResNeXt-Tensorflow)\n* [SENet-Tensorflow](https://github.com/taki0112/SENet-Tensorflow)\n* [ResNet-Tensorflow](https://github.com/taki0112/ResNet-Tensorflow)\n\n## References\n* [Korean](https://www.youtube.com/watch?v=fe2Vn0mwALI)\n* [English](https://www.youtube.com/watch?v=-W6y8xnd--U)\n* [Classification Datasets Results](http://rodrigob.github.io/are_we_there_yet/build/classification_datasets_results.html)\n\n## Author\nJunho Kim\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaki0112%2Fdensenet-tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaki0112%2Fdensenet-tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaki0112%2Fdensenet-tensorflow/lists"}