当前位置:网站首页>Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
2022-07-03 02:43:00 【strawberry47】
Recorded will tensorflow turn pytorch when , Some commonly used function conversions :
Can't convert directly
tf.transpose(input,[1, 0, 2])->input.permute([1, 0, 2])It cannot be directly replaced bytorch.transpose, Because you can't operate multidimensionaltf.expand_dims(input), axis=1)->input.unsqueeze(1)tf.concat([content1,content2], axis=1->torch.cat((content1,content2), dim=1)Remember to axis Switch to dimtf.tile(input, [2, 1])->input.repeat([2, 1])tf.range(10)->torch.arange(0)tf.reduce_sum(x, axis=1, keep_dims=True)->torch.sum(x,dim=1,keepdim=True)tf.clip_by_value(x, min, max)->torch.clamp(x, min, max)tf.multinomial(logits=a, num_samples=1)->torch.multinomial(input=a, num_samples=1, replacement=False)tf.equal(x, y)->torch.eq(x, y)tf.nn.embedding_lookup(W_fe, Feature_input + 1)->torch.index_select(W_fe, 0, Feature_input + 1)tf.one_hot()->functional.one_hot()
tf.gather_nd(x,y) transformation
def gather_nd(self,params, indices):
''' 4D example params: tensor shaped [n_1, n_2, n_3, n_4] --> 4 dimensional indices: tensor shaped [m_1, m_2, m_3, m_4, 4] --> multidimensional list of 4D indices returns: tensor shaped [m_1, m_2, m_3, m_4] ND_example params: tensor shaped [n_1, ..., n_p] --> d-dimensional tensor indices: tensor shaped [m_1, ..., m_i, d] --> multidimensional list of d-dimensional indices returns: tensor shaped [m_1, ..., m_1] '''
out_shape = indices.shape[:-1]
indices = indices.unsqueeze(0).transpose(0, -1) # roll last axis to fring
ndim = indices.shape[0]
indices = indices.long()
idx = torch.zeros_like(indices[0], device=indices.device).long()
m = 1
for i in range(ndim)[::-1]:
idx += indices[i] * m
m *= params.size(i)
out = torch.take(params, idx)
return out.view(out_shape)
Can convert directly
tf.reshape()->torch.reshape()tf.log()tf.squeeze
边栏推荐
- Build a private cloud disk cloudrev
- Pytest (6) -fixture (Firmware)
- The difference between left value and right value in C language
- What does "where 1=1" mean
- Counter统计数量后,如何返回有序的key
- Global and Chinese ammonium dimolybdate market in-depth analysis and prospect risk prediction report 2022 Edition
- Add MDF database file to SQL Server database, and the error is reported
- cvpr2022去雨去雾
- Oauth2.0 authentication, login and access "/oauth/token", how to get the value of request header authorization (basictoken)???
- random shuffle注意
猜你喜欢

Check log4j problems using stain analysis

【翻译】后台项目加入了CNCF孵化器

What is the way out for children from poor families?

MATLAB小技巧(24)RBF,GRNN,PNN-神经网络

Tongda OA homepage portal workbench
![[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)](/img/6e/67bc187a89fb9125856c78c89f7bfb.gif)
[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)
[advanced ROS] Lesson 6 recording and playback in ROS (rosbag)

4. Classes and objects

Add automatic model generation function to hade

Pytest (6) -fixture (Firmware)
随机推荐
[shutter] banner carousel component (shutter_wiper plug-in | swiper component)
Monitoring and management of JVM
Use optimization | points that can be optimized in recyclerview
Your family must be very poor if you fight like this!
[fluent] future asynchronous programming (introduction | then method | exception capture | async, await keywords | whencomplete method | timeout method)
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
Add MDF database file to SQL Server database, and the error is reported
The left value and the right finger explain better
Summary of interview project technology stack
Apple releases MacOS 11.6.4 update: mainly security fixes
How to change the panet layer in yolov5 to bifpn
HW initial preparation
A2L file parsing based on CAN bus (2)
The data in servlet is transferred to JSP page, and the problem cannot be displayed using El expression ${}
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
Apple releases MacOS 11.6.4 update: mainly security fixes
GBase 8c系统表-pg_auth_members
xiaodi-笔记
面试八股文整理版
疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文