飞桨图像分割7日打卡训练营学习笔记class1 basic_model.py

飞桨图像分割7日打卡训练营学习笔记

课程介绍
顶会论文审稿人亲自授课,从基础理论到前沿技术,配套5次实战打卡,带你入门到精通,7日攻克图像分割。从经典算法到学界前沿,从技术细节到完整流程,语义分割、实例分割、全景分割,带你逐个击破。

环境搭配

Baidu AI Studio
框架版本 : Paddle 18.4, Python 3.7
网址: https://aistudio.baidu.com
Local Env:
使用Conda安装 Paddle1.8
网址: https://www.paddlepaddle.org.cn
手把手教你 win10 安装Paddlepaddle-GPU:https://aistudio.baidu.com/aistudio/projectdetail/696822

class1 basic_model.py

import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph import to_variable #TODO数据矩阵转换成一行数据
from paddle.fluid.dygraph import Conv2D#TODO卷积函数
from paddle.fluid.dygraph import Pool2D#TODO池化操作函数
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) #TODO
        self.conv = Conv2D(num_channels=3, num_filters=num_classes,filter_size=1)#TODO

    def forward(self, inputs):
        x = self.pool(inputs)#TODO 
        x = fluid.layers.interpolate(x, out_shape=(inputs.shape[2], inputs.shape[3]))
        x = self.conv(x)#TODO 
        return x

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

if __name__ == "__main__":
    main()

学习心得
通过这次学习对图像分割有基本的认识和了解,可以使用开源的库来实现某种算法,从而解决问题。非常感谢百度研发老师的详细讲解图像分割的相关网络,现场逐行coding代码,比较通俗易懂。非常感谢百度研发老师的详细讲解图像分割的相关网络,现场逐行coding代码,比较通俗易懂。对图像分割有了很好的入门,百度提供的飞桨(PaddlePaddle)用于图像分割非常方便,效率很高。
而且ai studio的平台也提供了免费的算力运算,为一般业余爱好者提供了测试,运行的平台。
课程链接:https://aistudio.baidu.com/aistudio/education/group/info/1767。

你可能感兴趣的:(神经网络,深度学习)