1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Gluon API深度學(xué)習(xí)庫(kù)

        聯(lián)合創(chuàng)作 · 2023-09-26 04:16

        Gluon 是微軟聯(lián)合亞馬遜推出的一個(gè)開源深度學(xué)習(xí)庫(kù),這是一個(gè)清晰、簡(jiǎn)潔、簡(jiǎn)單但功能強(qiáng)大的深度學(xué)習(xí) API,該規(guī)范可以提升開發(fā)人員學(xué)習(xí)深度學(xué)習(xí)的速度,而無(wú)需關(guān)心所選擇的深度學(xué)習(xí)框架。Gluon API 提供了靈活的接口來(lái)簡(jiǎn)化深度學(xué)習(xí)原型設(shè)計(jì)、創(chuàng)建、訓(xùn)練以及部署,而且不會(huì)犧牲數(shù)據(jù)訓(xùn)練的速度。

        Gluon 規(guī)范已經(jīng)在 Apache MXNet 中實(shí)現(xiàn),只需要安裝最新的 MXNet 即可使用。推薦使用 Python 3.3 或者更新版本。

        主要優(yōu)勢(shì)包括:

        • 代碼簡(jiǎn)單,易于理解

        • 靈活,命令式結(jié)構(gòu): 不需要嚴(yán)格定義神經(jīng)網(wǎng)絡(luò)模型,而是將訓(xùn)練算法和模型更緊密地結(jié)合起來(lái),開發(fā)靈活

        • 動(dòng)態(tài)圖: Gluon 可以讓開發(fā)者動(dòng)態(tài)的定義神經(jīng)網(wǎng)絡(luò)模型,這意味著他們可以在運(yùn)行時(shí)創(chuàng)建模型、結(jié)構(gòu),以及使用任何 Python 原生的控制流

        • 高性能: Gluon 所提供的這些優(yōu)勢(shì)對(duì)底層引擎的訓(xùn)練速度并沒有任何影響

        示例代碼:

        import mxnet as mx
        from mxnet import gluon, autograd, ndarray
        import numpy as np
        
        train_data = mx.gluon.data.DataLoader(mx.gluon.data.vision.MNIST(train=True, 
        			transform=lambda data, label: (data.astype(np.float32)/255, label)),
                    batch_size=32, shuffle=True)
        test_data = mx.gluon.data.DataLoader(mx.gluon.data.vision.MNIST(train=False, 
        			transform=lambda data, label: (data.astype(np.float32)/255, label)),
                    batch_size=32, shuffle=False)                     
        
        # First step is to initialize your model
        net = gluon.nn.Sequential()
        # Then, define your model architecture
        with net.name_scope():
            net.add(gluon.nn.Dense(128, activation="relu")) # 1st layer - 128 nodes
            net.add(gluon.nn.Dense(64, activation="relu")) # 2nd layer – 64 nodes
            net.add(gluon.nn.Dense(10)) # Output layer
        
        # We start with random values for all of the model’s parameters from a
        # normal distribution with a standard deviation of 0.05
        net.collect_params().initialize(mx.init.Normal(sigma=0.05))
        
        # We opt to use softmax cross entropy loss function to measure how well the # model is able to predict the correct answer
        softmax_cross_entropy = gluon.loss.SoftmaxCrossEntropyLoss()
        
        # We opt to use the stochastic gradient descent (sgd) training algorithm
        # and set the learning rate hyperparameter to .1
        trainer = gluon.Trainer(net.collect_params(), 'sgd', {'learning_rate': .1})
        
        epochs = 10
        for e in range(epochs):
            for i, (data, label) in enumerate(train_data):
                data = data.as_in_context(mx.cpu()).reshape((-1, 784))
                label = label.as_in_context(mx.cpu())
                with autograd.record(): # Start recording the derivatives
                    output = net(data) # the forward iteration
                    loss = softmax_cross_entropy(output, label)
                    loss.backward()
                trainer.step(data.shape[0])
                # Provide stats on the improvement of the model over each epoch
                curr_loss = ndarray.mean(loss).asscalar()
            print("Epoch {}. Current Loss: {}.".format(e, curr_loss))
        瀏覽 14
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            色秘 乱码一区二区三区在线看 | 色国产精品一区在线观看 | 豆花视频网 | 色综合区| 狠狠亲狠狠操 | 久久精品国产亚洲aⅴ瑜伽 | 大陆少妇bbwbbw高潮 | 国色天香综合网 | 黄色视频网站在线观看视频 | 日韩成人无码一区二区 |