当前位置:网站首页>torch.nn.functional.one_hot()
torch.nn.functional.one_hot()
2022-07-29 08:04:00 【00000cj】
参数
- tensor(LongTensor),任意shape的类别值
- num_classes(int),所有类别的数量。默认为-1,如果设为-1,num_classes=tensor中最大的值+1
定义
假设tensor的shape为( * ),函数返回shape为( *, num_classes)的tensor,返回的tensor中除了最后一维索引为tensor对应值位置为1,其它都为0。
示例
target1 = torch.tensor([1, 2, 3])
print(target1.shape) # torch.Size([3])
print(target1) # tensor([1, 2, 3])
target1 = torch.nn.functional.one_hot(target1, num_classes=5)
print(target1.shape) # torch.Size([3, 5])
print(target1)
# tensor([[0, 1, 0, 0, 0],
# [0, 0, 1, 0, 0],
# [0, 0, 0, 1, 0]])
target2 = torch.tensor([1, 2, 3])
target2 = torch.nn.functional.one_hot(target2)
print(target2.shape) # torch.Size([3, 4])
print(target2)
# tensor([[0, 1, 0, 0],
# [0, 0, 1, 0],
# [0, 0, 0, 1]])参考
边栏推荐
- [cryoelectron microscope | paper reading] interpretation of sub fault average m software: multi particle cryo EM refining with M
- 【学术相关】为什么很多国内学者的AI的论文复现不了?
- [cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging
- Day 014 2D array exercise
- Beautiful girls
- Arduino uno error analysis avrdude: stk500_ recv(): programmer is not responding
- Mysql rownum 实现
- Day 014 二维数组练习
- Autojs微信研究:微信自动发送信息机器人最终成品(有效果演示)
- 阿里巴巴政委体系-第三章、阿里政委与文化对接
猜你喜欢

Amaze UI icon query

Simplefoc+platformio stepping on the path of the pit
![[cryoEM] Introduction to FSC, Fourier shell correlation](/img/01/6a4f6041444abfd1d3ca7e0c14b524.png)
[cryoEM] Introduction to FSC, Fourier shell correlation

Tle5012b+stm32f103c8t6 (bluepill) reading angle data

Up sampling deconvolution operation

How to connect VMware virtual machine to external network under physical machine win10 system

Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇

Redshift 2.6.41 for maya2018 watermark removal

CentOS deploy PostgreSQL 13

LANDSCAPE
随机推荐
Official tutorial redshift 01 basic theoretical knowledge and basic characteristics learning
Resize2fs: bad magic number in super block
Measured waveform of boot capacitor short circuit and open circuit of buck circuit
As long as flutter is data, it will be judged null
[cryoEM] Introduction to FSC, Fourier shell correlation
Keyboard processing in jetpack compose
How to connect VMware virtual machine to external network under physical machine win10 system
[beauty of software engineering - column notes] 29 | automated testing: how to kill bugs in the cradle?
[beauty of software engineering - column notes] 26 | continuous delivery: how to release new versions to the production environment at any time?
Solving linear programming problems based on MATLAB
[memo] summary of the reasons why SSH failed? Remember to come next time.
Greenplus enterprise deployment
[密码学实验] 0x00 安装NTL库
阿里巴巴政委体系-第四章、政委建在连队上
Detailed explanation of the find command (the most common operation of operation and maintenance at the end of the article)
In an SQL file, a test table and data are defined above, and you can select* from the test table below
QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
An optimal buffer management scheme with dynamic thresholds paper summary
String class
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)