創(chuàng)新互聯(lián)www.cdcxhl.cn八線(xiàn)動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買(mǎi)多久送多久,劃算不套路!
這篇文章主要介紹keras提供了三種定義模型方式分別是什么,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
前言
一、keras提供了三種定義模型的方式
1. 序列式(Sequential) API
序貫(sequential)API允許你為大多數(shù)問(wèn)題逐層堆疊創(chuàng)建模型。雖然說(shuō)對(duì)很多的應(yīng)用來(lái)說(shuō),這樣的一個(gè)手法很簡(jiǎn)單也解決了很多深度學(xué)習(xí)網(wǎng)絡(luò)結(jié)構(gòu)的構(gòu)建,但是它也有限制-它不允許你創(chuàng)建模型有共享層或有多個(gè)輸入或輸出的網(wǎng)絡(luò)。
2. 函數(shù)式(Functional) API
Keras函數(shù)式(functional)API為構(gòu)建網(wǎng)絡(luò)模型提供了更為靈活的方式。
它允許你定義多個(gè)輸入或輸出模型以及共享圖層的模型。除此之外,它允許你定義動(dòng)態(tài)(ad-hoc)的非周期性(acyclic)網(wǎng)絡(luò)圖。
模型是通過(guò)創(chuàng)建層的實(shí)例(layer instances)并將它們直接相互連接成對(duì)來(lái)定義的,然后定義一個(gè)模型(model)來(lái)指定那些層是要作為這個(gè)模型的輸入和輸出。
3.子類(lèi)(Subclassing) API
補(bǔ)充知識(shí):keras pytorch 構(gòu)建模型對(duì)比
使用CIFAR10數(shù)據(jù)集,用三種框架構(gòu)建Residual_Network作為例子,比較框架間的異同。
數(shù)據(jù)集格式
pytorch的數(shù)據(jù)集格式
import torch import torch.nn as nn import torchvision # Download and construct CIFAR-10 dataset. train_dataset = torchvision.datasets.CIFAR10(root='../../data/', train=True, download=True) # Fetch one data pair (read data from disk). image, label = train_dataset[0] print (image.size()) # torch.Size([3, 32, 32]) print (label) # 6 print (train_dataset.data.shape) # (50000, 32, 32, 3) # type(train_dataset.targets)==list print (len(train_dataset.targets)) # 50000 # Data loader (this provides queues and threads in a very simple way). train_loader = torch.utils.data.DataLoader(dataset=train_dataset, batch_size=64, shuffle=True) """ # 演示DataLoader返回的數(shù)據(jù)結(jié)構(gòu) # When iteration starts, queue and thread start to load data from files. data_iter = iter(train_loader) # Mini-batch images and labels. images, labels = data_iter.next() print(images.shape) # torch.Size([100, 3, 32, 32]) print(labels.shape) # torch.Size([100]) 可見(jiàn)經(jīng)過(guò)DataLoader后,labels由list變成了pytorch內(nèi)置的tensor格式 """ # 一般使用的話(huà)是下面這種 # Actual usage of the data loader is as below. for images, labels in train_loader: # Training code should be written here. pass
網(wǎng)站標(biāo)題:keras提供了三種定義模型方式分別是什么-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://www.chinadenli.net/article8/dgioip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)站改版、域名注冊(cè)、網(wǎng)站策劃、小程序開(kāi)發(fā)、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容