国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Keras可以使用的現(xiàn)有模型

這篇具有很好參考價(jià)值的文章主要介紹了Keras可以使用的現(xiàn)有模型。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

官網(wǎng):https://keras.io/api/applications/

Keras可以使用的現(xiàn)有模型,【Keras】,【計(jì)算機(jī)視覺】,keras,人工智能,深度學(xué)習(xí)Keras可以使用的現(xiàn)有模型,【Keras】,【計(jì)算機(jī)視覺】,keras,人工智能,深度學(xué)習(xí)

一些使用的列子:

?ResNet50:分類預(yù)測(cè)

import keras
from keras.applications.resnet50 import ResNet50
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np

model = ResNet50(weights='imagenet')

img_path = 'elephant.jpg'
img = keras.utils.load_img(img_path, target_size=(224, 224))
x = keras.utils.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

preds = model.predict(x)
# decode the results into a list of tuples (class, description, probability)
# (one such list for each sample in the batch)
print('Predicted:', decode_predictions(preds, top=3)[0])
# Predicted: [(u'n02504013', u'Indian_elephant', 0.82658225), (u'n01871265', u'tusker', 0.1122357), (u'n02504458', u'African_elephant', 0.061040461)]

VGG16:用作特征提取器時(shí),不需要最后的全連接層,所以實(shí)例化模型時(shí)參數(shù)?include_top=False

import keras
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input
import numpy as np

model = VGG16(weights='imagenet', include_top=False)

img_path = 'elephant.jpg'
img = keras.utils.load_img(img_path, target_size=(224, 224))
x = keras.utils.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

features = model.predict(x)

網(wǎng)上例子解釋:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-825599.html

from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import decode_predictions
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
from keras.utils.vis_utils import plot_model
import numpy as np

#加載VGG16模型,這里指定weights='imagenet'來(lái)自動(dòng)下載并加載預(yù)訓(xùn)練的模型參數(shù)
model = VGG16(weights='imagenet', include_top=True);
image_path = 'E:/dog.jpg';
#加載圖片,并且接企鵝為224*224
img = image.load_img(image_path, target_size=(224, 224));
#圖片轉(zhuǎn)為array格式
x = image.img_to_array(img)
#假設(shè)有一張灰度圖,讀取之后的shape是( 360, 480),而模型的輸入要求是( 1, 360 , 480 ) 或者是 ( 360 , 480 ,1 ),
# 那么可以通過np.expand_dims(a,axis=0)或者np.expand_dims(a,axis=-1)將形狀改變?yōu)闈M足模型的輸入
x = np.expand_dims(x, axis=0)
#對(duì)數(shù)據(jù)進(jìn)行歸一化處理x/255
x = preprocess_input(x)

#放入模型預(yù)測(cè)
features = model.predict(x)
#decode_predictions() 用于解碼ImageNet模型的預(yù)測(cè)結(jié)果,一般帶兩個(gè)參數(shù):features表示輸入批處理的預(yù)測(cè),top默認(rèn)是5,設(shè)置3表示返回3個(gè)概率最大的值
result = decode_predictions(features, top=3)

#展示結(jié)果,并且保存圖片
plot_model(model, 'E:/model.png', show_shapes=True)
print(result)

VGG19:

from keras.applications.vgg19 import VGG19
from keras.applications.vgg19 import preprocess_input
from keras.models import Model
import numpy as np

base_model = VGG19(weights='imagenet')
model = Model(inputs=base_model.input, outputs=base_model.get_layer('block4_pool').output)

img_path = 'elephant.jpg'
img = keras.utils.load_img(img_path, target_size=(224, 224))
x = keras.utils.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

block4_pool_features = model.predict(x)

Fine-tune InceptionV3:微調(diào)訓(xùn)練一個(gè)新類別

from keras.applications.inception_v3 import InceptionV3
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D

# create the base pre-trained model
base_model = InceptionV3(weights='imagenet', include_top=False)

# add a global spatial average pooling layer
x = base_model.output
x = GlobalAveragePooling2D()(x)
# let's add a fully-connected layer
x = Dense(1024, activation='relu')(x)
# and a logistic layer -- let's say we have 200 classes
predictions = Dense(200, activation='softmax')(x)

# this is the model we will train
model = Model(inputs=base_model.input, outputs=predictions)

# first: train only the top layers (which were randomly initialized)
# i.e. freeze all convolutional InceptionV3 layers
for layer in base_model.layers:
    layer.trainable = False

# compile the model (should be done *after* setting layers to non-trainable)
model.compile(optimizer='rmsprop', loss='categorical_crossentropy')

# train the model on the new data for a few epochs
model.fit(...)

# at this point, the top layers are well trained and we can start fine-tuning
# convolutional layers from inception V3. We will freeze the bottom N layers
# and train the remaining top layers.

# let's visualize layer names and layer indices to see how many layers
# we should freeze:
for i, layer in enumerate(base_model.layers):
   print(i, layer.name)

