Tensorflow代码转pytorch代码 函数的转换
生活随笔
收集整理的這篇文章主要介紹了
Tensorflow代码转pytorch代码 函数的转换
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
tensoflow函數和pytorch函數之間的轉換
| tf.reshape(input, shape) | input.view() |
| tf.expand_dims(input, dim) | input.unsqueeze(dim) / input.view() |
| tf.squeeze(input, dim) | torch.squeeze(dim)/ input.view() |
| tf.gather(input1, input2) | input1[input2] |
| tf.tile(input, shape) | input.repeat(shape) |
| tf.boolean_mask(input, mask) | input[mask] #注意,mask是bool值,不是0,1的數值 |
| tf.concat(input1, input2) | torch.cat(input1, input2) |
| tf.matmul() | torch.matmul() |
| tf.minium(input, min) | torch.clamp(input, max=min) |
| tf.equal(input1, input2) | torch.eq(input1, input2)/ input1 == input2 |
| tf.logical_and(input1, input2) | input1 & input2 |
| tf.logical_not(input) ~ | input |
| tf.reduce_logsumexp(input, [dim]) | torch.logsumexp(input, dim=dim) |
| tf.reduce_any(input, dim) | input.any(dim) |
| tf.reduce_mean(input) | torch.mean(input) |
| tf.reduce_sum(input) | input.sum() |
| tf.transpose(input) | input.t() |
| tf.softmax_cross_entroy_with_logits(logits, labels) | torch.nn.CrossEntropyLoss(logits, labels) |
總結
以上是生活随笔為你收集整理的Tensorflow代码转pytorch代码 函数的转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国6b什么时候实施2021年
- 下一篇: 解放军重启203毫米榴弹炮试验