An warware: lodin samfurin pytorchand daskare

load modelland daskare A cikin duniyar yau, inganta aikin ฦ™irar injina ya zama muhimmin aiki ga masu haษ“akawa da masana kimiyyar bayanai. Wata hanyar da aka saba amfani da ita don yin haka ita ce ta hanyar amfani da dabarun "samfurin kaya" da "daskare" dabaru. A cikin wannan labarin, za mu tattauna yadda waษ—annan hanyoyin ke taimakawa wajen inganta samfurin, yadda ake aiwatar da su a Python, da wasu muhimman al'amura da suka shafi matsalar da aiwatarwa.

Load model da kuma daskare dabaru ne guda biyu waษ—anda za a iya amfani da su don haษ“aka aiki da inganci na ฦ™irar koyon injin. Na farko ya ฦ™unshi loda samfurin da aka riga aka horar don yin amfani da fasalulluka maimakon horar da sabon ฦ™ira daga karce, yayin da na ฦ™arshen yana nufin dakatar da sabunta wasu ma'aunin nauyi yayin aikin horo don tacewa da haษ“aka aikin ฦ™irar. Dukansu fasahohin suna taimakawa wajen rage wuce gona da iri kuma suna iya taimakawa gina ingantattun samfura masu inganci.

Aiwatar da Model Load da Daskare a Python

Domin aiwatar da samfurin lodi da kuma daskare dabarun yadda ya kamata, za mu fara buฦ™atar samun samfurin da aka riga aka horar a hannunmu. Don wannan misalin, za mu yi amfani da Python tare da shahararrun ษ—akunan karatu na koyon injin kamar TensorFlow da Keras don nuna matakan.

import tensorflow as tf
from tensorflow.keras import layers

# Load a pre-trained model
model = tf.keras.applications.VGG16(weights='imagenet', include_top=False)

# Set specific layers as non-trainable (frozen)
for layer in model.layers[:10]:
    layer.trainable = False

# Add custom layers on top of the pre-trained model
x = model.output
x = layers.GlobalAveragePooling2D()(x)
x = layers.Dense(1024, activation='relu')(x)
predictions = layers.Dense(10, activation='softmax')(x)

# Finalize the new model
custom_model = tf.keras.Model(inputs=model.input, outputs=predictions)

Ana Load da Samfuran da aka riga aka horar

The kaya model tsari yana farawa ta hanyar shigo da samfurin da aka riga aka horar, kamar VGG16, wanda aka horar da shi akan bayanan bayanan ImageNet. TensorFlow da Keras suna ba da madaidaiciyar hanyoyi don shigo da irin waษ—annan samfuran, kamar yadda aka gani a lambar da ke sama. Amfanin yin amfani da samfurin da aka riga aka horar shi ne cewa ya riga ya koyi abubuwan da suka dace daga babban bayanan bayanai, yana ba mu damar yin amfani da wannan ilimin yayin horar da tsarin mu na al'ada, da rage yawan lokaci da albarkatun lissafi.

Daskarewar Yadudduka da ฦ˜ara Yadudduka na Musamman

Da zarar an ษ—ora samfurin da aka riga aka horar, za mu iya ci gaba zuwa daskare takamaiman yadudduka na samfurin don hana su daga sabunta su yayin horo. A cikin wannan misalin, mun daskare yadudduka 10 na farko na samfurin VGG16, muna saita sifa ta "masu horo" zuwa ฦ˜arya. Daskare waษ—annan yadudduka yana ba samfurin damar riฦ™e abubuwan da aka koya a baya da kuma mai da hankali kan tace yadudduka na gaba don ingantaccen aiki.

Bayan daskarewa da yadudduka da ake so, sai mu ฦ™ara yadudduka na al'ada a saman samfurin da aka riga aka horar bisa ga bukatunmu. Aiwatar da mu tana nuna ฦ™ari na GlobalAveragePooling2D Layer wanda ke biye da yadudduka masu yawa waษ—anda ke aiki azaman yadudduka na fitarwa don ฦ™irar mu ta al'ada. A ฦ™arshe, muna haษ—a samfurin da aka riga aka horar da tsarin ฦ™irar mu na al'ada a cikin sabon ฦ™irar ta amfani da hanyar tf.keras.Model.

Ta hanyar amfani da samfurin lodi da daskare dabaru tare da Python, TensorFlow, da Keras, mun sami nasarar inganta aikin ฦ™irar mu. Wannan haษ—in kayan aiki masu ฦ™arfi da dabaru za su ba wa masana kimiyyar bayanai da masu haษ“akawa damar ฦ™irฦ™irar ingantattun samfuran koyo na inji waษ—anda suke daidai kuma masu dacewa da albarkatu.

Shafi posts:

Leave a Comment