# we chose to train the top 2 inception blocks, i.e. we will freeze
# the first 249 layers and unfreeze the rest:
for layer in model.layers[:249]:
   layer.trainable = False
for layer in model.layers[249:]:
   layer.trainable = True

# we need to recompile the model for these modifications to take effect
# we use SGD with a low learning rate
from keras.optimizers import SGD
model.compile(optimizer=SGD(lr=0.0001, momentum=0.9), loss='categorical_crossentropy')

# we train our model again (this time fine-tuning the top 2 inception blocks
# alongside the top Dense layers
model.fit(...)

Build InceptionV3:自定義tensor,輸入V3

from keras.applications.inception_v3 import InceptionV3
from keras.layers import Input

# this could also be the output a different Keras model or layer
input_tensor = Input(shape=(224, 224, 3))

model = InceptionV3(input_tensor=input_tensor, weights='imagenet', include_top=True)

到了這里,關(guān)于Keras可以使用的現(xiàn)有模型的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【計(jì)算機(jī)視覺】DINOv2(視覺大模型)代碼使用和測(cè)試(完整的源代碼)

    【計(jì)算機(jī)視覺】DINOv2(視覺大模型)代碼使用和測(cè)試(完整的源代碼)

    輸出為: 命令是一個(gè)Git命令,用于克隆(Clone)名為\\\"dinov2\\\"的存儲(chǔ)庫(kù)。它使用了一個(gè)名為\\\"ghproxy.com\\\"的代理,用于加速GitHub的克隆操作。 我們需要切換為output的路徑: 以下是代碼的逐行中文解讀: 這段代碼的功能是對(duì)給定的圖像進(jìn)行一系列處理和特征提取,并使用PCA對(duì)特征進(jìn)

    2024年02月16日
    瀏覽(26)
  • Azure 機(jī)器學(xué)習(xí) - 使用 ONNX 對(duì)來(lái)自 AutoML 的計(jì)算機(jī)視覺模型進(jìn)行預(yù)測(cè)

    Azure 機(jī)器學(xué)習(xí) - 使用 ONNX 對(duì)來(lái)自 AutoML 的計(jì)算機(jī)視覺模型進(jìn)行預(yù)測(cè)

    本文介紹如何使用 Open Neural Network Exchange (ONNX) 對(duì)從 Azure 機(jī)器學(xué)習(xí)中的自動(dòng)機(jī)器學(xué)習(xí) (AutoML) 生成的計(jì)算機(jī)視覺模型進(jìn)行預(yù)測(cè)。 關(guān)注TechLead,分享AI全維度知識(shí)。作者擁有10+年互聯(lián)網(wǎng)服務(wù)架構(gòu)、AI產(chǎn)品研發(fā)經(jīng)驗(yàn)、團(tuán)隊(duì)管理經(jīng)驗(yàn),同濟(jì)本復(fù)旦碩,復(fù)旦機(jī)器人智能實(shí)驗(yàn)室成員,阿里云

    2024年02月05日
    瀏覽(15)
  • Azure 機(jī)器學(xué)習(xí) - 使用自動(dòng)化機(jī)器學(xué)習(xí)訓(xùn)練計(jì)算機(jī)視覺模型的數(shù)據(jù)架構(gòu)

    Azure 機(jī)器學(xué)習(xí) - 使用自動(dòng)化機(jī)器學(xué)習(xí)訓(xùn)練計(jì)算機(jī)視覺模型的數(shù)據(jù)架構(gòu)

    了解如何設(shè)置Azure Machine Learning JSONL 文件格式,以便在訓(xùn)練和推理期間在計(jì)算機(jī)視覺任務(wù)的自動(dòng)化 ML 實(shí)驗(yàn)中使用數(shù)據(jù)。 關(guān)注TechLead,分享AI全維度知識(shí)。作者擁有10+年互聯(lián)網(wǎng)服務(wù)架構(gòu)、AI產(chǎn)品研發(fā)經(jīng)驗(yàn)、團(tuán)隊(duì)管理經(jīng)驗(yàn),同濟(jì)本復(fù)旦碩,復(fù)旦機(jī)器人智能實(shí)驗(yàn)室成員,阿里云認(rèn)證的

    2024年02月05日
    瀏覽(26)
  • 計(jì)算機(jī)視覺:卷積核的參數(shù)可以通過反向傳播學(xué)習(xí)到嗎?

    計(jì)算機(jī)視覺:卷積核的參數(shù)可以通過反向傳播學(xué)習(xí)到嗎?

    在深度學(xué)習(xí)中,卷積神經(jīng)網(wǎng)絡(luò)(Convolutional Neural Networks, CNN)是一種常用的神經(jīng)網(wǎng)絡(luò)結(jié)構(gòu),其中卷積核是CNN的核心組件之一。卷積核是一個(gè)小矩陣,用于對(duì)輸入數(shù)據(jù)進(jìn)行卷積操作。卷積操作可以提取輸入數(shù)據(jù)的特征,通過不同的卷積核可以提取不同的特征。 ? 在前面課程中我

    2024年02月16日
    瀏覽(21)
  • Part1:使用 TensorFlow 和 Keras 的 NeRF計(jì)算機(jī)圖形學(xué)和深度學(xué)習(xí)——計(jì)算機(jī)圖形學(xué)世界中相機(jī)的工作原理

    Part1:使用 TensorFlow 和 Keras 的 NeRF計(jì)算機(jī)圖形學(xué)和深度學(xué)習(xí)——計(jì)算機(jī)圖形學(xué)世界中相機(jī)的工作原理

    是否有一種方法可以僅從一個(gè)場(chǎng)景多張不同視角的照片中捕獲整個(gè)3D場(chǎng)景? 有。 NeRF:將場(chǎng)景表示為用于視圖合成的神經(jīng)輻射場(chǎng)中(NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis),Mildenhall等人(2020)的論文解答了這個(gè)問題。NeRF的更簡(jiǎn)單實(shí)現(xiàn)贏得了 TensorFlow社區(qū)聚光

    2024年02月07日
    瀏覽(29)
  • 計(jì)算機(jī)視覺基礎(chǔ)知識(shí)(八)--點(diǎn)云模型

    計(jì)算機(jī)視覺基礎(chǔ)知識(shí)(八)--點(diǎn)云模型

    三維圖像 一種特殊的信息表達(dá)形式; 特征是表達(dá)的空間中有三個(gè)維度的數(shù)據(jù); 是對(duì)一類信息的統(tǒng)稱; 信息的表現(xiàn)形式: 深度圖:以灰度表達(dá)物體與相機(jī)的距離 幾何模型:由cad軟件建立 點(diǎn)云模型:所有逆向工程設(shè)備都將物體采樣為點(diǎn)云 和二維圖像相比; 三維圖像借助第三

    2024年01月25日
    瀏覽(24)
  • 【學(xué)習(xí)筆記】計(jì)算機(jī)視覺深度學(xué)習(xí)網(wǎng)絡(luò)模型

    【學(xué)習(xí)筆記】計(jì)算機(jī)視覺深度學(xué)習(xí)網(wǎng)絡(luò)模型

    這是本人學(xué)習(xí)計(jì)算機(jī)視覺CV領(lǐng)域深度學(xué)習(xí)模型的學(xué)習(xí)的一點(diǎn)點(diǎn)學(xué)習(xí)筆記,很多片子沒有完成,可以作為學(xué)習(xí)的參考~

    2024年04月10日
    瀏覽(43)
  • 計(jì)算機(jī)視覺領(lǐng)域經(jīng)典模型匯總(2023.09.08

    計(jì)算機(jī)視覺領(lǐng)域經(jīng)典模型匯總(2023.09.08

    一、RCNN系列 1、RCNN RCNN是用于目標(biāo)檢測(cè)的經(jīng)典方法,其核心思想是將目標(biāo)檢測(cè)任務(wù)分解為兩個(gè)主要步驟:候選區(qū)域生成和目標(biāo)分類。 候選區(qū)域生成:RCNN的第一步是生成可能包含目標(biāo)的候選區(qū)域,RCNN使用傳統(tǒng)的計(jì)算機(jī)視覺技術(shù),特別是 選擇性搜索(Selective Search)算法 ,這是一

    2024年02月09日
    瀏覽(24)
  • 數(shù)據(jù)增強(qiáng):讓計(jì)算機(jī)視覺模型更加智能和有效

    作者:禪與計(jì)算機(jī)程序設(shè)計(jì)藝術(shù) 引言 1.1. 背景介紹 隨著計(jì)算機(jī)視覺技術(shù)的快速發(fā)展,各種數(shù)據(jù)增強(qiáng)技術(shù)也應(yīng)運(yùn)而生。數(shù)據(jù)增強(qiáng)技術(shù)可以有效地提高計(jì)算機(jī)視覺模型的智能和有效性,從而在眾多應(yīng)用場(chǎng)景中取得更好的表現(xiàn)。 1.2. 文章目的 本文旨在闡述數(shù)據(jù)增強(qiáng)技術(shù)在計(jì)算機(jī)視

    2024年02月08日
    瀏覽(25)
  • 計(jì)算機(jī)視覺:比SAM快50倍的分割一切視覺模型FastSAM

    計(jì)算機(jī)視覺:比SAM快50倍的分割一切視覺模型FastSAM

    目錄 引言 1 FastSAM介紹 1.1 FastSAM誕生 1.2 模型算法 1.3 實(shí)驗(yàn)結(jié)果 2 FastSAM運(yùn)行環(huán)境構(gòu)建 2.1 conda環(huán)境構(gòu)建 2.2 運(yùn)行環(huán)境安裝 2.3 模型下載 3 FastSAM運(yùn)行 3.1 命令行運(yùn)行 3.1.1 Everything mode ?3.1.2 Text prompt 3.1.3 Box prompt (xywh) 3.1.4 Points prompt ?3.2 通過代碼調(diào)用 4 總結(jié) MetaAI提出的能夠“分割一切

    2024年02月11日
    瀏覽(29)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包