使用TF实现DenseNet并在CIFAR10数据集上进行分类任务

基本介绍

ResNet通过建立前面层与后面层之间的“短路连接”来训练出更深的CNN模型和更高的准确度。而DenseNet与ResNet类似,但它建立的是前面所有层与后面层的密集连接。相比ResNet,DenseNet提出了更激进的密集连接方式,相互连接所有的层,每个层都会接受其前面所有层作为其额外的输入。
在这里插入图片描述

DenseNet代码实现
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from typing import List
import matplotlib.pyplot as plt

from tensorflow.keras.applications import imagenet_utils


# 实现DenseNet 根据blocks不同而产生不同的DenseNet(DenseNet161、DenseNet121)
def DenseNet(blocks: List, shape: tuple) -> keras.Model:
    img_input = layers.Input(shape=shape)
    x = layers.ZeroPadding2D(padding=((3, 3), (3, 3)))(img_input)  # padding-top, bottom, left, right
    x = layers.Conv2D(64, 7, strides=2, use_bias=False)(x)
    x = layers.BatchNormalization(axis=3, epsilon=EPSILON)(x)
    x = layers.Activation('relu')(x)
    x = layers.ZeroPadding2D(padding=((1, 1), (1, 1)))(x)
    x = layers.MaxPooling2D(3, strides=2)(x)

    x = dense_block(x, blocks[0])
    x = transition_block(x, 0.5)
    x = dense_block(x, blocks
  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sundial dreams

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值