简体   繁体   English

Pytorch:张量归一化给出不好的结果

[英]Pytorch: tensor normalization giving bad result

I have a tensor of longitudes/latitudes that i want to normalize.我有一个要标准化的经度/纬度张量。 I want to use this tensor to perform a neural network algorithm on it that returns me the best trip between these different long/lat.我想使用这个张量对其执行神经网络算法,以返回这些不同的经纬度之间的最佳行程。 I used this function:我使用了这个功能:

from torch.nn.functional import normalize
t=normalize(locations)

This is a lign in my tensor [ 0.0000, 36.4672, 36.4735, 36.4705, 36.4638, 36.4671], [ 0.0000, 10.7637, 10.7849, 10.7822, 10.7821, 10.7637]],这是我的张量 [ 0.0000, 36.4672, 36.4735, 36.4705, 36.4638, 36.4671], [ 0.0000, 10.7637, 10.7849, 10.7822, 10.7821, 10.7637]]

This is after normalization: [0.0000, 0.2181, 0.2181, 0.2181, 0.2179, 0.2179], [0.0000, 0.2186, 0.2194, 0.2194, 0.2196, 0.2188]],这是标准化后的结果:[0.0000, 0.2181, 0.2181, 0.2181, 0.2179, 0.2179], [0.0000, 0.2186, 0.2194, 0.2194, 0.2196, 0.2188]],

As you can see the result is not good because there are many values repeating and this is affecting my results.如您所见,结果不好,因为有很多值重复,这影响了我的结果。 Is there another way to normalize my tensor?还有另一种方法可以使我的张量正常化吗? I'm using pytorch in this project.我在这个项目中使用 pytorch。

This is how torch.nn.functional.normalize works. 就是torch.nn.functional.normalize工作原理。

In my opinion, you should divide your original tensor value with the maximum value of longitudes/latitudes can have, making the tensor to have values range of [0, 1] .在我看来,您应该将原始张量值除以经度/纬度可以具有的最大值,使张量的值范围为[0, 1]


Additionally, I've tried:此外,我尝试过:

import torch
import torch.nn.functional as F

a = torch.tensor([[0.0000, 36.4672, 36.4735, 36.4705, 36.4638, 36.4671], [ 0.0000, 10.7637, 10.7849, 10.7822, 10.7821, 10.7637]])
res = F.normalize(a)

and the results was:结果是:

tensor([[0.0000, 0.4472, 0.4473, 0.4472, 0.4472, 0.4472],
        [0.0000, 0.4467, 0.4476, 0.4475, 0.4475, 0.4467]])

How did you get your results?你是怎么得到你的结果的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM