我不知道该如何处理这个问题。我在做模特训练。下面这部分是我得到的
mean_train = torch.Tensor(np.mean(train_vertices, axis=0))
TypeError: new(): data must be a sequence (got numpy.float64)我的代码是:
mean_train = torch.Tensor(np.mean(train_vertices, axis=0))
std_train = torch.Tensor(np.std(train_vertices, axis=0))发布于 2022-01-28 22:39:33
您有一个numpy数组,您想要从它创建一个pytorch张量。您可以使用torch.from_numpy来实现这一点。请注意,torch.from_numpy需要一个np.ndarray而不是np.float64,所以您需要弄清楚您的形状。
但是,如果您不需要numpy,可以直接使用跳转中的py手电筒。无论如何,Py手电很可能具有从numpy中需要的功能。
发布于 2022-07-27 10:03:29
如果您想要创建一个可以自动分级的Tensor (用自动梯度进行修改),那么您只能拥有可迭代的对象,如numpy.array()、list()等等,您只需要检查您的np.mean(train_vertices, axis=0)是否是标量。
如果您想要创建一个张量,它只需要是张量,但不会被修改,那么您可以使用torch.tensor(np.mean(train_vertices, axis=0))。
更多关于它的信息:https://pytorch.org/docs/stable/generated/torch.tensor.html
https://stackoverflow.com/questions/70900282
复制相似问题