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.