Beginning Anomaly Detection Using


LPSRUW WRUFK LPSRUW



Download 26,57 Mb.
Pdf ko'rish
bet253/283
Sana12.07.2021
Hajmi26,57 Mb.
#116397
1   ...   249   250   251   252   253   254   255   256   ...   283
Bog'liq
Beginning Anomaly Detection Using Python-Based Deep Learning

LPSRUW

WRUFK


LPSRUW

WRUFKQQ



DV

QQ

LPSRUW

WRUFKYLVLRQ

LPSRUW

WRUFKYLVLRQWUDQVIRUPV



DV

WUDQVIRUPV



LPSRUW

WRUFKRSWLP



DV

RSWLP


LPSRUW

WRUFKQQIXQFWLRQDO



DV

)

LPSRUW

QXPS\

DV

QS

GHYLFH WRUFKGHYLFH FXGD 



LI

WRUFKFXGDLVBDYDLODEOH 



HOVH

FSX


Figure B-3.  Importing the basic modules needed to create your network

Figure B-4.  The code in Figure 

B-3

 in a Jupyter cell

appendix B   intro to pytorch




366

FODVV

&11 QQ0RGXOH 



GHI

BBLQLWBB VHOI 

VXSHU

&11VHOI BBLQLWBB



VHOIFRQY QQ&RQYG 

VHOIFRQY QQ&RQYG 

VHOIGHQVH QQ/LQHDU   

VHOIGHQVH QQ/LQHDU QXPBFODVVHV



GHI

IRUZDUG VHOI[ 

[ )UHOX VHOIFRQY [

[ )UHOX VHOIFRQY [

[ )PD[BSRROG [

[ )GURSRXW [

[ [YLHZ   

[ )UHOX VHOIGHQVH [

[ )GURSRXW [

[ VHOIGHQVH [



UHWXUQ

)ORJBVRIWPD[ [GLP 



Figure B-5.  Defining the model

appendix B   intro to pytorch




367

With that out of the way, you can define both the training and testing functions (see 

Figure 

B-7


 and Figure 

B-8


 for the training function, and Figure 

B-9


 and Figure 

B-10


 for 

the testing function).



Figure B-6.  The code in Figure 

B-5

 in a Jupyter cell

appendix B   intro to pytorch




368

GHI

WUDLQ PRGHOGHYLFHWUDLQBORDGHUFULWHULRQRSWLPL]HUHSRFK

VDYHBGLU PRGHOFNSW 

WRWDOBVWHS OHQ WUDLQBORDGHU



IRU

L LPDJHVODEHOV 



LQ HQXPHUDWH

WUDLQBORDGHU 

LPDJHV LPDJHVWR GHYLFH

ODEHOV  ODEHOVWR GHYLFH

)RUZDUGSDVV

RXWSXWV PRGHO LPDJHV

ORVV FULWHULRQ RXWSXWVODEHOV

%DFNZDUGDQGRSWLPL]H

RSWLPL]HU]HURBJUDG

ORVVEDFNZDUG

RSWLPL]HUVWHS

LI

L   

SULQW

(SRFK>^`^`@6WHS>^`^`@/RVV



^I` IRUPDW HSRFKQXPBHSRFKVLWRWDOBVWHSORVVLWHP

WRUFKVDYH PRGHOVWDWHBGLFW  S\WRUFKBPQLVWBFQQFNSW



Figure B-7.  The training algorithm. The for loop takes each pair of image and 

labels and passes them into the GPU as a tensor. They then go into the model, and 

the gradients are calculated. The information about the epoch and loss are then 

output

appendix B   intro to pytorch




369

The training function takes in the following parameters:

• 

model: An instance of a model class. In this case, it’s an instance of 

the CNN class defined above.

• 

device: This basically tells PyTorch what device (if the GPU is an 

option, which GPU to run on, and if not, the CPU is the device) to run 

on. In this case, you define the device right after the imports.

• 

train_loader: The loader for the training data set. In this case, you 

use a data_loader because that’s how the MNIST data is formatted 

when importing from torchvision. This data loader contains the 

training samples for the MNIST data set.

• 

criterion: The loss function to use. Define this before calling the train 

function.

• 

optimizer: The optimization function to use. Define this before 

calling the train function.

• 

epoch: What epoch is running. In this case, you call the training 

function in a for loop while passing in the iteration as the epoch.

The testing function is shown in Figure 

B-9

 and Figure 



B-10

.

Figure B-8.  The code in Figure 



B-7

 in a Jupyter cell

appendix B   intro to pytorch




370


Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   249   250   251   252   253   254   255   256   ...   283




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish