Image Segmentation with U-Net(吴恩达课程)
Image Segmentation with U-Net(吴恩达课程)
# UNQ_C1
# GRADED FUNCTION: conv_block
def conv_block(inputs=None, n_filters=32, dropout_prob=0, max_pooling=True):"""Convolutional downsampling blockArguments:inputs -- Input tensorn_filters -- Number of filters for the convolutional layersdropout_prob -- Dropout probabilitymax_pooling -- Use MaxPooling2D to reduce the spatial dimensions of the output volumeReturns: next_layer, skip_connection -- Next layer and skip connection outputs"""### START CODE HEREconv = Conv2D(n_filters, # Number of filters3, # Kernel size activation='relu',padding='same',kernel_initializer='he_normal')(inputs)conv = Conv2D(n_filters, # Number of filters3, # Kernel sizeactivation='relu',padding='same',kernel_initializer='he_normal')(conv)### END CODE HERE# if dropout_prob > 0 add a dropout layer, with the variable dropout_prob as parameterif dropout_prob > 0:### START CODE HEREconv = Dropout(rate=dropout_prob)(conv)### END CODE HERE# if max_pooling is True add a MaxPooling2D with 2x2 pool_sizeif max_pooling:### START CODE HEREnext_layer = MaxPooling2D(2,2)(conv)### END CODE HEREelse:next_layer = convskip_connection = convreturn next_layer, skip_connection
# UNQ_C2
# GRADED FUNCTION: upsampling_block
def upsampling_block(expansive_input, contractive_input, n_filters=32):"""Convolutional upsampling blockArguments:expansive_input -- Input tensor from previous layercontractive_input -- Input tensor from previous skip layern_filters -- Number of filters for the convolutional layersReturns: conv -- Tensor output"""### START CODE HEREup = Conv2DTranspose(n_filters, # number of filters3, # Kernel sizestrides=2,padding='same')(expansive_input)# Merge the previous output and the contractive_inputmerge = concatenate([up, contractive_input], axis=3)conv = Conv2D(n_filters, # Number of filters3, # Kernel sizeactivation='relu',padding='same',kernel_initializer='he_normal')(merge)conv = Conv2D(n_filters, # Number of filters3, # Kernel sizeactivation='relu',padding='same',kernel_initializer='he_normal')(conv)### END CODE HEREreturn conv
# UNQ_C3
# GRADED FUNCTION: unet_model
def unet_model(input_size=(96, 128, 3), n_filters=32, n_classes=23):"""Unet modelArguments:input_size -- Input shape n_filters -- Number of filters for the convolutional layersn_classes -- Number of output classesReturns: model -- tf.keras.Model"""inputs = Input(input_size)# Contracting Path (encoding)# Add a conv_block with the inputs of the unet_ model and n_filters### START CODE HEREcblock1 = conv_block(inputs, n_filters)# Chain the first element of the output of each block to be the input of the next conv_block. # Double the number of filters at each new stepcblock2 = conv_block(cblock1[0], n_filters*2)cblock3 = conv_block(cblock2[0], n_filters*4)cblock4 = conv_block(cblock3[0], n_filters*8, dropout_prob=0.3) # Include a dropout of 0.3 for this layer# Include a dropout of 0.3 for this layer, and avoid the max_pooling layercblock5 = conv_block(cblock4[0], n_filters*16, dropout_prob=0.3, max_pooling=False) ### END CODE HERE# Expanding Path (decoding)# Add the first upsampling_block.# Use the cblock5[0] as expansive_input and cblock4[1] as contractive_input and n_filters * 8### START CODE HEREublock6 = upsampling_block(cblock5[0], cblock4[1], n_filters * 8)# Chain the output of the previous block as expansive_input and the corresponding contractive block output.# Note that you must use the second element of the contractive block i.e before the maxpooling layer. # At each step, use half the number of filters of the previous block ublock7 = upsampling_block(ublock6, cblock3[1], n_filters * 4)ublock8 = upsampling_block(ublock7, cblock2[1], n_filters * 2)ublock9 = upsampling_block(ublock8, cblock1[1], n_filters)### END CODE HEREconv9 = Conv2D(n_filters,3,activation='relu',padding='same',kernel_initializer='he_normal')(ublock9)# Add a Conv2D layer with n_classes filter, kernel size of 1 and a 'same' padding### START CODE HEREconv10 = Conv2D(n_classes, 1, padding='same')(conv9)### END CODE HEREmodel = tf.keras.Model(inputs=inputs, outputs=conv10)return model
Image Segmentation with U-Net(吴恩达课程)相关推荐
- Ex6_机器学习_吴恩达课程作业(Python):SVM支持向量机(Support Vector Machines)
Ex6_机器学习_吴恩达课程作业(Python):SVM支持向量机(Support Vector Machines) 文章目录 Ex6_机器学习_吴恩达课程作业(Python):SVM支持向量机(Su ...
- Residual Networks(吴恩达课程)
Residual Networks(吴恩达课程) # UNQ_C1 # GRADED FUNCTION: identity_blockdef identity_block(X, f, filters, ...
- Deep Learning Art: Neural Style Transfer(吴恩达课程)
Deep Learning & Art: Neural Style Transfer(吴恩达课程) # UNQ_C1 # GRADED FUNCTION: compute_content_co ...
- Transfer Learning with MobileNetV2(吴恩达课程)
Transfer Learning with MobileNetV2(吴恩达课程) # UNQ_C1 # GRADED FUNCTION: data_augmenter def data_augmen ...
- Autonomous Driving - Car Detection(吴恩达课程)
Autonomous Driving - Car Detection(吴恩达课程) # UNQ_C1 (UNIQUE CELL IDENTIFIER, DO NOT EDIT) # GRADED FU ...
- 干货|机器学习零基础?不要怕,吴恩达课程笔记第三周!逻辑回归与正则
吴恩达Coursera机器学习课系列笔记 课程笔记|吴恩达Coursera机器学习 Week1 笔记-机器学习基础 干货|机器学习零基础?不要怕,吴恩达机器学习课程笔记2-多元线性回归 1 Logis ...
- 吴恩达课程翻译_中文学习资源:斯坦福大学CS231n计算机视觉课程
hi,我是为你们的xio习操碎了心的和鲸社区男运营 我们的网站:和鲸社区 Kesci.co 我们的公众号:和鲸社区(ID:heywhale-kesci) 有干货,来! 大家好,此次本鲸给大家翻译的项目 ...
- 吴恩达课程及视频笔记汇总
马克一记https://zhuanlan.zhihu.com/p/30870804 转载于:https://www.cnblogs.com/573177885qq/p/7852564.html
- 【CNN】 吴恩达课程中几种网络的比较
LeNet5 AlexNet VGG16 ResNet : 残差网络 Inception Net : 特点,可以通过1*1*192 的卷积核来缩减参数个数,压缩维度,约缩减10倍, 例如 :用1 ...
最新文章
- mysql slave lock 跳过_处理 MySQL 因为 SLAVE 崩溃导致需要手动跳过 GTID 的问题 | 关于 GTID...
- oracle易忘函数用法(6)
- 用计算机数字技术制作的电影是,如何面对电影制作中的数字技术
- 如何在ASP.NET Core程序启动时运行异步任务(1)
- Python遍历破解FTP密码,并上传webshell
- [转载] Java7中增加的新特性
- cobbler装系统
- html超链接图标图片,HTML-标签:图片 超链接
- 决策树算法总结(下:CART决策树)
- HTML标签常用标签
- python报IndentationError: unexpected indent的解决方法.
- 山东教师教育网-404、登录、密码找回、常见问题、绑定已有账户
- 如何删除PDF空白签名域?
- 海思对接索尼ECX334 RGB OLED屏总结
- 关于数组的引用和引用的数组
- 可视化工具--Plotly
- 开源协议是什么?有哪些?如何选择?
- 京东到家库存设计(分布式系统)笔记
- 使用Hprose制作一个简单的分布式应用程序
- Unity实现体积雾与体积光