百度飞桨图像分割7日打卡营学习笔记(一、图像分割综述)

百度飞桨图像分割7日打卡营学习笔记(一、图像分割综述)

此次课程是百度飞桨邀请全球顶会论文审稿人亲自授课,从基础理论到前沿技术,并且全直播手把手理论指导+现场逐行coding,是一个很不错的学习机会。

在这里插入图片描述
下面这段代码简单的实现了语义分割的操作

import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph import to_variable
from paddle.fluid.dygraph import Conv2D
from paddle.fluid.dygraph import Pool2D
import numpy as np
np.set_printoptions(precision=2)


class BasicModel(fluid.dygraph.Layer):
    # BasicModel contains:
    # 1. pool:   4x4 max pool op, with stride 4
    # 2. conv:   3x3 kernel size, takes RGB image as input and output num_classes channels,
    #            note that the feature map size should be the same
    # 3. upsample: upsample to input size
    #
    # TODOs:
    # 1. The model takes an random input tensor with shape (1, 3, 8, 8)
    # 2. The model outputs a tensor with same HxW size of the input, but C = num_classes
    # 3. Print out the model output in numpy format 

    def __init__(self, num_classes=59):
        super(BasicModel, self).__init__()
        self.pool = Pool2D(pool_size=4, pool_stride=4)
        self.conv = Conv2D(num_channels=3, num_filters=1,filter_size=1)
    def forward(self, inputs):
        x = self.pool(inputs)
        x = fluid.layers.interpolate(x, out_shape=(inputs.shape[2], inputs.shape[3]))
        x = self.conv(x)
        return x

def main():
    place = paddle.fluid.CPUPlace()
    with fluid.dygraph.guard(place):
        model = BasicModel(num_classes=59)
        model.eval()
        input_data = np.random.rand(1,3,8,8).astype(np.float32)
        print('Input data shape: ', input_data.shape)
        input_data = to_variable(input_data)
        output_data = model(input_data)
        output_data = output_data.numpy()
        print('Output data shape: ', output_data.shape)

if __name__ == "__main__":
    main()

Input data shape: (1, 3, 8, 8)
Output data shape: (1, 1, 8, 8)

哈哈!课程在这里(是免费的哦),想了解的小伙伴可以试试。
https://aistudio.baidu.com/aistudio/course/introduce/1767?directly=1&shared=1

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值