当前位置:网站首页>Deep learning and image recognition: principle and practice notes day_ ten
Deep learning and image recognition: principle and practice notes day_ ten
2022-04-22 03:24:00 【Effort volume】
optimization
The goal of optimization : Find a series of weights that minimize the value of the loss function w
Random initialization
import torch
from torch.utils.data import DataLoader
import torchvision.datasets as dsets
import torchvision.transforms as transforms
import numpy as np
class_num = 10
batch_size = 4
label = torch.LongTensor(batch_size, 1).random_() % class_num
print(label)
# hold Tensor convert to one_hot scatter_(1,label,1) Indicating taking 1 according to label Matrix to right zeros The matrix is filled with columns
ont_hot = torch.zeros(batch_size,class_num).scatter_(1,label,1)
print('---')
print(ont_hot)
Gradient descent method
The code implementation is as follows :
def gradient_descent(f, init_X,lr=0.01,step_num=100):
x = init_X
for i in range(step_num):
grad = numberical_gradient(f,x)
x =-= lr*grad
return x
Parameters f It's a function to optimize ,init_x Is the initial value ,lr It means the learning rate ,step_num Represents the number of repetitions of the gradient descent method
Add concept :Np.nditer
The code is as follows :
import numpy as np
arr1 = np.arange(0,30,5).reshape(2,3)
it = np.nditer(arr1, flags=['multi_index'], op_flags=['readwrite'])
while not it.finished:
print(it.multi_index)
it.iternext()
Running results :

op_flags=['readwrite'] Means not only to a To read , You can also write
print(it.multi_index) Represents the index of the output element
it.iternext() Indicates entering the next iteration
版权声明
本文为[Effort volume]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211347167598.html
边栏推荐
- Bad config encountered during initialization:/ No such notebook dir:
- Ink back words -- extract all its offline words through the installation package
- Understanding and analyzing log files
- Memory distribution of stm32
- Nacos access message 404
- 吉他樂理整理
- Saas. Extended field custom field
- Polyfill是什么?
- Web automation master card in file upload and pop-up processing?
- Finition musicale de guitare
猜你喜欢
![[NCTF2019]Fake XML cookbook](/img/55/b0f996fd1db2792c14444bcba39377.png)
[NCTF2019]Fake XML cookbook

Unmanned virtual simulation (XV) -- obstacle detection and recognition 1

leetcode:297. Serialization and deserialization of binary tree

C language multiplication table

Ali II: can the main method be inherited?

How to take sonar as an example to create a test step applicable to all enterprises
![[7:00 pm tonight] discussion on the development and application scenarios of metartc](/img/58/965e9bd295e34c4b37cd00aada2120.jpg)
[7:00 pm tonight] discussion on the development and application scenarios of metartc

【云计算】3台虚拟机完成Spark Yarn集群部署并编写Scala应用程序实现单词计数统计

The original test engineers who were promoted and raised were good at interface testing

Pytest automated testing framework (2)
随机推荐
Chapter 9 introduction to kernel synchronization
Guitar music theory finishing
Multithreaded deadlock use case
Bad config encountered during initialization:/ No such notebook dir:
Category 7 sorting summary insertion selection exchange quick sorting merge sorting quick rush
Zabbix5 series - monitor Huawei and H3C switches (snmpv2c / SNMPv3 / snmptrap) (II)
linux安装MySQL
Quantitative evaluation rules for security evaluation of commercial password applications (2021 Edition)
C language daily question -- [noip2008] ISBN number (question 76 of niuke.com)
TP5 is making QR code
Can Chrome browser + postman do interface testing like this?
Record of problems in socket multicast
Allegro Gerber file path setting
关于TP5出现的一些错误
Sword finger offer special breakthrough version 91. Painting the house
[wustctf2020] plain
吉他乐理整理
1 ActiveMQ introduction and installation
Cognitive system services
TP5使用phpoffice/phpexcel包操作excel(导出)